context-optimization
Skill by muratcankoylan
Guides an AI agent through context optimization, including token budgeting, observation masking, KV-cache ordering, compaction and context partitioning. Aimed at developers building agents that run long tasks within limited context windows.
Install context-optimization
Built from the published package, never by AI.
git clone --depth 1 https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering /tmp/Agent-Skills-for-Context-Engineering && mkdir -p ~/.claude/skills && cp -r /tmp/Agent-Skills-for-Context-Engineering/skills/context-optimization ~/.claude/skills/context-optimizationRun in your terminal. Claude Code loads skills from ~/.claude/skills automatically.
git clone --depth 1 https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering /tmp/Agent-Skills-for-Context-Engineering && mkdir -p ~/.gemini/antigravity-cli/skills && cp -r /tmp/Agent-Skills-for-Context-Engineering/skills/context-optimization ~/.gemini/antigravity-cli/skills/context-optimizationAntigravity CLI loads skills from ~/.gemini/antigravity-cli/skills, or .agents/skills for one project.
Step-by-step: install context-optimization in Antigravity CLI
Skills can run scripts on your machine. Some need an API key: check the README.
About
The context-optimization skill gives an agent techniques for getting more useful work out of a limited context window. It ranks four strategies by impact and risk: KV-cache optimization, observation masking, compaction, and context partitioning. It also covers budget management, with explicit token allocations per context category and triggers that start optimization when utilization crosses 70% or 80%.
The skill sets concrete targets, such as 50-70% token reduction from compaction with under 5% quality degradation, and a 70%+ cache hit rate for stable workloads. It stresses measuring before and after each change, and removing techniques that do not measurably help. It is written for developers and agents working on long tasks where token cost or context limits constrain results. Related topics such as context degradation and file-based storage are handled by other skills.
Written from the project's SKILL.md and checked against it.
What it can do
- KV-cache optimizationOrders prompts so stable content forms a cacheable prefix and dynamic content comes last.
- Observation maskingReplaces verbose tool outputs with compact references once their purpose has been served.
- CompactionSummarizes accumulated context above 70% utilization, then reinitializes with the summary.
- Context partitioningSplits work across sub-agents with isolated contexts when estimated context exceeds 60% of the window.
- Budget managementAllocates token budgets across context categories and sets triggers for optimization.
- Optimization decision frameworkPicks the first technique based on what dominates the current context.
Try asking
- Order my agent prompt so the stable parts hit the KV-cache.
- Set a token budget for system prompt, tool outputs and history with a buffer.
- When should I mask tool outputs instead of compacting my conversation?
Good to know
- Compaction is lossy, and over-aggressive compaction is the most common failure mode.
- Masked observations must be stored externally so the full content stays retrievable.
- Partitioning only pays off when savings exceed the coordinator's token overhead.
Security check
ANo download-and-run commands, hidden instructions or signs of sending keys out were found.
Checked automatically: skills/context-optimization/SKILL.md, skills/context-optimization/scripts/compaction.py. This looks for known risky patterns and is not a full audit. How grades work
Inside the skill
-
SKILL.md16 KB -
references/optimization_techniques.md9 KB -
scripts/compaction.py19 KB
Alternatives to context-optimization
All alternatives →Aligns a Qwen Code feature with a Codex or Claude Code reference agent. It runs both under the same scenario, captures HTTP and terminal traces, and compares them until behavior matches.
Searches, views, creates, updates, and deletes the user's Google Contacts from an AI assistant. It is for people who want to manage their address book through conversation. A one-time Google connect is required before it returns data.
Guides an AI assistant on error handling choices. It covers when to use Result, Option, ? propagation, unwrap, expect and panic, plus anyhow and thiserror.
Caveman is an agent skill that makes an AI assistant reply in a terse style. It cuts filler and keeps technical facts, code, commands and errors exact. It is built for users who want shorter, cheaper replies.
docs-sync audits or updates English SDK documentation against the requested implementation scope. It is for maintainers who want docs to match main branch features, configuration options, and defaults.
Guides an AI assistant through setting up and running monorepos with pnpm workspaces, Turborepo and Nx. Aimed at developers who need faster builds, shared code and managed dependencies across multiple packages.
Compare with agent-reproduce-align, google_contacts or m06-error-handling
context-optimization: common questions
When should context be compacted?
The skill says to trigger compaction when context utilization exceeds 70%, summarizing first and then reinitializing with the summary. It should run after masking has removed low-value bulk.
Does this skill require a larger model?
No. The source says effective optimization increases useful capacity without larger models or longer windows, but only when applied with measurement.
Should the system prompt ever be compressed?
No. The source says never compress the system prompt, because removing it causes unpredictable degradation.
How do I install context-optimization?
Run the command above to copy the skill into ~/.claude/skills/. Claude Code picks it up automatically.
Is context-optimization free?
The code is published under the MIT licence. The service it connects to may have its own pricing.
Is context-optimization safe to use?
It scores 94 of 100. Grades: maintenance A, licence A, quality A. Security check: grade A, no risky patterns found in the files checked. Review the code before you install. How grades work.
What are alternatives to context-optimization?
Similar skills: agent-reproduce-align, google_contacts, m06-error-handling, caveman.
