/context-guard
Install, uninstall, or check status of Context Guard hooks for AI context file freshness: $ARGUMENTS
Install opt-in hooks that detect stale AI context files, remind you to update them, and prevent content filter errors when generating standard OSS files. Claude Code only — these hooks use Claude Code’s PreToolUse, PostToolUse, and Stop hook system, which is not supported by OpenCode, Codex CLI, or other AI coding tools.
Context Guard has two enforcement tiers:
- Tier 1 — Nudge (default): Advisory. A Stop hook suggests updating context docs before the session ends. Claude can still stop if context docs genuinely don’t need changes.
- Tier 2 — Guard (opt-in): Blocking. A PreToolUse hook blocks
git commitwhen structural files are staged without context doc updates.
Behaviour
- Load the
context-guardskill for reference - Execute the requested action:
install,install strict,uninstall, orstatus
Arguments
-
install: Install Context Guard (Tier 1) into the current project:- Create
.claude/hooks/directory if it does not exist - Copy
context-drift-check.sh,context-structural-change.sh,content-filter-guard.sh, andcontext-guard-stop.shfrom the plugin’shooks/directory to.claude/hooks/ - Make the scripts executable (
chmod +x) - Merge PreToolUse, PostToolUse, and Stop hook entries into
.claude/settings.json(create the file if needed; if entries already exist, append without overwriting) - Copy
context-quality.mdto.claude/rules/context-quality.md(create directory if needed) - Report what was installed
- Create
-
install strict: Install Context Guard (Tier 1 + Tier 2) into the current project:- Perform all steps from
installabove - Additionally copy
context-commit-guard.shfrom the plugin’shooks/directory to.claude/hooks/ - Add a PreToolUse Bash hook entry for
context-commit-guard.shto.claude/settings.json - Report what was installed, noting Tier 2 is active
- Perform all steps from
-
uninstall: Remove all Context Guard hooks from the current project:- Remove
.claude/hooks/context-drift-check.sh,.claude/hooks/context-structural-change.sh,.claude/hooks/content-filter-guard.sh,.claude/hooks/context-guard-stop.sh, and.claude/hooks/context-commit-guard.sh - Remove all Context Guard hook entries (PreToolUse, PostToolUse, and Stop) from
.claude/settings.json(preserve other hooks) - Remove
.claude/rules/context-quality.md - Report what was removed
- Remove
-
status: Check installation state and current drift:- Check if hook scripts exist in
.claude/hooks/ - Check if hook entries are present in
.claude/settings.json - Check if the quality rule exists in
.claude/rules/ - Determine which tier is active (Tier 1 if Stop hook present, Tier 2 if commit guard also present)
- Run a quick drift check (same logic as
/contextdocs:ai-context audit) to report current staleness - Report findings
- Check if hook scripts exist in
Output
Install
Context Guard installed (Tier 1 — Nudge):
✓ .claude/hooks/context-drift-check.sh — warns after commits if context files are stale
✓ .claude/hooks/context-structural-change.sh — reminds after structural file changes
✓ .claude/hooks/content-filter-guard.sh — blocks Write on high-risk OSS files, advises on medium-risk
✓ .claude/hooks/context-guard-stop.sh — nudges to update context docs before session ends
✓ .claude/rules/context-quality.md — auto-loaded quality standards for context files
✓ .claude/settings.json — PreToolUse, PostToolUse, and Stop hooks registered
Tier 2 (Guard) not installed. Run /contextdocs:context-guard install strict to also
block commits when structural files change without context doc updates.
Note: These hooks are Claude Code-specific. If your team also uses OpenCode or
Codex CLI, the hooks will be ignored by those tools (no errors, just no effect).
Add .claude/hooks/ to .gitignore if you prefer hooks to be per-developer.
Install Strict
Context Guard installed (Tier 1 + Tier 2 — Nudge + Guard):
✓ .claude/hooks/context-drift-check.sh — warns after commits if context files are stale
✓ .claude/hooks/context-structural-change.sh — reminds after structural file changes
✓ .claude/hooks/content-filter-guard.sh — blocks Write on high-risk OSS files, advises on medium-risk
✓ .claude/hooks/context-guard-stop.sh — nudges to update context docs before session ends
✓ .claude/hooks/context-commit-guard.sh — blocks commits with stale context docs
✓ .claude/rules/context-quality.md — auto-loaded quality standards for context files
✓ .claude/settings.json — PreToolUse, PostToolUse, and Stop hooks registered
Status
Context Guard Status:
✓ Tier 1 — Nudge (Stop hook active — reminds about context docs before session end)
✓ Tier 2 — Guard (commit blocker active — blocks commits with stale context)
✓ Base hooks installed (3/3 scripts in .claude/hooks/)
✓ Settings configured (PreToolUse, PostToolUse, and Stop entries in .claude/settings.json)
✓ Quality rule active (.claude/rules/context-quality.md)
Drift check:
✓ CLAUDE.md — up to date
⚠ AGENTS.md — 12 source commits since last update
✓ .cursorrules — up to date
· GEMINI.md — not present