context-optimization
Optimizes context window via MECW principles and memory tiering. Use when context exceeds 30% or before long multi-step tasks.
它会碰到什么
这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。
技能内容
Table of Contents
- [When to Use](#when-to-use)
- [Core Hub Responsibilities](#core-hub-responsibilities)
- [Module Selection Strategy](#module-selection-strategy)
- [Context Classification](#context-classification)
- [Integration Points](#integration-points)
- [Resources](#resources)
Context Optimization Hub
When To Use
- Threshold Alert: When context usage approaches 50% of the window.
- Complex Tasks: For operations requiring multi-file analysis or long tool chains.
When NOT To Use
- Simple single-step tasks with low context usage
- Already using mcp-code-execution for tool chains
Core Hub Responsibilities
- Assess context pressure and MECW compliance.
- Route to appropriate specialized modules.
- Coordinate subagent-based workflows.
- Manage token budget allocation across modules.
- Synthesize results from modular execution.
Module Selection Strategy
def select_optimal_modules(context_situation, task_complexity):
if context_situation == "CRITICAL":
return ["mecw-assessment", "subagent-coordination"]
elif task_complexity == "high":
return ["mecw-principles", "subagent-coordination"]
else:
return ["mecw-assessment"]
Context Classification
| Utilization | Status | Action |
|-------------|--------|--------|
| < 30% | LOW | Continue normally |
| 30-50% | MODERATE | Monitor, apply principles |
| > 50% | CRITICAL | Immediate optimization required |
Large Output Handling (Claude Code 2.1.2+)
Behavior Change: Large bash command and tool outputs are saved to disk instead of being truncated; file references are provided for access.
Impact on Context Optimization
| Scenario | Before 2.1.2 | After 2.1.2 |
|----------|--------------|-------------|
| Large test output | Truncated, partial data | Full output via file reference |
| Verbose build logs | Lost after 30K chars | Complete, accessible on-demand |
| Context pressure | Less from truncation | Same - only loaded when read |
Best Practices
- Avoid pre-emptive reads: Large outputs are referenced, not automatically loaded into context.
- Read selectively: Use
head,tail, orgrepon file references. - Use full data: Quality gates can access complete test results via files.
- Monitor growth: File references are small, but reading the full files adds to context.
Integration Points
- Token Conservation: Receives usage strategies, returns MECW-compliant optimizations.
- CPU/GPU Performance: Aligns context optimization with resource constraints.
- MCP Code Execution: Delegates complex patterns to specialized MCP modules.
Resources
- MECW Theory: See
modules/mecw-principles.mdfor core concepts, the 50% rule, and quick-start code examples. - Context Analysis: See
modules/mecw-assessment.mdfor risk identification. - Workflow Delegation: See
modules/subagent-coordination.mdfor decomposition patterns. - Context Waiting: See
modules/context-waiting.mdfor deferred loading strategies. - Cache Alignment: See
modules/cache-aligned-prefixes.mdfor ordering context so provider KV caches hit (stable prefix first, volatile last).
Troubleshooting
Common Issues
If context usage remains high after optimization, check for large files that were read entirely rather than selectively. If MECW assessments fail, ensure that your environment provides accurate token count metadata. For permission errors when writing output logs to /tmp, verify that the project's temporary directory is writable.
Exit Criteria
- [ ] Context pressure assessed against the MECW 50% rule
- [ ] A memory tier or routing decision recorded for the current state
- [ ] Large outputs referenced by file or handle, not read in full
- [ ] When the request controls the provider payload, prefix ordering checked
against modules/cache-aligned-prefixes.md (stable first, volatile last)
- [ ] Optimization downgraded to advisory when the harness already caches
(cache writes cost more than they save on non-repeated prefixes)
想直接用这个技能?
本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。
它属于哪个仓库
plugins/conserve/skills/context-optimization/SKILL.md同一个仓库里的其他技能
- claude-code-plugin-reference
- night-market-architecture-contract
- night-market-build-and-env
- night-market-change-control
- night-market-collective-memory
- night-market-completion-integrity-campaign
- night-market-config-catalog
- night-market-debugging-playbook
- night-market-diagnostics-toolkit
- night-market-docs-and-writing
- night-market-failure-archaeology
- night-market-model-and-harness-updates