Repository navigation
chore(hooks): skip hooks gracefully when pyproject.toml has merge conflict markers - #2355
Merged
Merged
Conversation
…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]>
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
grep -q '^<<<<<<< ' pyproject.tomlpre-check to every.claude/settings.jsonhook command. If unresolved merge conflict markers are present, the hook short-circuits through the existing||fallback and exits 0 with a warning instead of lettinguv runcrash with a TOML parse error.The bug this fixes — real lockout observed today
During PR #2346's rebase,
pyproject.tomlhad conflict markers mid-rebase. Every Claude tool triggered a PreToolUse hook → hook ranuv run python ci/hooks/<script>.py→ uv tried to parsepyproject.tomlfor 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:
The agent couldn't fix
pyproject.tomlbecause 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.tomlbetweencd "$d"andexec uv run .... Conflict-marker detection is ~1ms, thegrepis already on every system, and the existing|| { echo ...; exit 0; }fallback now gracefully handles both failure modes.Also adds a
_conflict_marker_guarddocumentation key insettings.jsonnext to the existing_cwd_resolutionnote, so future readers understand why thegrepis there.Test plan
pyproject.toml(normal operation) — verified during this session; tools work.pyproject.tomlcontains<<<<<<<markers. Can be reproduced by runninggit mergewith a deliberate conflict inpyproject.toml.🤖 Generated with Claude Code