-
Notifications
You must be signed in to change notification settings - Fork 43
Fix Windows statusLine hook never firing under Git Bash #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,6 +135,10 @@ def _find_system_python() -> str: | |
|
|
||
| def _shell_arg(value: str) -> str: | ||
| if sys.platform == "win32": | ||
| # Claude Code runs statusLine commands through Git Bash when it is | ||
| # installed. Backslashes are escape characters there, while forward | ||
| # slashes also work in PowerShell, so emit the portable Windows form. | ||
| value = value.replace("\\", "/") | ||
| return subprocess.list2cmdline([value]) | ||
| return shlex.quote(value) | ||
|
|
||
|
|
@@ -148,6 +152,32 @@ def _uses_bundled_app_python(command: str) -> bool: | |
| return ".app/Contents" in command | ||
|
|
||
|
|
||
| def _migrate_windows_statusline_command_if_needed( | ||
| settings: dict[str, Any] | None = None, | ||
| ) -> None: | ||
| """Replace legacy backslash paths in usage-owned Windows statusLine commands.""" | ||
| if sys.platform != "win32": | ||
| return | ||
| data = _load_settings() if settings is None else settings | ||
| sl = data.get("statusLine") | ||
| if not isinstance(sl, dict): | ||
| return | ||
| command = sl.get("command") | ||
| if not isinstance(command, str) or "\\" not in command: | ||
| return | ||
| if "usage-statusline-forwarder" in command: | ||
| new_command = _forwarder_command() | ||
| elif "usage-statusline" in command: | ||
| new_command = _statusline_command() | ||
|
Comment on lines
+168
to
+171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For Windows users who already enabled Resume or Terse mode before upgrading, the existing Useful? React with 👍 / 👎. |
||
| else: | ||
| return | ||
| if command == new_command: | ||
| return | ||
| sl["command"] = new_command | ||
| _save_settings(data) | ||
| _append_hook_repair_log("migrate_windows_statusline", "backslash paths -> forward slashes") | ||
|
|
||
|
|
||
| def _append_hook_repair_log(action: str, detail: str) -> None: | ||
| settings = _load_settings() | ||
| usage_settings = settings.get(BACKUP_KEY) | ||
|
|
@@ -600,6 +630,7 @@ def setup(force_forwarder: bool = False) -> int: | |
| if has_claude: | ||
| settings = _load_settings() | ||
| _migrate_bundled_python_commands_if_needed(settings) | ||
| _migrate_windows_statusline_command_if_needed(settings) | ||
| state = _detect_current_state(settings) | ||
|
|
||
| if force_forwarder or state in {"external", "legacy-tt"}: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When Claude Code invokes this through Git Bash,
subprocess.list2cmdlineis still Windows argv quoting, not shell quoting: it leaves Bash metacharacters unescaped, so a valid path likeC:\Users\R&D\.claude\usage-statusline.pybecomesC:/Users/R&D/...and Bash treats&as a control operator before the hook runs. The statusLine docs say thecommandfield runs in a shell, so after making the command Bash-compatible with forward slashes this also needs shell-safe quoting for Windows paths with characters such as&,$, or parentheses.Useful? React with 👍 / 👎.