docs: ADR-001 — Claude Code conditional hooks (if field)#52
Merged
Conversation
Applied `if` field filtering to ~/.claude/settings.json for 4 Bash hooks (conventional_commits, tsc_precommit, git_safety, pnpm_enforcer). Hook processes now only spawn when their specific command pattern matches. Removed redundant early-exit guards from the three scripts that did internal command matching. Documents the writing hook exclusion rationale (auto-generated script + Write|Edit matcher restructuring complexity). Closes SAM-218 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
iffield (v2.1.85+) to 4 Bash hook handlers in~/.claude/settings.json, so hook processes only spawn when their command pattern matchesconventional_commits.py,tsc_precommit.py, andpnpm_enforcer.pyDECISIONS.mdas ADR-001Changes
~/.claude/settings.json(global config):conventional_commits.py→if: "Bash(git commit *)"tsc_precommit.py→if: "Bash(git commit *)"git_safety.py→if: "Bash(git *)"pnpm_enforcer.py→ two handlers:if: "Bash(npm *)"+if: "Bash(yarn *)"Hook scripts simplified: removed internal early-exit guards from
conventional_commits.py,tsc_precommit.py,pnpm_enforcer.pyExcluded from
iffield:writing_guard.py(auto-generated by Margin CLI),voice_loader.py(Write|Edit matcher restructuring required),trauma_guard.py(dynamic JSONL patterns)Test plan
python3 -m json.tool ~/.claude/settings.json— valid JSONconventional_commits.py: exits silently on non-commit input; blocks bad commit message; passes conventional formatgit_safety.py: exits silently on non-git Bash; blocks destructive git commandspnpm_enforcer.py: blocks npm/yarn in pnpm project; exits silently on other commandspython3 -m py_compile🤖 Generated with Claude Code