Repository navigation
fix: Parse Claude Code hook JSON and cap prompt length in user-prompt-submit hook - #17
Open
HellFireAE wants to merge 2 commits into
Open
HellFireAE wants to merge 2 commits into
HellFireAE wants to merge 2 commits into
Conversation
…-submit hook The hook treated stdin as the raw prompt, but Claude Code sends a JSON object. Memories were stored as session metadata JSON instead of prompt text, and retrieval output degraded to empty entries. Extract .prompt and .cwd with jq (falls back to raw stdin if jq is missing or input is not JSON). Truncate the prompt to 1200 chars so long inputs stay under the 512-token embedding limit instead of failing with an ONNX broadcast error. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…HARS Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Author
|
Follow-up pushed ( Why: the hard-coded 1200 chars only fits the bundled Notes:
|
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.
Problem
user-prompt-submit.shtreats stdin as the raw prompt, but Claude Code passes hook input as a JSON object (session_id,transcript_path,cwd,prompt, ...). Result:lucid contextprinted mostly[conversation] ...entries.ONNX Runtime error ... Attempting to broadcast an axis by a dimension other than 1. 512 by 893, so those memories never get embeddings.Fix
.promptand.cwdwithjq; fall back to raw stdin ifjqis missing or input is not JSON (old behavior).cwdas the project path whenCLAUDE_PROJECT_PATHis unset.Testing
Piped
{"cwd":"...","prompt":"..."}into the hook: stored memory is clean prompt text andlucid contextreturns it.bash -npasses.Notes
Adds an optional
jqdependency. The PowerShell hook (user-prompt-submit.ps1) is untouched and may need the same check.🤖 Generated with Claude Code