Skip to content

fix: Windows statusline hook — UTF-8 stdin, system language, real console width#80

Merged
aqua5230 merged 3 commits into
mainfrom
fix/windows-tray-quota-and-perf
Jul 17, 2026
Merged

fix: Windows statusline hook — UTF-8 stdin, system language, real console width#80
aqua5230 merged 3 commits into
mainfrom
fix/windows-tray-quota-and-perf

Conversation

@aqua5230

Copy link
Copy Markdown
Owner

Summary

Four fixes that finally make the Claude Code statusline hook fully work on Windows:

  • ASCII-only hook command (c4053b3): Claude Code on Windows fails to spawn statusLine commands whose path contains non-ASCII characters. setup_hook now prefers an all-ASCII python.exe and --setup migrates existing non-ASCII commands.
  • UTF-8 stdin (486a371): Windows decodes piped stdin with the locale codepage (cp950 on zh-TW), 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 pins encoding=utf-8 on its subprocess fan-out.
  • System UI language (6fcc0e1): with no LANG-style env var set (the Windows norm), hooks now fall back to GetUserDefaultUILanguage, matching the tray's existing usage_lang.py logic.
  • Real console width (6fcc0e1): os.get_terminal_size(2) always fails under piped spawn, pinning get_width() at 116 columns and dropping the '(left)' reset-time suffixes on wide terminals. Now probes CONOUT$ + GetConsoleScreenBufferInfo first.

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 ., full pytest: 777 passed, 2 skipped (POSIX-only skips) on Windows 10 zh-TW.
  • Manually verified end-to-end on zh-TW Windows: CJK cwd payload round-trips, output renders in Traditional Chinese, and a 200-column console keeps reset-time suffixes with a long branch name.

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread usage_statusline.py
Comment on lines 766 to +769
def main() -> None:
_configure_windows_utf8_output()
try:
raw = sys.stdin.read()
raw = _read_stdin_utf8()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

aqua5230 and others added 3 commits July 17, 2026 18:38
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>
@aqua5230
aqua5230 force-pushed the fix/windows-tray-quota-and-perf branch from 6fcc0e1 to a890780 Compare July 17, 2026 10:41
@aqua5230
aqua5230 merged commit 729bd36 into main Jul 17, 2026
5 checks passed
@aqua5230
aqua5230 deleted the fix/windows-tray-quota-and-perf branch July 17, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant