fix: handle windows hook unicode prompts - #1316
Open
222twotwotwo wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue or RFC does this PR close?
Closes #1305
Rationale for this change
On Windows, the Claude Code and Codex hook scripts could read stdin using the local console encoding instead of UTF-8. That corrupted non-ASCII prompts and could produce lone surrogate characters. The server then failed while rendering the 422 validation response because the raw invalid input was included in the returned error details.
What changes are included in this PR?
The Claude Code and Codex hook scripts now read JSON payloads from
sys.stdin.bufferand decode them as UTF-8 before parsing.The server’s
RequestValidationErrorhandler now removes the rawinputfield from validation errors before returning the 422 response.Regression tests were added for UTF-8 stdin handling on Windows and for surrogate-safe validation responses.
Are there any user-facing changes?
Yes. Windows users submitting non-ASCII prompts through Claude Code or Codex hooks should no longer see corrupted prompts or broken validation responses.
The API still returns 422 for invalid requests, but it no longer echoes the raw invalid input in the error details.
How was this change tested?
pytest tests/test_server.py -q -k "invalid_request_without_input_field or unicode_surrogates_without_crashing"pytest tests/claude_code_plugin/test_hook.py tests/codex_plugin/test_recall.py -qAI usage statement
AI tools were used to implement and verify this change.