Skip to content

feat: advisory PreToolUse hook for ~/.claude/reference/ naming scope (#286) - #306

Merged
Data-Wise merged 1 commit into
devfrom
feature/issue-286-reference-scope-guard
Jul 25, 2026
Merged

feat: advisory PreToolUse hook for ~/.claude/reference/ naming scope (#286)#306
Data-Wise merged 1 commit into
devfrom
feature/issue-286-reference-scope-guard

Conversation

@Data-Wise

Copy link
Copy Markdown
Owner

Summary

  • Adds scripts/reference-scope-guard.sh: an advisory-only PreToolUse hook that warns (never blocks) when a Write/Edit targets ~/.claude/reference/ with a filename that doesn't match the directory's naming convention — lowercase kebab-case, no .html, no SPEC-*/GRILL-*/BRAINSTORM-* prefix (those belong in docs/specs/).
  • Wires it into scripts/install-guards.sh alongside branch-guard/no-switch-guard: install_hook copy step, Edit|Write-only PreToolUse registration, guards.json registry seed — same idempotent, lock-coordinated pattern as the existing two guards.
  • Adds a 13-case e2e suite (tests/test_reference_scope_guard.sh) covering clean filenames (silent), each violation type (advisory), tilde-path expansion, and out-of-scope paths/tools (silent).

Closes #286.

Design notes

  • Always exits 0 — per the issue's explicit requirement, this hook is advisory-only and must never block a Write/Edit.
  • Scope is strictly ~/.claude/reference/ and Write/Edit tool calls only (no Bash matcher, matching the issue's proposed scope).
  • Verified the problem statement empirically: real pre-existing violations already exist in ~/.claude/reference/ (SPEC-proof-tutorial-tooling.md, SPEC-tutor-command-fixes-2026-07-13.md, tutor-cookbook.html) — these are correctly flagged (advisory) by the new hook, not retroactively fixed by this PR.

Test plan

  • HOOK_SCRIPT=scripts/reference-scope-guard.sh bash tests/test_reference_scope_guard.sh — 13/13 passed (repo copy)
  • bash scripts/install-guards.sh — installs cleanly, registers Edit|Write matcher, seeds guards.json; settings.json/guards.json both jq-valid after
  • bash tests/test_reference_scope_guard.sh — 13/13 passed against the installed hook
  • bash tests/test_branch_guard.sh — 141/141 passed (unaffected by this change)
  • bash tests/test_no_switch_guard.sh — 39/39 passed (unaffected by this change)
  • python3 -m pytest tests/ — 2615 passed, 0 failed, 49 skipped, 1 xfailed, 1 xpassed (pre-existing/benign)

🤖 Generated with Claude Code

…286)

Adds scripts/reference-scope-guard.sh: warns (never blocks) when a
Write/Edit targets ~/.claude/reference/ with a filename that doesn't
match the directory's convention (lowercase kebab-case, no SPEC-*/
GRILL-*/BRAINSTORM-* prefix, no .html). Wires it into install-guards.sh
(install_hook, Edit|Write PreToolUse registration, guards.json seed)
alongside branch-guard and no-switch-guard, and adds a 13-case e2e
suite (tests/test_reference_scope_guard.sh) covering clean/flagged
filenames, tilde-path expansion, and out-of-scope paths/tools.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Data-Wise
Data-Wise merged commit 7c94e77 into dev Jul 25, 2026
2 checks passed
@Data-Wise
Data-Wise deleted the feature/issue-286-reference-scope-guard branch July 25, 2026 03:42
Data-Wise added a commit that referenced this pull request Jul 25, 2026
@Data-Wise Data-Wise mentioned this pull request Jul 25, 2026
4 tasks
Data-Wise added a commit that referenced this pull request Jul 26, 2026
docs/index.md's "Latest" callout and docs/NEWS.md were both still describing
v4.3.0 (#305/#306) under a v4.4.0 label — NEWS.md never got a v4.4.0 entry
after that release, and index.md's callout inherited the stale text.

Also adds [Unreleased] entries to both CHANGELOGs for the two post-4.4.0
fixes from this session: the branch-guard.sh 2>&1 repo-sync (0d11236) and
the --refine docs drift (cf11471).
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