fix: Windows statusline hook — UTF-8 stdin, system language, real console width#80
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6fcc0e10e8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def main() -> None: | ||
| _configure_windows_utf8_output() | ||
| try: | ||
| raw = sys.stdin.read() | ||
| raw = _read_stdin_utf8() |
There was a problem hiding this comment.
Bump hook versions so installed hooks receive these fixes
On a normal application launch, main._self_heal() calls session_hooks.self_heal(), which only replaces the installed statusline script when its __version__ differs from setup_hook.HOOK_VERSION (setup_hook.py:587-596, session_hooks.py:1112-1116). Both remain 1.0, so an existing Windows installation keeps the pre-change ~/.claude/usage-statusline.py and never gets this UTF-8 stdin, language, or console-width behavior unless the user manually runs --setup. The resume and terse hook version pairs are likewise unchanged, so their new UTF-8/language behavior is also not deployed to already-enabled hooks.
Useful? React with 👍 / 👎.
Claude Code on Windows fails to spawn statusLine commands whose path contains non-ASCII characters. setup_hook now prefers an all-ASCII python.exe (falling back to system PATH when the venv path is not ASCII) and --setup migrates existing non-ASCII commands. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Windows decodes piped stdin with the locale codepage (cp950 on zh-TW); Claude Code sends the session JSON as UTF-8, so a cwd like 'GitHub專案' turned into mojibake, JSON parsing failed, and usage-status.json was never written. All five hook scripts now read stdin via sys.stdin.buffer and decode UTF-8 explicitly; the forwarder also pins encoding=utf-8 on its subprocess fan-out. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…width Language: the four hook scripts only read USAGE_LANG/TT_LANG/LANG, which are rarely set on Windows, so output was always English. When no env var is set they now fall back to GetUserDefaultUILanguage via ctypes (same logic usage_lang.py already uses for the tray), and usage-statusline gains the missing USAGE_LANG override. Width: os.get_terminal_size(2) always fails when Claude Code spawns the hook with piped stdio (WinError 6), so get_width() stuck at the 116-column fallback and wide terminals lost the '(left)' reset-time suffixes. get_width() now probes the attached console via CONOUT$ + GetConsoleScreenBufferInfo before falling back to 116. Non-Windows behavior unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
6fcc0e1 to
a890780
Compare
Summary
Four fixes that finally make the Claude Code statusline hook fully work on Windows:
c4053b3): Claude Code on Windows fails to spawn statusLine commands whose path contains non-ASCII characters.setup_hooknow prefers an all-ASCIIpython.exeand--setupmigrates existing non-ASCII commands.486a371): Windows decodes piped stdin with the locale codepage (cp950 on zh-TW), so a cwd likeGitHub專案turned into mojibake, JSON parsing failed, andusage-status.jsonwas never written. All five hook scripts now read stdin viasys.stdin.bufferand decode UTF-8 explicitly; the forwarder pinsencoding=utf-8on its subprocess fan-out.6fcc0e1): with noLANG-style env var set (the Windows norm), hooks now fall back toGetUserDefaultUILanguage, matching the tray's existingusage_lang.pylogic.6fcc0e1):os.get_terminal_size(2)always fails under piped spawn, pinningget_width()at 116 columns and dropping the '(left)' reset-time suffixes on wide terminals. Now probesCONOUT$+GetConsoleScreenBufferInfofirst.Also includes
057f9e4: tray now shows complete hook rate limits and caches the history scan per tick.Non-Windows behavior unchanged in all commits.
Test plan
ruff check,mypy ., fullpytest: 777 passed, 2 skipped (POSIX-only skips) on Windows 10 zh-TW.🤖 Generated with Claude Code