context-window-management
Skill38 starsChanged 8 months agoApache-2.0View on GitHub
Use when working on multi-step tasks, long conversations, or when agent output quality degrades mid-session. Techniques for keeping context lean so the model produces better results.
8 other projects use a version of this.
Adopted by
Most recently taken up by
- Wsh7Ash/skillmcptheir own version, first seen Nov 8, 2026
- lauren-framework/lauren-aitheir own version, first seen Nov 1, 2026
- xfstudio/skillstheir own version, first seen Oct 13, 2026
- varunk130/ai-workflow-playbookstheir own version, first seen May 22, 2026
- Fandry96/k3-agentic-skillstheir own version, first seen May 12, 2026
- hmzainjamil/claude-ai-skillstheir own version, first seen May 10, 2026
Other versions8 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 8
- Fandry96/k3-agentic-skills★ 27same name
- xfstudio/skills★ 9same name
- hmzainjamil/claude-ai-skills★ 3same name
- ai4brands-design/claude-skills★ 2same name
- varunk130/ai-workflow-playbooks★ 2same name
- lauren-framework/lauren-ai★ 0same name
- tjennychen/claude-context-window-management★ 0same name
- Wsh7Ash/skillmcp★ 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 repository15 other files it gives its agents.
- adversarial-code-reviewSkill
- agent-maintained-docsSkill
- brainstorming-plannerSkill
- crispi-planningSkill
- documentation-first-setupSkill
- expert-persona-skillsSkill
- hooks-and-enforcementSkill
- merge-conflict-resolutionSkill
- objective-researchSkill
- parallel-agent-managementSkill
- product-researchSkill
- three-layer-memorySkill
- validation-runnerSkill
- visual-regressionSkill
- voice-first-planningSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
15 rules. 0 are common, 14 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
14
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
When agent output quality drops mid-conversation (hallucinations, repetition, ignoring instructions)
- Distinctive: line 18
When combining multiple prompt sources (system prompt, CLAUDE.md, tool results, user instructions)
- Distinctive: line 19
When tool calls return large payloads (logs, file contents, API responses)
- Distinctive: line 20
When a task requires more than 3-4 back-and-forth exchanges
- Distinctive: line 26
When you are already under 40% context utilization
- Distinctive: line 43
Before starting work, count the instructions the model will receive from all sources combined:
- Distinctive: line 50
Target total: under 150-200 instructions across all sources: If you are over, cut the lowest-priority instructions.
- Distinctive: line 59
Never target higher than 60%.
- Distinctive: line 63
When a tool call returns a large result (file contents, logs, API responses):
- Very specific: line 65
Write the full result to a temporary file (e.g., docs/scratch/tool-output-<timestamp>.md).
- Distinctive: line 95
When this happens: save state to a file and start a new session.
- Distinctive: line 99
When writing instructions (system prompts, CLAUDE.md, project rules):
- Distinctive: line 102
Use actual control flow for branching logic: If you find yourself writing "If X, do Y.
- Distinctive: line 104
Delete instructions that duplicate tool descriptions: If a tool's schema already describes its behavior, don't repeat it in prose.
- Distinctive: line 121
The context window is working memory, not storage: Use files for storage. Load into context only what the current step requires.
“Common” is measured: kept by at least 6 in 10 of the 6 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 Window Management
Overview
Techniques for managing what goes into the context window so the model stays focused and produces high-quality output. The core insight is counterintuitive: less context produces better results. Stuffing the context window with everything available degrades performance. Instead, save state to files, keep prompts short, and restart sessions when confused.
Core principle: The context window is expensive working memory, not cheap storage. Offload state to files and load only what you need right now.
When to Use
- At the start of any multi-step implementation (plan your context budget before you begin)
- When agent output quality drops mid-conversation (hallucinations, repetition, ignoring instructions)
- When combining multiple prompt sources (system prompt, CLAUDE.md, tool results, user instructions)
- When tool calls return large payloads (logs, file contents, API responses)
- When a task requires more than 3-4 back-and-forth exchanges
When NOT to Use
- Single-shot questions with short answers
- Tasks that genuinely need the full context loaded (e.g., cross-file refactors where all files fit comfortably)
- When you are already under 40% context utilization
Common Mistakes
| Mistake | Why it's wrong |
| Dumping entire file contents into context | Large tool results push out earlier instructions. Offload to a file and show only the first ~100 lines. Harrison Chase: "Load the first hundred lines, let the agent ask for more." |
| Writing 50+ instructions in a single prompt | The model starts dropping instructions past ~40. Dex: "Keep individual prompts under 40 instructions." Budget across all sources. |
| Using the system prompt for control flow logic | Prompts are for goals and constraints, not if/else branching. Use actual code for control flow. Dex: "Don't use prompts for control flow -- use actual control flow." |
| Continuing a confused conversation instead of restarting | Accumulated confusion compounds. Josh: "Clear and restart when confused. More context is not always better." |
| Treating the context window as a notebook | Important state belongs in static markdown files on disk, not carried in the conversation. Context is volatile; files are persistent. |
| Ignoring total instruction count across sources | Your system prompt, CLAUDE.md, tool descriptions, and user message all share one budget of ~150-200 instructions max. Going over means something gets silently dropped. |
Technique: Context Budget Planning
Step 1: Audit your instruction sources
Before starting work, count the instructions the model will receive from all sources combined:
- System prompt / custom instructions: How many directives?
- Project instructions (CLAUDE.md, etc.): How many rules?
- Tool descriptions: Each tool schema counts against the budget.
- User message: How many asks in this turn?
Target total: under 150-200 instructions across all sources. If you are over, cut the lowest-priority instructions. No single source should exceed 40 instructions.
Step 2: Set your context utilization target
| Experience level | Max context utilization | Why |
| Beginner / unfamiliar codebase | 40% | Leave headroom for mistakes and recovery |
| Experienced / familiar codebase | 60% | You can be more precise about what to include |
Never target higher than 60%. The remaining space is needed for the model's own reasoning and output generation.
Step 3: Offload large results to files
When a tool call returns a large result (file contents, logs, API responses):
- Write the full result to a temporary file (e.g.,
docs/scratch/tool-output-<timestamp>.md). - Show only the first ~100 lines in the conversation.
- Reference the file path so the agent can read more if needed.
# Instead of pasting 2000 lines of logs:
[First 100 lines of build output shown]
Full output saved to: docs/scratch/build-output-2026-03-04.logStep 4: Save state to markdown artifacts
At natural breakpoints in a multi-step task, write the current state to a markdown file:
- What has been completed
- What remains
- Key decisions made and why
- File paths modified
Save to docs/scratch/ or a similar scratch directory. This lets you restart the conversation fresh while preserving progress.
Step 5: Recognize when to clear and restart
Signs the context window is degraded:
- The model repeats itself or contradicts earlier statements
- Instructions you gave earlier are being ignored
- The model hallucinates file contents or tool outputs
- Output quality is noticeably worse than at the start of the conversation
When this happens: save state to a file and start a new session. Load only the state file and the next task. Do not try to "remind" the model -- a fresh start with less context will outperform a long conversation every time.
Step 6: Structure prompts for the budget
When writing instructions (system prompts, CLAUDE.md, project rules):
- Under 40 instructions per source. This is the reliable ceiling for a single prompt.
- Use actual control flow for branching logic. If you find yourself writing "If X, do Y; otherwise do Z" in a prompt, move that logic into code that selects which prompt to send.
- Front-load the most important instructions. The model pays more attention to what comes first.
- Delete instructions that duplicate tool descriptions. If a tool's schema already describes its behavior, don't repeat it in prose.
Quick Reference
| Threshold | Value | Source |
| Max instructions per prompt | ~40 | Dex |
| Max total instructions (all sources) | ~150-200 | Dex |
| Beginner context utilization target | 40% | Dex |
| Experienced context utilization target | 60% max | Dex |
| Large tool result preview | First ~100 lines | Harrison Chase |
| Signs of degradation | Repetition, hallucination, ignored instructions | Josh |
| Recovery action | Save state to file, restart session | Josh, Dex |
Key Principles
- Less context = better results. This is the single most important insight. Resist the urge to "give the model everything." Curate ruthlessly.
- The context window is working memory, not storage. Use files for storage. Load into context only what the current step requires.
- Budget instructions across all sources. System prompt + project rules + tool schemas + user message all share one pool of ~150-200 instructions. Exceeding this means silent drops.
- No single prompt over 40 instructions. Past this point, compliance drops. Split into multiple interactions or move logic to code.
- Save state, restart often. A fresh session with a state file beats a long degraded conversation. Make "save and restart" a habit, not a last resort.
- Don't use prompts for control flow. Prompts set goals and constraints. Code handles branching. Mixing the two wastes context and confuses the model.
Attribution
Based on techniques from the Coding Agents: AI Driven Dev Conference. Key contributors: Dex (HumanLayer) on instruction budgets, prompt sizing, and context utilization thresholds; Harrison Chase (LangChain) on offloading large tool results to files; and Josh on recognizing context degradation and the practice of clearing and restarting sessions.
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.

