Sponsored byOutsenseAI that finds your next clients
SponsorGROUOutbound, LinkedIn content and leads for B2B teamsSponsorOutsenseAI that finds your next clientsAd+Your tool hereSeen by people installing AI tools@Weekly picksThe best new tools, one email a week

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.

  • Score 94
  • 18k stars
  • MIT
  • Updated
Works withClaude CodeClaude apps Antigravity CLI

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-optimization

Run in your terminal. Claude Code loads skills from ~/.claude/skills automatically.

Step-by-step: install context-optimization in Claude Code

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

A

No 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 →

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.

context-optimization Install

Add to stack

Loading.