Context window auto-management — signals, strategies, and recovery protocol. Detects approaching context limits and guides compact vs checkpoint decisions to prevent lost work.
From clarcnpx claudepluginhub marvinrichter/clarc --plugin clarcThis skill uses the workspace's default tool permissions.
Designs and optimizes AI agent action spaces, tool definitions, observation formats, error recovery, and context for higher task completion rates.
Enables AI agents to execute x402 payments with per-task budgets, spending controls, and non-custodial wallets via MCP tools. Use when agents pay for APIs, services, or other agents.
Compares coding agents like Claude Code and Aider on custom YAML-defined codebase tasks using git worktrees, measuring pass rate, cost, time, and consistency.
Strategies for detecting, responding to, and recovering from context window pressure. The session-end hook warns when sessions exceed 90 minutes without a .clarc/context.md, prompting a checkpoint.
/compact or context is nearing capacity.clarc/ memory bank so session-end hooks automatically persist context across restarts| Signal | Threshold | Action |
|---|---|---|
| Session length | > 90 min | Create .clarc/context.md checkpoint |
| File count in task | > 20 files | Split into phases with checkpoints |
| Token estimate | > 80% of window | /compact or summarize |
| Repeated context loads | Same files > 3x | Extract summary to working file |
| Tool call depth | > 50 in session | /checkpoint create before continuing |
/compact automaticallyBefore running /compact, always checkpoint:
/checkpoint create pre-compact
The checkpoint records:
After compaction, restore with:
/checkpoint verify pre-compact
cat .clarc/context.md
.clarc/context.md is the canonical session handoff document (written by session-end hook automatically). Keep it current during long sessions:
# Session Context — 2026-03-09
## Current focus
- Implementing REST API authentication middleware
- Files: src/middleware/auth.ts, tests/unit/auth.test.ts
## Progress
- [x] JWT validation logic
- [x] Unit tests passing
- [ ] Integration test
- [ ] Rate limiting
## Key decisions
- Using RS256 (not HS256) for multi-service JWT
- Middleware runs before route handlers
## Next steps
1. Write integration test (src/tests/integration/auth.test.ts)
2. Add rate limiting (src/middleware/rate-limit.ts)
Update manually at logical milestones or run:
/checkpoint create milestone-name
For large tasks spanning many files, summarize as you go:
Working summary pattern:
This reduces re-reading costs and fits more analysis in the context window.
Break large implementations into phases, each fitting in one context window:
Phase 1: Plan + design (separate session or first context)
Output: docs/specs/feature-plan.md
Phase 2: Core implementation
Input: feature-plan.md (small, loaded fresh)
Output: core files
Phase 3: Tests + edge cases
Input: feature-plan.md + list of core files
Output: test files
Phase 4: Review + cleanup
Input: git diff (compact representation)
Output: final commits
Each phase starts fresh with minimal context load.
When context has been lost or compacted mid-task:
1. Read .clarc/context.md # Memory Bank (if exists)
2. Run: git log --oneline -10 # Recent commits
3. Run: git diff HEAD # Current changes
4. Run: git stash list # Any stashed work
5. Read checkpoint log:
cat .claude/checkpoints.log
6. Reconstruct state and continue
If .clarc/context.md is up to date, recovery takes < 2 minutes.
The session-end hook (scripts/hooks/session-end.js) automatically:
.clarc/context.md at session end (if .clarc/ exists).clarc/progress.mdTo opt in: mkdir .clarc in your project root.
Approximate token budget guidance. Context window size varies by model — check current limits at Anthropic docs. The proportions below apply regardless of the exact window size:
| Component | Typical tokens | Notes |
|---|---|---|
| System prompt + rules | ~8k | Fixed |
| Conversation history | ~40k | Grows over session |
| Working files | ~30k | Keep focused |
| Tool outputs | ~20k | Flush when done |
| Available for new work | ~30k | After 90 min session (assumes ~128k window) |
When available budget drops below ~20k: checkpoint + compact.
Reading entire files on every step wastes context budget rapidly.
Turn 1: Read src/auth/jwt.ts (800 tokens)
Turn 2: Read src/auth/jwt.ts again (800 tokens — forgot it was already loaded)
Turn 3: Read src/middleware/index.ts (1,200 tokens)
Turn 4: Read src/middleware/index.ts (1,200 tokens — re-loaded for reference)
Turn 5: Read src/auth/jwt.ts (800 tokens — needed one function again)
Total wasted re-reads: ~3,800 tokens
Compounded across a 50-file refactor, re-reads alone consume 20–30k tokens.
Turn 1: Read src/auth/jwt.ts
→ Write working note: "jwt.ts exports: verifyToken(token), signToken(payload, opts)"
Turn 2: Read src/middleware/index.ts
→ Append to working note: "middleware/index.ts mounts: auth (jwt), rateLimit, cors"
Turn 3: (work continues using the working note — never re-read jwt.ts)
# Working note stays under 200 tokens; replaces thousands of re-read tokens
Rule of thumb: After reading a file, extract the 3–5 facts you need from it into a working note. Use the note for the rest of the session; re-read the file only if you need the exact text (e.g., before an edit).
These patterns signal you are re-reading unnecessarily:
When you notice this: stop, write a one-paragraph working summary, and continue from the summary.