Skip to content

chore(hooks): skip hooks gracefully when pyproject.toml has merge conflict markers - #2355

Merged
zackees merged 1 commit into
masterfrom
fix-hooks-conflict-marker-guard
Apr 19, 2026
Merged

zackees merged 1 commit into
masterfrom
fix-hooks-conflict-marker-guard

Conversation

@zackees

@zackees zackees commented Apr 19, 2026

Copy link
Copy Markdown
Member

Summary

Adds a grep -q '^<<<<<<< ' pyproject.toml pre-check to every .claude/settings.json hook command. If unresolved merge conflict markers are present, the hook short-circuits through the existing || fallback and exits 0 with a warning instead of letting uv run crash with a TOML parse error.

The bug this fixes — real lockout observed today

During PR #2346's rebase, pyproject.toml had conflict markers mid-rebase. Every Claude tool triggered a PreToolUse hook → hook ran uv run python ci/hooks/<script>.py → uv tried to parse pyproject.toml for dependency resolution → TOML parse error → hook exited non-zero → tool was blocked.

Result: total tool lockout. Every single tool (Read, Write, Edit, Bash, Skill, ToolSearch, Glob, Grep) returned the same:

PreToolUse:Bash hook error: [d=$PWD; ...]: warning: Failed to parse `pyproject.toml` ...
error: Failed to parse: `pyproject.toml`
  Caused by: TOML parse error at line 9, column 5
9 |     "fbuild>=2.1.20",
missing comma between array elements, expected `,`

The agent couldn't fix pyproject.toml because editing it required Read → hook → uv → parse-fail → blocked. A catch-22. The user had to intervene manually from a terminal.

Fix

Single-line change to each of the 12 hook command strings: add && ! grep -q '^<<<<<<< ' pyproject.toml between cd "$d" and exec uv run .... Conflict-marker detection is ~1ms, the grep is already on every system, and the existing || { echo ...; exit 0; } fallback now gracefully handles both failure modes.

-[ -f "$d/pyproject.toml" ] && cd "$d" && exec uv run python ci/hooks/<SCRIPT> || { echo 'FastLED hook skipped: project root (pyproject.toml) not found above $PWD' >&2; exit 0; }
+[ -f "$d/pyproject.toml" ] && cd "$d" && ! grep -q '^<<<<<<< ' pyproject.toml && exec uv run python ci/hooks/<SCRIPT> || { echo 'FastLED hook skipped: pyproject.toml missing or has unresolved merge conflict markers' >&2; exit 0; }

Also adds a _conflict_marker_guard documentation key in settings.json next to the existing _cwd_resolution note, so future readers understand why the grep is there.

Test plan

  • Confirm hooks still fire correctly on a clean pyproject.toml (normal operation) — verified during this session; tools work.
  • Confirm hooks skip with the new warning message when pyproject.toml contains <<<<<<< markers. Can be reproduced by running git merge with a deliberate conflict in pyproject.toml.

🤖 Generated with Claude Code

…flict markers

Adds a `grep -q '^<<<<<<< ' pyproject.toml` pre-check in every `.claude`
hook command. If unresolved merge conflict markers are present, the hook
short-circuits through the existing `||` fallback and exits 0 with a
descriptive warning instead of letting `uv run` crash with a TOML parse
error (which propagates as hook failure and blocks every subsequent tool
call).

Without this guard, a mid-rebase state where git leaves conflict markers
in `pyproject.toml` creates a catch-22: every Claude tool invocation
triggers a PreToolUse hook → uv can't parse pyproject.toml → hook exits
non-zero → tool is blocked → the agent literally cannot fix the file
because every tool (Read, Write, Edit, Bash, Skill, ToolSearch) is
locked out. We hit this today during the PR #2346 rebase — user had to
fix pyproject.toml manually in a terminal to unblock the agent.

Implementation: single `grep` call (~1ms) in each hook's shell command;
the `||` fallback clause now covers both failure modes (no pyproject.toml
found AND conflict markers present) with an updated error message.

Also adds a `_conflict_marker_guard` key in settings.json documenting
the rationale so future readers know why the grep is there.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees zackees mentioned this pull request Apr 19, 2026
2 tasks
@zackees
zackees merged commit a843234 into master Apr 19, 2026
1 check failed
@zackees
zackees deleted the fix-hooks-conflict-marker-guard branch April 19, 2026 10:11
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