context-optimization
하는 일
이 스킬은 제한된 컨텍스트 창 안에 더 많은 유용한 작업을 담는 방법을 다룹니다. 예를 들면 장황한 도구 출력을 가리기, 캐시된 프롬프트 앞부분 재사용, 여러 에이전트로 작업 나누기입니다. AI 비용을 줄이거나 더 큰 작업을 하려는 팀을 위한 스킬입니다.
사용하는 경우
- ✓작업이 컨텍스트 공간을 다 쓰거나 토큰 비용이 너무 많이 들 때.
- ✓긴 도구 출력이 에이전트가 거의 필요로 하지 않는 세부 내용으로 컨텍스트를 채울 때.
- ✓반복되는 비용을 줄이려고 프롬프트의 캐시된 부분을 재사용하고 싶을 때.
스킬 링크
https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/blob/main/skills/context-optimization/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“에이전트의 도구 출력이 컨텍스트를 너무 빨리 채웁니다. 품질을 잃지 않고 대화를 가볍게 유지하는 방법을 보여 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
스킬은 영향과 위험에 따라 기법의 순위를 매깁니다. 출력 마스킹, 프롬프트 시작 부분 캐싱, 작업 분할 등이 있으며, 각 변경을 측정하라고 말합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
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:
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.
Observation masking — Replace verbose tool outputs with compact references once their purpose has been served. Tool outputs can dominate agent trajectories (claim-context-optimization-tool-output-dominance), so masking often yields the largest capacity gains. The original content remains retrievable if needed downstream.
Compaction — Summarize accumulated context when utilization exceeds 70%, then reinitialize with the summary. This distills the window's contents while preserving task-critical state. Compaction is lossy — apply it after masking has already removed the low-value bulk.
Context partitioning — Split work across sub-agents with isolated contexts when a single window cannot hold the full problem. Each sub-agent operates in a clean context focused on its subtask. Reserve this for tasks where estimated context exceeds 60% of the window limit, because coordination overhead is real.
The governing principle: context quality matters more than quantity. Every optimization preserves signal while reducing noise. Measure before optimizing, then measure the optimization's effect.
Detailed Topics
Compaction Strategies
Trigger compaction when context utilization exceeds 70%: summarize the current context, then reinitialize with the summary. This distills the window's contents in a high-fidelity manner, enabling continuation with minimal performance degradation. Prioritize compressing tool outputs first (they consume 80%+ of tokens), then old conversation turns, then retrieved documents. Never compress the system prompt — it anchors model behavior and its removal causes unpredictable degradation.
Preserve different elements by message type:
- Tool outputs: Extract key findings, metrics, error codes, and conclusions. Strip verbose raw output, stack traces (unless debugging is ongoing), and boilerplate headers.
- Conversational turns: Retain decisions, commitments, user preferences, and context shifts. Remove filler, pleasantries, and exploratory back-and-forth that led to a conclusion already captured.
- Retrieved documents: Keep claims, facts, and data points relevant to the active task. Remove supporting evidence and elaboration that served a one-time reasoning purpose.
Target 50-70% token reduction with less than 5% quality degradation. If compaction exceeds 70% reduction, audit the summary for critical information loss — over-aggressive compaction is the most common failure mode.
Observation Masking
Mask observations selectively based on recency and ongoing relevance — not uniformly. Apply these rules:
- Never mask: Observations critical to the current task, observations from the most recent turn, observations used in active reasoning chains, and error outputs when debugging is in
자주 묻는 질문
관찰 마스킹이란 무엇인가요?
긴 도구 출력을 짧은 참조로 바꾸는 방식이며, 에이전트는 필요할 때 그 참조를 다시 찾아볼 수 있습니다.
프리픽스 캐싱이란 무엇인가요?
프롬프트의 변하지 않는 시작 부분을 재사용해서, 모델이 매번 다시 처리하지 않게 하는 방식입니다.
이렇게 하면 답변 품질이 떨어지나요?
스킬은 각 변경을 측정하라고 말합니다. 답변 품질이 유지될 때만 그 기법을 쓰면 됩니다.
상세 정보
작성자의 원본 설명
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.
인기도
- GitHub 스타
- 18k
- 순위
- #10640
- 라이선스
- MIT
- 업데이트
- 2026. 10. 11.
댓글
- …
이 저장소의 다른 스킬
context-engineering-collection
18k에이전트가 AI 모델의 컨텍스트 창에 들어가는 내용을 관리하도록 돕습니다. 메모리와 도구부터 다중 에이전트 구성, 평가까지 다룹니다.
advanced-evaluation
18k에이전트가 다른 AI를 이용해 AI 답변을 평가하는 방법을 가르칩니다. 점수 매기기, 나란히 비교, 편향 점검을 포함합니다.
bdi-mental-states
18k에이전트가 BDI 방식으로 믿음, 목표, 계획을 모델링하도록 가르쳐서, 결정을 추적하고 설명할 수 있게 합니다.
context-compression
18k에이전트가 긴 AI 세션을 결정, 파일, 위험, 다음 단계를 유지한 요약으로 줄이도록 돕습니다.
비슷한 스킬
add-model-provider
394k에이전트가 안전한 설정 명령으로 새 AI 모델 제공자를 OpenClaw에 연결하고, API 키를 평문으로 두지 않으며, 실시간 테스트를 실행하도록 돕습니다.
acp-router
394k에이전트가 OpenClaw를 통해 Claude Code나 Cursor 같은 코딩 도우미에 작업을 전달해, 작업이 그 도구에서 실행되도록 돕습니다.
browser-automation
394k에이전트가 로그인, 탭, 페이지 응답이 멈췄을 때의 복구를 포함해 웹 페이지를 단계별로 조작하도록 가르칩니다.