context-guard
Installs opt-in Claude Code hooks that detect stale AI context files (CLAUDE.md, AGENTS.md, GEMINI.md, etc.) and remind developers to update them. Includes post-commit drift detection, structural change reminders, and a quality rule. Claude Code only — hooks do not work in OpenCode, Codex CLI, or other tools.
Best use case
context-guard is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Installs opt-in Claude Code hooks that detect stale AI context files (CLAUDE.md, AGENTS.md, GEMINI.md, etc.) and remind developers to update them. Includes post-commit drift detection, structural change reminders, and a quality rule. Claude Code only — hooks do not work in OpenCode, Codex CLI, or other tools.
Teams using context-guard should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/context-guard/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How context-guard Compares
| Feature / Agent | context-guard | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Installs opt-in Claude Code hooks that detect stale AI context files (CLAUDE.md, AGENTS.md, GEMINI.md, etc.) and remind developers to update them. Includes post-commit drift detection, structural change reminders, and a quality rule. Claude Code only — hooks do not work in OpenCode, Codex CLI, or other tools.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Context Guard
## What It Does
Context Guard adds two PostToolUse hooks and one quality rule to a project. The hooks detect when AI context files (CLAUDE.md, AGENTS.md, GEMINI.md, .cursorrules, copilot-instructions.md, .windsurfrules, .clinerules) are out of date and nudge the developer to update them.
**Claude Code only.** These hooks use Claude Code's hook system (PostToolUse events, `.claude/settings.json` configuration). OpenCode, Codex CLI, Cursor, Windsurf, Cline, and Gemini CLI do not support Claude Code hooks. The quality rule (`.claude/rules/context-quality.md`) is also Claude Code-specific.
Cross-tool features like skills (`.claude/skills/`) and AGENTS.md work in OpenCode and Codex CLI without Context Guard.
## Components
### Hook: context-drift-check.sh
- **Event:** PostToolUse on `Bash` (filters for `git commit` commands)
- **Fires:** After a successful git commit
- **Checks:**
1. Compares each context file's last-modified commit vs the most recent source-code commit
2. Detects broken file-path references inside context files
3. Flags when `package.json` or `pyproject.toml` changed more recently than context files
- **Output:** Lists stale files and recommends `/ai-context audit`, or stays silent if everything is current
- **Throttle:** Max once per hour via `.git/.context-guard-last-check` timestamp
### Hook: context-structural-change.sh
- **Event:** PostToolUse on `Write|Edit`
- **Fires:** After creating or editing structural files (commands, skills, agents, rules, manifests, config)
- **Reminds:** Which context files may need updating based on the type of change
- **File patterns:**
- `commands/*.md` → AGENTS.md, CLAUDE.md, llms.txt
- `.claude/skills/*/SKILL.md` → AGENTS.md, CLAUDE.md, llms.txt
- `.claude/agents/*.md` → AGENTS.md
- `.claude/rules/*.md` → CLAUDE.md, AGENTS.md
- `package.json`, `pyproject.toml`, config files → all context files
### Rule: context-quality.md
Auto-loaded every session. Establishes cross-file consistency, path verification, version accuracy, command accuracy, and a sync-points table mapping project changes to context files.
## Installation
The `/context-guard install` command:
1. Copies hook scripts to `.claude/hooks/` in the target project
2. Merges hook configuration into `.claude/settings.json`
3. Copies the quality rule to `.claude/rules/context-quality.md`
4. Makes hook scripts executable
### Settings.json Configuration
```json
{
"hooks": {
"PostToolUse": [
{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": ".claude/hooks/context-drift-check.sh"
}]
},
{
"matcher": "Write|Edit",
"hooks": [{
"type": "command",
"command": ".claude/hooks/context-structural-change.sh"
}]
}
]
}
}
```
## Uninstallation
The `/context-guard uninstall` command removes the hook scripts, settings.json entries, and the quality rule.
## Customisation
### Throttle Interval
Edit `context-drift-check.sh` line with `3600` (seconds) to change the check interval. Set to `0` to check on every commit.
### File Patterns
Edit `context-structural-change.sh` case statement to add or remove structural file patterns.
## Troubleshooting
| Issue | Cause | Fix |
|-------|-------|-----|
| Hooks not firing | Scripts not executable | `chmod +x .claude/hooks/*.sh` |
| No output after commit | Throttle active | Delete `.git/.context-guard-last-check` to reset |
| "jq: command not found" | jq not installed | Install jq: `apt install jq` or `brew install jq` |
| Hook errors in logs | Wrong project directory | Check `CLAUDE_PROJECT_DIR` is set correctly |Related Skills
extracting-ai-context
Extracts and manages AI context (skills, AGENTS.md) from workflow-kotlin library JARs. Use when setting up AI tooling for a workflow-kotlin project, updating skills after a library version change, or configuring agent-specific directories.
create-agent-with-sanity-context
Build AI agents with structured access to Sanity content via Context MCP. Covers Studio setup, agent implementation, and advanced patterns like client-side tools and custom rendering.
context-optimizer
Analyzes Copilot Chat debug logs, agent definitions, skills, and instruction files to audit context window utilization. Provides log parsing, turn-cost profiling, redundancy detection, hand-off gap analysis, and optimization recommendations. Use when optimizing agent context efficiency, identifying where to add subagent hand-offs, or reducing token waste across agent systems.
context-fundamentals
Understand the components, mechanics, and constraints of context in agent systems. Use when designing agent architectures, debugging context-related failures, or optimizing context usage.
context-engineering
Use when designing agent system prompts, optimizing RAG retrieval, or when context is too expensive or slow. Reduces tokens while maintaining quality through strategic positioning and attention-aware design.
context-degradation
Recognize patterns of context failure: lost-in-middle, poisoning, distraction, and clash
context-assembler
Assembles relevant context for agent spawns with prioritized ranking. Ranks packages by relevance, enforces token budgets with graduated zones, captures error patterns for learning, and supports configurable per-agent retrieval limits.
Codebase context
Create a lightweight codebase_context.md that anchors the idea in the existing repo (modules, constraints, extension points). Generic framework prompt.
agentguard
GoPlus AgentGuard — AI agent security guard. Automatically blocks dangerous commands, prevents data leaks, and protects secrets. Use when reviewing third-party code, auditing skills, checking for vulnerabilities, evaluating action safety, or viewing security logs.
agent-context-system
A persistent local-only memory system for AI coding agents. Two files, one idea — AGENTS.md (committed, shared) + .agents.local.md (gitignored, personal). Agents read both at session start, update the scratchpad at session end, and promote stable patterns over time. Works across Claude Code, Cursor, Copilot, Windsurf. Subagent-ready. No plugins, no infrastructure, no background processes.
add-route-context
为Flutter页面添加路由上下文记录功能,支持日期等参数的AI上下文识别。当需要让AI助手通过"询问当前上下文"功能获取页面状态(如日期、ID等参数)时使用。适用场景:(1) 日期驱动的页面(日记、活动、日历等),(2) ID驱动的页面(用户详情、订单详情等),(3) 任何需要AI理解当前页面参数的场景
localsetup-context
Localsetup v2 framework context - overview, invariants, and skills index. Load first when working in a repo that uses Localsetup v2. Use when starting work in this repo or when user asks about framework rules.