context-optimization

Apply compaction, masking, caching, and partitioning techniques to extend LLM context capacity.

9|2|Updated Jan 31, 2026
One-click install
npx skills add https://github.com/AbdullahMalik17/Hacathan_5 --skill context-optimization-abdullahmalik17
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: context-optimization
Source: https://github.com/AbdullahMalik17/Hacathan_5/tree/main/.claude/skills/context-optimization
Command: npx skills add https://github.com/AbdullahMalik17/Hacathan_5 --skill context-optimization-abdullahmalik17

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Long-running agents and extended conversations quickly exhaust limited context windows, driving up token costs, latency, and response quality degradation. This Skill provides concrete techniques to compress, mask, cache, and partition context so agents stay effective within fixed token budgets. ## 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, reclaiming 60-80% of tokens while keeping content retrievable. - KV-Cache Optimization: Reorder prompts with stable prefixes first and strip dynamic content like timestamps to maximize cache hit rates and reduce cost and latency. - Context Partitioning & Budgeting: Split work across isolated sub-agent contexts and enforce explicit token budgets per category with trigger-based optimization. - Use Case: A customer support agent handling multi-hour conversations hits 80% context utilization; apply compaction to summarize early turns and mask stale tool outputs, cutting token usage in half without losing task state. ## Quick Start Use the context-optimization skill to compact this conversation history and mask verbose tool outputs so the agent can continue within its context limit.

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 conversation turns and tool outputs when utilization exceeds 80%, and mask verbose observations with reference IDs. These techniques typically achieve 50-70% token reduction with minimal quality loss.

What is observation masking in agent systems?

Observation masking replaces verbose tool outputs with compact reference IDs stored in an ObservationStore, since tool outputs can consume over 80% of tokens. The full content remains retrievable by reference while the summary preserves key points in context.

How do I improve KV-cache hit rates for LLM prompts?

Place stable content like system prompts and tool definitions first, and remove dynamic elements such as timestamps and session IDs from prompt prefixes. Stable prefixes enable prefix caching, targeting 70%+ hit rates for consistent workloads.

When should I trigger context compaction?

Trigger compaction when context utilization exceeds 80% of the limit, with a warning threshold at 70% and aggressive compaction at 90%. Also trigger on quality degradation signals like attention degradation or dropping quality scores.

What are the limitations of context compaction?

Over-aggressive compaction can remove critical information like task goals, user preferences, and recent context. Never compress the system prompt, and test compaction at increasing aggressiveness to balance token savings against quality preservation.

How accurate is the token estimation in the scripts?

The scripts use a rough heuristic of about 4 characters per token for English text. Production systems should use model-specific tokenizers like tiktoken for OpenAI models or HuggingFace tokenizers for local models.