context-guard
Skill5 starsChanged 6 months agoMITView on GitHub
Installs Claude Code hooks that keep AI context files fresh. Two-tier enforcement — Tier 1 nudges at session end, Tier 2 blocks commits when structural files are staged without context updates. Includes content filter, drift check, structural change reminder, SessionStart health check, and the context-updater agent.
- Installs packages
5 other projects use a version of this.
Adopted by
Most recently taken up by
- Cand1ePower/codex-context-guard-skilltheir own version, first seen Nov 8, 2026
- CorvusWing/CorvusWingtheir own version, first seen Oct 25, 2026
- freema/ai-skillstheir own version, first seen Oct 13, 2026
- iAstroUnicorn/astro-skillstheir own version, first seen Jul 29, 2026
- shivae372/claude-bootstraptheir own version, first seen Apr 8, 2026
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- freema/ai-skills★ 5same name
- Cand1ePower/codex-context-guard-skill★ 1same name
- CorvusWing/CorvusWing★ 1same name
- shivae372/claude-bootstrap★ 1same name
- iAstroUnicorn/astro-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository7 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms-full.txtllms.txt
- llms.txtllms.txt
- ai-contextSkill
- context-verifySkill
- contextdocsSkill
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 37
Default: Tier 1 only. Add Tier 2 with install strict.
- Very specific: line 55
If your repository uses the .agents/ layout instead of .claude/, apply the same AGENTS-first update order to the equivalent skill and agent …
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Context Guard
What It Does
Hooks and a quality rule to keep AI context files in sync with the codebase. Prevents content filter errors on standard OSS files. Two-tier enforcement for context doc freshness.
Primary platform: Claude Code (full automation, 12 hook events). Other platforms with hook support — Gemini CLI (11 events), Copilot (8, preview), Cursor (4+), Cline (3) — can use adapted hooks from platforms/ packages (coming soon). For platforms without hooks (Codex CLI, OpenCode, Windsurf), use bin/context-verify.sh as a manual or CI-based alternative.
Enforcement Tiers
| Tier | Name | Mechanism | Behaviour |
| 1 | Nudge | Stop hook | Advisory — suggests updating context docs before session ends |
| 2 | Guard | PreToolUse on git commit | Blocking — prevents commits when structural files staged without context updates (exit 2) |
Default: Tier 1 only. Add Tier 2 with install strict.
Components
content-filter-guard.sh (PreToolUse → Write)
- HIGH-risk (CODE_OF_CONDUCT.md, LICENSE, SECURITY.md): blocks write, returns fetch commands for canonical URL
- MEDIUM-risk (CHANGELOG.md, CONTRIBUTING.md): allows write, advises chunked writing
- All other files: passes through silently
context-structural-change.sh (PostToolUse → Write|Edit)
Fires after creating/editing structural files. Reminds which context files may need updating:
commands/*.md,.claude/skills/*/SKILL.md,.agents/skills/*/SKILL.md→ updateAGENTS.mdfirst, thenCLAUDE.md,llms.txt, and any affected bridge files.claude/agents/*.md,.agents/agents/*.md→AGENTS.md,llms.txt.claude/rules/*.md→AGENTS.mdandCLAUDE.mdif rule references changed- Config files (
package.json,pyproject.toml, etc.) → updateAGENTS.mdfirst, then only the bridge files with tool-specific command/tooling notes
If your repository uses the .agents/ layout instead of .claude/, apply the same AGENTS-first update order to the equivalent skill and agent paths above.
context-drift-check.sh (PostToolUse → Bash)
Fires after git commit. Compares context file last-modified commit vs most recent source commit. Detects broken path references. Throttled to max once per hour via .git/.context-guard-last-check.
context-guard-stop.sh (Stop — Tier 1)
Fires on session end. Checks for uncommitted structural changes without context updates. Returns {"decision": "block"} if drift detected. Checks stop_hook_active flag to prevent infinite loops.
context-commit-guard.sh (PreToolUse → Bash — Tier 2)
Fires before git commit. Checks staging area for structural files without context files. Exit 2 blocks the commit.
context-session-start.sh (SessionStart)
Fires at session start. Quick context health check: counts context files, detects stale files (source commits ahead), warns if aggregate line count exceeds budget. Advisory only — cannot block session start.
context-forced-eval.sh (UserPromptSubmit)
Fires on every user prompt. Checks for context-related keywords and injects a skill evaluation sequence that instructs Claude to evaluate and activate ContextDocs skills before responding. Keyword-gated to avoid overhead on unrelated prompts. Advisory only — never blocks.
context-updater agent
Autonomous agent (.claude/agents/context-updater.md) launched by Claude in response to hook output. Applies surgical, incremental context file updates. Uses .git/.context-updater-running flag for loop prevention.
Installation
/contextdocs:context-guard install (Tier 1): copies hooks to .claude/hooks/, agent to .claude/agents/, rule to .claude/rules/, merges config into .claude/settings.json.
/contextdocs:context-guard install strict (Tier 1 + 2): adds context-commit-guard.sh and its PreToolUse Bash entry.
Settings.json
{
"hooks": {
"PreToolUse": [
{ "matcher": "Write", "hooks": [{ "type": "command", "command": ".claude/hooks/content-filter-guard.sh" }] },
{ "if": "Bash(git commit*)", "hooks": [{ "type": "command", "command": ".claude/hooks/context-commit-guard.sh" }] }
],
"PostToolUse": [
{ "if": "Bash(git commit*)", "hooks": [{ "type": "command", "command": ".claude/hooks/context-drift-check.sh" }] },
{ "matcher": "Write|Edit", "hooks": [{ "type": "command", "command": ".claude/hooks/context-structural-change.sh" }] }
],
"SessionStart": [
{ "hooks": [{ "type": "command", "command": ".claude/hooks/context-session-start.sh" }] }
],
"UserPromptSubmit": [
{ "hooks": [{ "type": "command", "command": ".claude/hooks/context-forced-eval.sh" }] }
],
"Stop": [
{ "hooks": [{ "type": "command", "command": ".claude/hooks/context-guard-stop.sh" }] }
]
}
}The PreToolUse if: Bash(git commit*) entry for context-commit-guard.sh is only added with install strict (Tier 2).
if: vs matcher: — Claude Code v2.1.85 added if: (permission-rule syntax, e.g. Bash(git commit*)) so hooks fire only on matching bash commands. Older versions ignore unknown if: — the in-script substring guards keep both safe. Use matcher: "Bash" when the hook needs every Bash invocation.
Uninstallation
/contextdocs:context-guard uninstall removes all hook scripts, the context-updater agent, settings.json entries, and the quality rule.
Troubleshooting
| Issue | Fix |
| Hooks not firing | chmod +x .claude/hooks/*.sh |
| No output after commit | Delete .git/.context-guard-last-check to reset throttle |
| "jq: command not found" | Install jq: apt install jq or brew install jq |
| Claude loops on stop | Verify context-guard-stop.sh checks stop_hook_active flag; or remove Stop entry from settings.json |
| Tier 2 false positive | Stage a context file with a minor update, or remove the commit guard PreToolUse entry |
Untether Compatibility
When running via Untether (Telegram bridge), context-guard-stop.sh checks UNTETHER_SESSION env var and exits immediately — Stop hook blocks would displace user content in Telegram output. All other hooks (drift check, structural reminders, content filter, commit guard) work normally. If you don't use Untether, this has no effect.
Hook System Reference
For the complete hook event catalogue (17 events), handler types (command, http, prompt, agent), advanced features (async, once, timeout, matcher, updatedInput, CLAUDE_ENV_FILE), and settings.json schema, load the companion reference: SKILL-reference.md
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

