fix(hooks): read hook input from stdin JSON instead of environment variables - #4
Open
sergiobuilds wants to merge 1 commit into
Open
fix(hooks): read hook input from stdin JSON instead of environment variables#4sergiobuilds wants to merge 1 commit into
sergiobuilds wants to merge 1 commit into
Conversation
…riables - `pre-tool-use` and `post-tool-use` read `TOOL_NAME`, `FILE_PATH`, and `TOOL_OUTPUT` from the environment, which Claude Code never sets, so both guards were installed, listed in hooks.json, and unreachable — every condition evaluated against an empty string; they now parse the stdin JSON object for `tool_name`, `tool_input.file_path`, and `tool_response`, and fall through silently on malformed input - the persona-path test widened from `personas/*` to `*personas/*` because the hook receives an absolute path, which the anchored pattern could never match
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.
pre-tool-use.shandpost-tool-use.shreadTOOL_NAME,FILE_PATH, andTOOL_OUTPUTfrom the environment. Claude Code delivers hook input as a JSON object on stdin and sets none of those, so both conditions test an empty string. The guards are installed, registered inhooks.json, and unreachable.The PLOON-overwrite guard is the one that matters — it is the thing standing between an agent and a clobbered interview log, which is the one file in this project that cannot be regenerated.
Measured
Same input, two contracts:
session-start.shis unaffected — it reads files, not the environment, and works today.Second defect, found on the way
The path test was
$FILE_PATH == personas/*, anchored at the start. Hooks receive an absolute path, so that pattern would still never match even after the input was fixed. Widened to*personas/*.After
Writeto a persona fileReadWritetoREADME.mdpost-tool-use, slop intool_responsepost-tool-use, stringtool_responseParsing goes through
node, which the project already requires, so nojqdependency is added. Malformed input falls through to empty rather than aborting underset -euo pipefail, so a hook can never take a session down with it.