
Context Optimization Techniques
Teaches an agent to cut token use and extend usable context via masking, caching, compaction and partitioning
- Stars
- 18,282
- Licence
- MIT
- Files
- 3 files
What it does
When installed, the agent follows a set of guidelines for managing its limited working memory on long tasks: it replaces bulky tool outputs with short references, orders prompts so cached content can be reused, summarizes context when it gets too full, and suggests splitting work across sub-agents when needed. The skill is written as guidance with thresholds (for example, compaction around 70% utilization) and includes a Python utility file with helper functions for estimating tokens, categorizing messages, and tracking masked observations and cache metrics.
Great for
- Developers building long-running agents that hit context or token-cost limits
- Engineers tuning prompt structure for prefix or KV-cache hit rates
- Teams deciding whether a task needs sub-agent partitioning
Skip it if
- Simple, short chats where context limits never matter, since the overhead adds complexity without benefit
- Situations needing exact token counts or real cache metrics: the bundled script uses a rough 4-characters-per-token estimate and illustrative cache numbers, which its own notes say must be replaced in production
- Tasks where lossy summarization is unacceptable, such as legal or compliance records, because compaction can drop critical details
Try asking
- “Our agent runs out of context halfway through long debugging sessions. How should we mask old tool outputs?”
- “Review my prompt structure and tell me how to improve prefix cache hit rate.”
- “Decide whether this multi-file refactor should be split across sub-agents.”
- “Set up a context budget with triggers for compaction and masking in my agent loop.”
Install in 3 steps
- 1
Download the skill
The ZIP contains the 3 original files, the MIT licence and an attribution note.
context-optimization.zip - 2
Add it to your agent
Claude Code (all projects)
mkdir -p ~/.claude/skills && unzip context-optimization.zip -d ~/.claude/skills/Claude Code / Agent SDK (this project only)
mkdir -p .claude/skills && unzip context-optimization.zip -d .claude/skills/Claude apps (web/desktop): Settings → Capabilities → Skills → Upload skill, and choose the ZIP.
- 3
Ask for the task
No special command needed — the agent reads the skill's description and loads it when your request matches. Try one of the prompts above.
Get better results
- Treat the thresholds (70% compaction, 60% partitioning, 70% cache hit target) as starting points and measure your own results before and after applying them.
- Replace the script's character-based token estimate with your model's real tokenizer before relying on its budget numbers.
- Apply masking before compaction, since compaction is lossy and masking removes low-value bulk first.
What's inside
- references/optimization_techniques.md
- scripts/compaction.py
- SKILL.md
Redistributed unmodified from muratcankoylan/Agent-Skills-for-Context-Engineering under the MIT licence. The assessment was drafted with AI from the skill's files on 2026-10-29. Skills can instruct your agent to run code — read SKILL.md and any scripts before installing.