ctx-guard
/ctx-guard
Behavioral context self-check before a handoff. Use when the user asks whether the conversation is getting too long, after a context compaction, when the model starts repeating rejected plans or forgetting edited files, or whenever starting a fresh session is being considered. Runs three recall tests, cross-checks them against the real working tree, and returns a green/yellow/red verdict plus an optional handoff document.
- Author
- Arid-G1FT ↗
- Repository
- ctx-handoff-sentinel ↗
- Licence
- MIT
- Last repository change
- 09.11.2026
Assessment and security
- Files in this package
- 6
- Scripts
- 3
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 09.11.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
- 3 scripts in this package. Review them before installing, as Claude may execute them.
Scripts: scripts/guard.py, scripts/handoff.py, tests/test_guard.py
What it does and when to use it
Behavioral context self-check before a handoff. Use when the user asks whether the conversation is getting too long, after a context compaction, when the model starts repeating rejected plans or forgetting edited files, or whenever starting a fresh session is being considered. Runs three recall tests, cross-checks them against the real working tree, and returns a green/yellow/red verdict plus an optional handoff document.
Arguments
/ctx-guard [check|handoff] [reason]
Original author description
Behavioral context self-check before a handoff. Use when the user asks whether the conversation is getting too long, after a context compaction, when the model starts repeating rejected plans or forgetting edited files, or whenever starting a fresh session is being considered. Runs three recall tests, cross-checks them against the real working tree, and returns a green/yellow/red verdict plus an optional handoff document.
How it works
- When to run
- Protocol — run this silently
- Verdict policy (what the script enforces)
- Reporting format
- After the verdict
SKILL.md preview
---
name: ctx-guard
description: Behavioral context self-check before a handoff. Use when the user asks whether the conversation is getting too long, after a context compaction, when the model starts repeating rejected plans or forgetting edited files, or whenever starting a fresh session is being considered. Runs three recall tests, cross-checks them against the real working tree, and returns a green/yellow/red verdict plus an optional handoff document.
argument-hint: "[check|handoff] [reason]"
allowed-tools: Bash(python3:*), Bash(python:*), Bash(git status:*), Bash(git diff:*), Read, Write
---
# Context handoff sentinel
Decide **whether the current context can still prove itself**, then hand off if it
cannot. Never decide from turn count, context percentage, or compaction count:
those say when to *test*, not whether to leave.
## When to run
- The user asks "should I start a new conversation", "is this context getting
stale", or invokes `/ctx-guard`.
- The host reports a context compaction.
- You notice degradation: repeating a rejected plan, forgetting which files you
edited, two versions of the same fact, needing the same constraint re-explained.
- Before writing a handoff document for another session.
## Protocol — run this silently
Do not dump the questionnaire into the conversation. The user wants the verdict,
not the exam.
1. **Read the ground truth** (do not let it influence your answers): `git status
--porcelain` and `git diff --stat`. If this is not a git repository, say so in
the evidence line and rely on what you actually wrote this session.
2. **Answer the three questions from memory only.** Do not grep/read files to
reconstruct the answers; that would test the filesystem, not the context.
- A. Immovable constraints still in force, each with its source.
- B. Files actually changed this session, with *what* and *why*, and one key
line you still remember from one of them.
- C. The next step and a runnable verification command.
If you cannot recall something, say so in `unknowns` — honesty is the point.
3. **Write the report JSON** to `.ctx-guard/report.json` in the workspace:
```json
{
"verdict": "green|yellow|red",
"objective": "one line: what this session set out to finish",
"constraints": [{"text": "do not touch X", "source": "user", "certain": true}],
"files": [{"path": "src/a.ts", "change": "added null guard", "reason": "crash on empty input", "certain": true}],
"done": ["parser built and fuzzed"],
"verified": [{"command": "npm test", "result": "12 passed"}],
"nextStep": "run the migration and check the failing test",
"verify": ["npm test -- src/a.test.ts"],
"unknowns": ["whether the staging flag was enabled"],
"decisions": ["chose a queue over polling because the API rate-limits"],
"failedAttempts": ["retrying with a 100ms sleep still hit 429"],
"spotCheckFile": "src/a.ts"
}
```
`objective`, `done`, `verified`, `decisions`, and `failedAttempts` are optional
but they are exactly what the handoff document needs — without them the next
session re-derives the project from scratch.
4. **Run the evidence check** from the workspace root:
```sh
python3 "$SKILL_DIR/scripts/guard.py" --root . --report .ctx-guard/report.json
```
`$SKILL_DIR` is the directory containing this SKILL.md (Claude Code exposes it
as `${CLAUDE_SKILL_DIR}`; Codex users pass the path explicitly). On Windows use
`python` when `python3` is missing. If Python is unavailable, apply the policy
below by hand and print the same verdict block.
5. **Print only the verdict block** the script returns, verbatim. No A/B/C dump.
6. **Handoff** when the user asked for one or the verdict is red:
```sh
python3 "$SKILL_DIR/scripts/handoff.py" --root . --report .ctx-guard/report.json
```
Print the returned path and the opener from the document.
Exit code `2` from `guard.py` means **red**, not a crash; still print its output.
## Verdict policy (what the script enforces)
The model's own verdict is the baseline. Evidence overrides it only on hard
contradictions:
| Hard contradiction | Verdict |
| --- | --- |
| The report admits it cannot recall the constraints/rules | 🔴 |
| ≥90% of changed files omitted, with at least 10 files written | 🔴 |
| ≥10 files written but the report lists none | 🔴 |
| The working tree changed ≥3 files but the report lists none (fewer than 10) | 🟡 |
| The report omits more than half of the changed files (and ≥2) | 🟡 |
| ≥3 reported files are absent from the baseline and dominate the report | 🟡 |
| No next step, or no runnable verification command | 🟡 |
Everything else is a **note, not a demotion**: a few omitted helper files,
shell-written paths outside git, honestly declared unknowns, short reasons,
"no constraints" when nothing was pinned.
Rationale: a healthy conversation must not be graded yellow for omitting scratch
files — but losing almost all of them is not noise, it is the failure the red
verdict exists for. Full rules: `references/policy.md`.
## Reporting format
```
ctx-guard · 🟡 YELLOW
reasons: ...
notes: ...
evidence: 12 changed · 7 reported · 5 missing · 0 unverified (baseline: git working tree)
```
Keep it to that block. If the user wants the detail, they can open
`.ctx-guard/report.json` or ask.
## After the verdict
- 🟢 **green** — keep working; the context still proves itself.
- 🟡 **yellow** — finish only the current sub-goal, do not expand scope, then
run the handoff step.
- 🔴 **red** — stop adding work. Write the handoff now and start a fresh session
from the document.
Files in this package (6)
- SKILL.md 6 KB
- agents/openai.yaml 1 KB
- references/policy.md 3 KB
- scripts/guard.py 14 KB
- scripts/handoff.py 9 KB
- tests/test_guard.py 5 KB
Versions
The database has no other skills named ctx-guard.
Database snapshot: 13.11.2026 · package version 84e041fb4034 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 90session-guard
Use when working on complex multi-step tasks, when a session is getting long (40+ tool calls), when the agent starts ignoring rules it followed earlier, when conventions drift, when output quality seems to degrade, or after any context compaction event. Prevents long-session… - 100session-handoff
Compact the conversation into a handoff document for a fresh agent. It writes what only the conversation knows and links records, issues and commits instead of copying them. Use when the user asks for a handoff, when context runs low, or before passing the work to another session. - 100quick-recap
Use when the user wants each agent response to end with a red/yellow/green status line showing whether the work is finished, pending a follow-up, or blocked on input. - 81evermind
Keep session context small to cut usage, with persistent memory. Use when a hook message starts with "[evermind]", when the user types /evermind [dashboard|status|panel|handoff|switch|digest|search|remember|resolve|history|report], says "refresh context" or "remember this"… - 100ctx-init
Initialize AGENTS.md + CLAUDE.md + rules/ in a code repo (fresh mode). Triggers on "/ctx-init", "init context", "scaffold AGENTS.md", or when user asks to set up project context in a new repo. - 100ctx-recall
Browse session history. Use when referencing past discussions or finding context from previous work.