context-optimization

Optimize LLM context windows through compaction, observation masking, KV-cache reuse, and partitioning.

1|Updated Feb 18, 2026
Ready to run
npx skills add https://github.com/Cramer-69/skills-repository-3af2d1c7 --skill context-optimization-cramer-69
💬 Prompt for ChatGPT / Claude Chat▼
Please help me install this Agent Skill.
Skill: context-optimization
Source: https://github.com/Cramer-69/skills-repository-3af2d1c7/tree/main/packages/Agent-Skills-for-Context-Engineering/skills/context-optimization
Command: npx skills add https://github.com/Cramer-69/skills-repository-3af2d1c7 --skill context-optimization-cramer-69

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Long-running agents and conversations quickly exhaust limited context windows, driving up token costs, latency, and response degradation. This Skill provides concrete techniques to extend effective context capacity without larger models. ## Core Features & Use Cases - Compaction Strategies: Summarize tool outputs, old conversation turns, and retrieved documents when context utilization crosses thresholds, preserving key decisions and metrics. - Observation Masking: Replace verbose tool outputs with compact reference IDs stored in an ObservationStore, cutting token usage by 60-80% on masked content. - KV-Cache Optimization & Partitioning: Design cache-stable prompts with stable prefixes and split work across sub-agents with isolated contexts. - Use Case: A production agent handling multi-hour sessions hits 80% context utilization; use the ContextBudget class to trigger compaction and masking, reducing tokens by half while keeping quality loss under 5%. ## Quick Start Use the context-optimization skill to compact my agent's conversation history and mask old tool outputs now that context usage exceeds 80%.

Frequently Asked Questions about context-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce token usage in long LLM conversations?▼

Apply compaction to summarize old turns and tool outputs when utilization exceeds 80%, and mask verbose observations with reference IDs. The skill's ContextBudget class triggers optimization automatically based on utilization thresholds.

What is observation masking in agent workflows?▼

Observation masking replaces verbose tool outputs with compact references like [Obs:id elided] once they have served their purpose. The ObservationStore class stores full content retrievable by ID while freeing context space.

How does KV-cache optimization reduce LLM costs?▼

KV-cache optimization reuses cached key-value tensors across requests sharing identical prefixes, avoiding recomputation. Place stable elements like system prompts first and avoid dynamic content such as timestamps to maximize cache hit rates.

When should I use context partitioning with sub-agents?▼

Use partitioning when a single context cannot hold the task, splitting work across sub-agents with isolated contexts. Each sub-agent focuses on its subtask while a coordinator aggregates validated results.

What are the limitations of the token estimation in this skill?▼

The estimate_token_count function uses a rough heuristic of about 4 characters per token, which varies by model, content type, and language. Production systems should use model-specific tokenizers like tiktoken or HuggingFace tokenizers.