一键导入
context-optimization
Activate when hitting context limits, experiencing quality degradation in long sessions, or needing to extend effective context capacity.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Activate when hitting context limits, experiencing quality degradation in long sessions, or needing to extend effective context capacity.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | context-optimization |
| version | 1.0.0 |
| description | Activate when hitting context limits, experiencing quality degradation in long sessions, or needing to extend effective context capacity. |
| triggers | ["context-limit","optimization","compaction","masking","token-budget","long-session","cache"] |
Techniques for maximizing available context window capacity through strategic optimization rather than requiring larger models. Focuses on getting more useful work done within existing constraints.
Summarize context near capacity limits. Replace verbose message history with structured summaries that preserve key decisions, file changes, and next steps. Target 50-70% token reduction.
When to use: Message history is growing large, conversation has been going for many turns, earlier exchanges are no longer directly relevant.
How: Compress earlier conversation into a structured summary at the start of context, keeping recent exchanges intact. The summary should preserve:
Replace verbose tool outputs with compact references. Tool outputs can comprise 80%+ of token usage in agent trajectories. Most of that content is never referenced again.
When to use: Tool-heavy workflows (running tests, reading large files, searching codebases).
How: After processing a tool result, replace it with a brief summary: "Read src/payment.ts (245 lines) - found PaymentService class with 3 public methods." The full content was already processed; the summary preserves what was learned.
Reuse cached computations across requests sharing identical prefixes. When system prompts and early context are identical across calls, the model can skip recomputing attention for those tokens.
Practical impact: Keep system prompts and static context (like skill files) stable across turns. Avoid reordering or modifying the beginning of context between calls.
Distribute work across isolated sub-agents. Each sub-agent gets a fresh context window for focused subtasks, preventing context degradation on long-running tasks.
When to use: Tasks that naturally decompose into independent subtasks. Research tasks where multiple files need deep analysis. Tasks exceeding what a single context window can handle well.
Deciding which strategy to apply:
Context dominated by tool outputs → Apply observation masking
Context dominated by documents → Apply summarization/extraction
Context dominated by messages → Apply compaction
All of the above → Apply context partitioning (sub-agents)
Compaction summary format:
## Session Summary (Turn 1-15)
**Objective:** Refactor PaymentService to use Value Objects
**Modified:** src/payment/service.ts, src/payment/email.ts (new)
**Decisions:** Using readonly properties for VOs, PHPUnit for tests
**Blocked:** Need to update 3 consumers of PaymentService
**Next:** Update CheckoutController to use new Email VO
context-fundamentals (attention budget concepts)context-compression (specific compression algorithms), filesystem-context (offloading to filesystem as optimization)Activate when an Engineering Manager needs to shape a rough initiative into a clear, scoped, outcome-oriented brief before execution.
Activate when reviewing branches, commits, or pull requests using the emoji-driven review protocol.
Activate when managing conversation history in long sessions, choosing compression strategies, or preserving critical information during context truncation.
Activate when designing agent systems, debugging unexpected agent behavior, or optimizing context usage and attention budgets.
Activate when generating in-code comments or system documentation using the Diátaxis framework.
Activate when testing agent systems, measuring output quality, or designing evaluation frameworks for AI-assisted workflows.