Skip to content
Back to skills

Context Optimization

ASecurity

Extend effective context capacity through strategic compression, masking, caching, and partitioning.

  • 7 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 3, 2026
ai-agentspythongo

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned September 3, 2026

npx -y skills add mediar-ai/skillhubz --skill context-optimization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Context Optimization?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Context Optimization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mediar-ai-context-optimization/badge)](https://www.skillsdirectory.com/skills/mediar-ai-context-optimization)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Context Optimization Techniques

Extend effective context capacity through strategic compression, masking, caching, and partitioning.

## Prerequisites

- Understanding of context windows
- Familiarity with token economics

## Instructions

### Optimization Strategies

**Compaction**: Summarize context near limits, reinitialize with summary.
- Target 50-70% token reduction
- Less than 5% quality degradation

**Observation Masking**: Replace verbose tool outputs with references.
- Tool outputs can be 80%+ of token usage
- Store full output, return summary + reference

**KV-Cache Optimization**: Reuse cached computations for common prefixes.
- Place stable elements first (system prompt, tool definitions)
- Avoid dynamic content like timestamps

**Context Partitioning**: Split work across sub-agents with isolated contexts.
- Each sub-agent gets fresh context
- Aggregate results at coordination layer

### Compaction Priority

1. Tool outputs → replace with summaries
2. Old turns → summarize early conversation
3. Retrieved docs → summarize if recent versions exist
4. Never compress → system prompt

### Observation Masking Strategy

**Never mask**: Critical observations, most recent turn, active reasoning

**Consider masking**: 3+ turns ago, verbose outputs with extractable key points

**Always mask**: Repeated outputs, boilerplate, already-summarized content

### Cache-Friendly Ordering

```python
context = [system_prompt, tool_definitions]  # Stable, cacheable
context += [reused_templates]                 # Reusable
context += [unique_content]                   # Unique per request
```

## Guidelines

1. Measure before optimizing—know your current state
2. Apply compaction before masking when possible
3. Design for cache stability with consistent prompts
4. Partition before context becomes problematic
5. Balance token savings against quality preservation

## Notes

- Context quality matters more than quantity
- Optimization can double or triple effective capacity
- Monitor token utilization and trigger at 70-80%

Source: muratcankoylan/Agent-Skills-for-Context-Engineering

Files in this skill

  • manifest.json338 B
  • skill.md2.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…