docs(hookify): refresh authoring cheatsheet + add regression harness#10
Merged
adelaidasofia merged 1 commit intomainfrom May 4, 2026
Merged
Conversation
The hookify-authoring template was authored against an older hookify
plugin that had two known bugs (now fixed upstream in claude-code#54873):
1. `new_text` field returned empty on Write tool calls. The cheatsheet
recommended `content` as a workaround. With the upstream fix,
`new_text` falls back to `tool_input.content` and works correctly,
so the workaround note is no longer accurate.
2. The hand-rolled YAML parser in core/config_loader.py double-escaped
backslashes, which made double-quoted regex patterns load with extra
backslashes (`"\d"` stored as `\\d`). The cheatsheet documented this
as a YAML feature ("double-quoted strings double-escape backslashes")
and recommended single-quoting as the workaround. With yaml.safe_load
in place upstream, double-quoted patterns work correctly. Single
quotes are still preferred for readability, but the underlying bug
is gone.
This commit:
- Updates `templates/rules/hookify-authoring.md` to reflect the post-fix
reality and adds three new sections that codify additional gotchas
surfaced during a recent rule audit:
* Negative lookahead with `re.search` requires `^` anchor
* Unquoted patterns starting with `[` or `\` break YAML parsing
(the parser reads `[A-Z]` as a flow sequence and errors on bare
backslash, dropping the rule at load time)
* Companion PreToolUse Python hooks for logic that goes beyond
regex, including the constraint that MCP tools cannot be called
from a hook subprocess (replicate by reading config files
directly instead)
- Adds `templates/scripts/hookify-rule-tests.py`, a copy-then-edit
regression harness that pipes synthetic tool_input payloads through
the hookify subprocess and asserts each rule fires (or stays silent)
as expected. Exit 0 means all pass. Catches three bug classes at
authoring time:
1. Rule references a non-existent operator (silent always-False)
2. YAML parse error drops a rule at load time
3. Pattern logic regression after a rule edit
The harness is dogfooded: this PR's template tests pass against a
vault running the patched hookify plugin.
- Adds entries to `templates/hookify-rules/README.md` linking to both
the authoring cheatsheet and the harness.
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
The hookify authoring docs were authored against an older hookify plugin with two known bugs that have since been fixed upstream in anthropics/claude-code#54873. This refreshes the cheatsheet, codifies three additional gotchas surfaced during a recent rule audit, and ships a regression harness so users can catch the same class of bugs at authoring time instead of at runtime.
What changes
`templates/rules/hookify-authoring.md`: rewrite
`templates/scripts/hookify-rule-tests.py`: new file
`templates/hookify-rules/README.md`: link to both the cheatsheet and the harness.
Test plan
🤖 Generated with Claude Code