Repository navigation
chore(claude): make hook walk-up resilient; add escape hatches - #2606
Conversation
…ape hatches
The PreToolUse hooks walked up from $PWD looking for the first pyproject.toml
above it, then `exec`-ed a hook script relative to that root. When a sibling
FastLED clone / fbuild worktree under scratch/ also carried a pyproject.toml +
ci/hooks/ dir, the walk-up stopped there — but its ci/hooks/ contained
different scripts (tool_guard.py, lint.py, etc.), so exec landed on a missing
path and cascade-blocked every Claude tool until the stray pyproject.toml was
manually moved.
Changes:
- Walk-up now requires pyproject.toml AND the hook's OWN specific script
(e.g. ci/hooks/check_forbidden_commands.py). Unique per-hook script names
guarantee the walk-up only stops at the FastLED root.
- Stops using `exec` for the hook script — uses regular invocation so the
|| fallback actually fires when the script exits non-zero (with exec, the
shell is replaced and the fallback can never run).
- Adds two env-var escape hatches:
FL_HOOK_SKIP=1 — short-circuit every hook to exit 0 with no script run
FL_HOOK_SOFT=1 — keep running scripts but force exit 0 on failure
(errors still printed to stderr)
Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThe PR consolidates Claude tool hook execution across all trigger types (PreToolUse, PostToolUse, SessionStart, Stop, Notification, UserPromptSubmit) to use a unified command flow with environment-controlled escape hatches, script-aware root discovery, and merge-conflict-marker guarding. ChangesClaude Hook Escape-Hatch and Standardized Flow
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
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 |
Summary
scratch/can't trap it. Each hook walks up looking forpyproject.tomlAND its OWN specific script (e.g.ci/hooks/check_forbidden_commands.py) — not just anypyproject.tomlor anyci/hooks/directory.execfor the hook script, so the||fallback can actually fire when the script exits non-zero (withexec, the shell is replaced and the fallback never runs — which is why a missing script cascade-blocked every tool).FL_HOOK_SKIP=1— short-circuit every hook toexit 0with no script runFL_HOOK_SOFT=1— keep running scripts but forceexit 0on failure (errors still print to stderr)Failure mode this fixes
If a sibling clone of FastLED or an fbuild worktree lands under
scratch/(each carrying its ownpyproject.toml+ci/hooks/dir with different scripts), and$PWDhappens to be inside that subdir, the old walk-up stopped at the wrong root.exec uv run python ci/hooks/check_forbidden_commands.pythen ran from a directory where that script doesn't exist, returned exit 1, and the||fallback never fired — blocking every subsequent Claude tool until the straypyproject.tomlwas manually moved.With this change, the walk-up requires the FastLED-specific script for that hook, so it transparently passes through any sibling pyproject.toml + ci/hooks/ pair that doesn't actually belong to FastLED.
Test plan
scratch/fbuild/(sibling fbuild clone) when simulated PWD is inside itFL_HOOK_SKIP=1short-circuits hook commands to exit 0 with no script executionFL_HOOK_SOFT=1demotes a non-zero script exit to exit 0 while still printing to stderrpyproject.toml)🤖 Generated with Claude Code
Summary by CodeRabbit