Skip to content

fix: set UTF-8 input encoding for Windows stdin reading#50

Merged
mylee04 merged 1 commit into
mylee04:mainfrom
alexyan0431:fix/windows-utf8-stdin
Jun 3, 2026
Merged

fix: set UTF-8 input encoding for Windows stdin reading#50
mylee04 merged 1 commit into
mylee04:mainfrom
alexyan0431:fix/windows-utf8-stdin

Conversation

@alexyan0431

Copy link
Copy Markdown
Contributor

Problem

On Windows systems with a non-UTF-8 system codepage, notify.ps1 reads UTF-8 stdin from Claude Code hooks using [Console]::In.ReadToEnd(), which decodes bytes with the system codepage instead of UTF-8. This corrupts non-ASCII characters and breaks JSON parsing for any hook that receives non-ASCII data (e.g. PreToolUse with AskUserQuestion containing non-English text).

Fix

Add one line before reading stdin:

[Console]::InputEncoding = [System.Text.Encoding]::UTF8

Testing

  • Verified on Windows 11 that PreToolUse hooks with non-ASCII text in the JSON payload parse correctly after this fix
  • Existing hooks (Stop, Notification) continue to work as before

On Windows systems with a non-UTF-8 system codepage, [Console]::In.ReadToEnd()
decodes UTF-8 stdin using the system codepage instead of UTF-8. This corrupts
non-ASCII characters and breaks JSON parsing for hooks that receive non-ASCII
data (e.g. PreToolUse with AskUserQuestion containing non-English text).

Fix: set [Console]::InputEncoding to UTF-8 before reading stdin.
@mylee04 mylee04 merged commit 861f5b1 into mylee04:main Jun 3, 2026
2 checks passed
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.

2 participants