# Context Optimization

Should be used for improving context efficiency: context budgeting, observation...

- Repository: https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering (18272 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-10-12
- Runs scripts: yes, review before use

## Install

Claude Code: `npx skills add muratcankoylan/Agent-Skills-for-Context-Engineering --skill context-optimization -g -a claude-code -y`
Codex: `npx skills add muratcankoylan/Agent-Skills-for-Context-Engineering --skill context-optimization -g -a codex -y`
Cursor: `npx skills add muratcankoylan/Agent-Skills-for-Context-Engineering --skill context-optimization -g -a cursor -y`
Gemini CLI: `npx skills add muratcankoylan/Agent-Skills-for-Context-Engineering --skill context-optimization -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add muratcankoylan/Agent-Skills-for-Context-Engineering`

## Description

This skill should be used for improving context efficiency: context budgeting, observation masking, prefix or KV-cache strategy, partitioning, token-cost reduction, retrieval scoping, and extending effective context capacity without lowering answer quality.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Context Optimization Techniques

Context optimization extends the effective capacity of limited context windows through strategic compression, masking, caching, and partitioning. Effective optimization increases useful capacity without requiring larger models or longer windows, but only when applied with measurement discipline. The techniques below are ordered by impact and risk.

## When to Activate

Activate this skill when:
- Context budgets or token costs constrain task complexity
- Observation masking can replace verbose tool outputs with retrievable references
- Prefix or KV-cache hit rate needs improvement
- Retrieval scoping can reduce irrelevant loaded context
- Context partitioning can extend effective capacity across agents
- Budget triggers are needed for masking, compaction, or partitioning

Do not activate this skill for adjacent work owned by other skills:
- Explaining why attention or context windows behave this way: `context-fundamentals`.
- Diagnosing active lost-in-middle, poisoning, distraction, confusion, or clash: `context-degradation`.
- Designing a structured handoff summary for a long conversation: `context-compression`.
- Storing large outputs, plans, or logs as files: `filesystem-context`.
- Model-initiated rewrites of its own context and their re-prefill cost: `self-managed-context`.

## Core Concepts

Apply four primary strategies in this priority order:

1. **KV-cache optimization**, Reorder and stabilize prompt structure so the inference engine reuses cached Key/Value tensors. This is the cheapest optimization when the runtime supports prefix caching: low quality risk, immediate cost and latency savings. Apply it first when stable prefixes exist.

The rest: https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/blob/HEAD/skills/context-optimization/SKILL.md
