From f4c7e1a37ff5bae400badf8a0ff26ce98444ea48 Mon Sep 17 00:00:00 2001 From: Amit Vijapur Date: Tue, 21 Jul 2026 00:38:00 +0800 Subject: [PATCH] fix(hooks): read PostToolUse payload from stdin instead of $TOOL_INPUT env var MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PostToolUse auto-update hook read "$TOOL_INPUT" to detect git commit/merge/cherry-pick/rebase commands, but Claude Code never sets a TOOL_INPUT environment variable for hook processes — hook input is delivered as JSON on stdin (fields tool_name, tool_input, cwd, ...). The grep therefore always tested an empty string, the && chain short-circuited, and the trailing || true swallowed the failure: the per-commit auto-update silently never fired, on any OS. Capture stdin into INPUT, then extract tool_input.command via a small node -e script (matching the JSON-parsing style already used by the SessionStart hook's node -p call, and requiring no new dependency — jq isn't guaranteed present on Windows/Git Bash hosts). The extracted command is piped into the same grep check as before; everything downstream (UA_DIR resolution, config.json/knowledge-graph.json gating) is unchanged. Verified by piping a realistic PostToolUse JSON payload into both the old and new hook commands: the old command produces no output (bug reproduced), the new one prints the auto-update instruction. Also checked git merge/cherry-pick/rebase trigger correctly, non-matching commands and non-Bash tool payloads (no tool_input.command field) stay silent, embedded quotes in commit messages don't break JSON parsing, and the autoUpdate:false / missing knowledge-graph.json gates still suppress the hook as before. Fixes #594. --- understand-anything-plugin/hooks/hooks.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/understand-anything-plugin/hooks/hooks.json b/understand-anything-plugin/hooks/hooks.json index 3daa83fb8..de9bb14e8 100644 --- a/understand-anything-plugin/hooks/hooks.json +++ b/understand-anything-plugin/hooks/hooks.json @@ -6,7 +6,7 @@ "hooks": [ { "type": "command", - "command": "UA_DIR=.understand-anything; [ -d \"$UA_DIR\" ] || UA_DIR=.ua; printf '%s' \"$TOOL_INPUT\" | grep -qE 'git\\s+(commit|merge|cherry-pick|rebase)' && [ -f $UA_DIR/config.json ] && grep -q '\"autoUpdate\".*true' $UA_DIR/config.json && [ -f $UA_DIR/knowledge-graph.json ] && echo \"[understand-anything] Commit detected with auto-update enabled. You MUST read the file at ${CLAUDE_PLUGIN_ROOT}/hooks/auto-update-prompt.md and execute its instructions to incrementally update the knowledge graph. Do not ask the user for confirmation — just do it.\" || true" + "command": "UA_DIR=.understand-anything; [ -d \"$UA_DIR\" ] || UA_DIR=.ua; INPUT=$(cat); CMD=$(printf '%s' \"$INPUT\" | node -e \"let d='';process.stdin.on('data',c=>d+=c);process.stdin.on('end',()=>{try{process.stdout.write(JSON.parse(d).tool_input?.command||'')}catch{}})\" 2>/dev/null); printf '%s' \"$CMD\" | grep -qE 'git\\s+(commit|merge|cherry-pick|rebase)' && [ -f $UA_DIR/config.json ] && grep -q '\"autoUpdate\".*true' $UA_DIR/config.json && [ -f $UA_DIR/knowledge-graph.json ] && echo \"[understand-anything] Commit detected with auto-update enabled. You MUST read the file at ${CLAUDE_PLUGIN_ROOT}/hooks/auto-update-prompt.md and execute its instructions to incrementally update the knowledge graph. Do not ask the user for confirmation — just do it.\" || true" } ] }