context-optimization

Applies compaction, observation masking, KV-cache optimization, and partitioning to extend LLM context capacity.

Updated Apr 13, 2026
One-click install
npx skills add https://github.com/scoots31/engineering-playbook --skill context-optimization-scoots31
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: context-optimization
Source: https://github.com/scoots31/engineering-playbook/tree/main/references/context-optimization
Command: npx skills add https://github.com/scoots31/engineering-playbook --skill context-optimization-scoots31

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Long-running agents and long conversations hit context window limits, driving up token costs, latency, and quality degradation. This Skill provides a disciplined set of techniques to reduce token usage while preserving task-critical information. ## Core Features & Use Cases - KV-Cache Optimization: Order prompts so stable content forms a reusable prefix, targeting 70%+ cache hit rates and major cost and latency savings. - Observation Masking & Compaction: Replace verbose tool outputs with compact references and summarize context at 70-80% utilization, targeting 50-70% token reduction with minimal quality loss. - Context Partitioning & Budgeting: Split work across sub-agents with isolated contexts and allocate explicit token budgets per context category. - Use Case: A production agent handling multi-hour debugging sessions keeps exceeding its context window. Apply masking to old tool outputs, trigger compaction at 80% utilization, and stabilize the prompt prefix to cut costs in half. ## Quick Start Ask the AI to optimize the context usage of your long-running agent by applying masking, compaction, and cache-friendly prompt ordering.

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 costs in long LLM conversations?

Apply observation masking to verbose tool outputs first, then trigger compaction when context utilization exceeds 70-80%. Stabilize your prompt prefix for KV-cache reuse, which alone can cut costs by 50% or more on cached tokens.

What is observation masking in agent context management?

Observation masking replaces verbose tool outputs with compact references once their key points are extracted, storing full content externally for later retrieval. It targets 60-80% reduction in masked observations with under 2% quality impact.

When should I compact context instead of masking it?

Mask first to remove low-value bulk like old tool outputs, then compact what remains when utilization crosses 70-80%. Compaction is lossy summarization, so it works best after masking has already stripped redundant content.

Why does my KV-cache hit rate drop after prompt changes?

Any change to the prompt prefix, even a single whitespace or a timestamp in the system prompt, invalidates the cached block downstream. Keep system prompts immutable and move dynamic metadata into user messages or tool results.

When should I partition work across sub-agents?

Partition when estimated task context exceeds 60% of the window limit and the task decomposes into at least three independent subtasks. Below that threshold, coordination overhead typically exceeds the token savings.

What are the risks of aggressive context compaction?

Over-aggressive compaction drops task goals, user constraints, and nuanced state, especially when the compacting model is itself above 85% utilization. Trigger compaction at 70-80% and re-validate summaries against the current task goal.