fix(hooks): pass phase argument from hook ID to observe.sh#1042
Conversation
The shell wrapper run-with-flags-shell.sh was not extracting the phase prefix from the hook ID (e.g., "pre:observe" -> "pre") and passing it as $1 to the invoked script. This caused observe.sh to always default to "post", recording all observations as tool_complete events with no tool_start events captured. Fixes affaan-m#1018 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe hook runner now extracts the phase prefix from the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR fixes a one-line bug in Key changes:
No issues found. The fix is correct, minimal, and well-commented. Confidence Score: 5/5Safe to merge — single-line targeted bug fix with no regressions. The change is minimal and correct: it fixes a missing argument pass-through using standard POSIX shell parameter expansion. observe.sh already had the ${1:-post} default in place waiting for this argument. The only call sites of run-with-flags-shell.sh in the entire repo are the two observe.sh registrations in hooks/hooks.json, so no other scripts are impacted. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant CC as Claude Code
participant RWF as run-with-flags-shell.sh
participant OBS as observe.sh
Note over CC,OBS: PreToolUse (before fix)
CC->>RWF: $1="pre:observe", stdin=JSON
RWF->>OBS: (no args), stdin=JSON
OBS->>OBS: HOOK_PHASE="${1:-post}" → "post"
OBS-->>CC: records tool_complete ❌
Note over CC,OBS: PreToolUse (after fix)
CC->>RWF: $1="pre:observe", stdin=JSON
RWF->>RWF: HOOK_PHASE="${HOOK_ID%%:*}" → "pre"
RWF->>OBS: $1="pre", stdin=JSON
OBS->>OBS: HOOK_PHASE="${1:-post}" → "pre"
OBS-->>CC: records tool_start ✅
Note over CC,OBS: PostToolUse (unchanged behavior)
CC->>RWF: $1="post:observe", stdin=JSON
RWF->>RWF: HOOK_PHASE="${HOOK_ID%%:*}" → "post"
RWF->>OBS: $1="post", stdin=JSON
OBS->>OBS: HOOK_PHASE="${1:-post}" → "post"
OBS-->>CC: records tool_complete ✅
Reviews (1): Last reviewed commit: "fix(hooks): pass phase argument from hoo..." | Re-trigger Greptile |
…1042) The shell wrapper run-with-flags-shell.sh was not extracting the phase prefix from the hook ID (e.g., "pre:observe" -> "pre") and passing it as $1 to the invoked script. This caused observe.sh to always default to "post", recording all observations as tool_complete events with no tool_start events captured. Fixes affaan-m#1018 Co-authored-by: Millectable <noreply@github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…1042) The shell wrapper run-with-flags-shell.sh was not extracting the phase prefix from the hook ID (e.g., "pre:observe" -> "pre") and passing it as $1 to the invoked script. This caused observe.sh to always default to "post", recording all observations as tool_complete events with no tool_start events captured. Fixes affaan-m#1018 Co-authored-by: Millectable <noreply@github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
run-with-flags-shell.shto extract the phase prefix from the hook ID (e.g.,"pre:observe"→"pre","post:observe"→"post") and pass it as$1to the invoked scriptobserve.shalways defaults to"post", causing all observations to be recorded astool_completeevents — notool_startevents are ever capturedRoot Cause
In
hooks.json, the PreToolUse observe hook is registered with hook ID"pre:observe"and PostToolUse with"post:observe". The shell wrapper receives this ID as$1but never extracts the phase and forwards it to the script. The JS wrapper (run-with-flags.js) doesn't have this issue because the JS hook scripts receive the hook ID directly.Fix
Added phase extraction using
${HOOK_ID%%:*}(bash parameter expansion to get everything before the first colon) and passes it as an argument to the script.Test plan
codex-hooks.test.jsunrelated to this change)tool_startandtool_completeeventsFixes #1018
🤖 Generated with Claude Code
Summary by cubic
Fix the shell hook runner to pass the phase ("pre"/"post") from the hook ID to
observe.sh. This restores recording of bothtool_startandtool_completeevents.HOOK_IDwith${HOOK_ID%%:*}and pass it as$1to the script.observe.shdefaulted to "post", recording onlytool_completeevents.Written for commit 749a11d. Summary will update on new commits.
Summary by CodeRabbit