Skip to content

chore(claude): make hook walk-up resilient; add escape hatches - #2606

Merged
zackees merged 1 commit into
masterfrom
fix/claude-hooks-walkup-escape-hatches
May 30, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/claude-hooks-walkup-escape-hatches

Conversation

@zackees

@zackees zackees commented May 30, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Walk-up uses a unique per-hook marker so sibling FastLED clones / fbuild worktrees under scratch/ can't trap it. Each hook walks up looking for pyproject.toml AND its OWN specific script (e.g. ci/hooks/check_forbidden_commands.py) — not just any pyproject.toml or any ci/hooks/ directory.
  • Stops using exec for the hook script, so the || fallback can actually fire when the script exits non-zero (with exec, the shell is replaced and the fallback never runs — which is why a missing script cascade-blocked every tool).
  • Adds two env-var escape hatches for emergencies:
    • 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 print to stderr)

Failure mode this fixes

If a sibling clone of FastLED or an fbuild worktree lands under scratch/ (each carrying its own pyproject.toml + ci/hooks/ dir with different scripts), and $PWD happens to be inside that subdir, the old walk-up stopped at the wrong root. exec uv run python ci/hooks/check_forbidden_commands.py then 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 stray pyproject.toml was 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

  • Verified walk-up correctly skips past scratch/fbuild/ (sibling fbuild clone) when simulated PWD is inside it
  • Verified FL_HOOK_SKIP=1 short-circuits hook commands to exit 0 with no script execution
  • Verified FL_HOOK_SOFT=1 demotes a non-zero script exit to exit 0 while still printing to stderr
  • Verified the conflict-marker guard still works (grep on resolved root's pyproject.toml)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Enhanced hook configuration with improved reliability and consistency. Added environment-controlled mechanisms to skip or gracefully handle hook failures. Improved error handling for merge-conflict detection and project root resolution.

Review Change Stack

…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]>
@coderabbitai

coderabbitai Bot commented May 30, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The 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.

Changes

Claude Hook Escape-Hatch and Standardized Flow

Layer / File(s) Summary
Escape-hatch mechanism and documentation
.claude/settings.json
Documentation describes FL_HOOK_SKIP=1 (skip hooks entirely) and FL_HOOK_SOFT=1 (downgrade non-zero exit codes to success). The check_forbidden_commands.py PreToolUse hook is rewritten to demonstrate the standardized flow: check escape hatches, discover project root requiring both pyproject.toml and the hook script, skip if merge-conflict markers exist, run via uv run python "$S" while capturing exit status, apply soft-fail behavior, and exit appropriately.
PreToolUse hook command updates
.claude/settings.json
check_test_file_pairing.py, check_pr_merge_reviews.py, tdd_guard.py, and protect_platform_headers.py commands updated to use the same escape-hatch and root-discovery flow as the introduced mechanism.
Non-PreToolUse hook updates
.claude/settings.json
PostToolUse hooks (lint-on-save.py, auto_test_suggest.py, compile_example.py), SessionStart (check-on-start.py), Stop (check-on-stop.py), Notification (desktop_notify.py), and UserPromptSubmit (git_context.py) rewritten to apply the unified standardized command flow across all hook trigger types.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • FastLED/FastLED#2537: Changes the shared .claude/settings.json wrapper logic for all Claude tool hooks, directly affecting how newly added hook scripts are invoked and behave.
  • FastLED/FastLED#2330: Also modifies .claude/settings.json hook command execution flow, which would be governed by the unified hook command pattern introduced in this PR.
  • FastLED/FastLED#2295: Modifies hook command resolution logic in .claude/settings.json for project root discovery before running uv run python ..., overlapping at the hook-command level.

Poem

🐰 Hooks align in harmony,
Skip gates and soft fails set free,
Conflict guards in place,
Each script finds its space—
One flow, standardized decree!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: improving hook walk-up resilience by requiring both pyproject.toml and hook script presence, and adding FL_HOOK_SKIP/FL_HOOK_SOFT escape hatches.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/claude-hooks-walkup-escape-hatches

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zackees
zackees merged commit 7fd161e into master May 30, 2026
1 check failed
@zackees
zackees deleted the fix/claude-hooks-walkup-escape-hatches branch May 30, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant