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, and 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 arrive as file references and stay out of context until read.
- Read selectively: Use
head, tail, or grep on 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.md for core concepts, the 50% rule, and quick-start code examples.
- Context Analysis: See
modules/mecw-assessment.md for risk identification.
- Workflow Delegation: See
modules/subagent-coordination.md for decomposition patterns.
- Context Waiting: See
modules/context-waiting.md for deferred loading strategies.
- Cache Alignment: See
modules/cache-aligned-prefixes.md for ordering context so provider KV caches hit (stable prefix first, volatile last).
- Compression Choice: See
modules/compression-strategies.md to pick one
of /clear and /catchup, a continuation agent, archive and summarize, or
delegation, with savings and risk.
- Large Tool Outputs: See
modules/reversible-compression.md for
archiving an oversized output to a retrievable handle.
- Pasted Logs: See
modules/log-debugging-hygiene.md for filtering a log
before any compression. /filter-log anchors on it.
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
1---2name: context-optimization3description: Optimizes context window via MECW principles and memory tiering. Use when context exceeds 30% or before long multi-step tasks.4alwaysApply: false5category: conservation6token_budget: 1507progressive_loading: true8modules:9- modules/context-waiting.md10- modules/findings-format.md11- modules/mecw-assessment.md12- modules/mecw-principles.md13- modules/memory-tiers.md14- modules/session-routing.md15- modules/subagent-coordination.md16- modules/belief-clarity.md17- modules/cache-aligned-prefixes.md18- modules/compression-strategies.md19- modules/reversible-compression.md20- modules/log-debugging-hygiene.md21role: hook-target22metadata:23 source: https://skillmd.com/skills/athola/context-optimization24---2526# Context Optimization Hub2728## When To Use2930- **Threshold Alert**: When context usage approaches 50% of the window.31- **Complex Tasks**: For operations requiring multi-file analysis or long tool chains.3233## When NOT To Use3435- Simple single-step tasks with low context usage36- Already using mcp-code-execution for tool chains3738## Core Hub Responsibilities39401. Assess context pressure and MECW compliance.412. Route to appropriate specialized modules.423. Coordinate subagent-based workflows.434. Manage token budget allocation across modules.445. Synthesize results from modular execution.4546## Module Selection Strategy4748```python49def select_optimal_modules(context_situation, task_complexity):50 if context_situation == "CRITICAL":51 return ["mecw-assessment", "subagent-coordination"]52 elif task_complexity == "high":53 return ["mecw-principles", "subagent-coordination"]54 else:55 return ["mecw-assessment"]56```5758## Context Classification5960| Utilization | Status | Action |61|-------------|--------|--------|62| < 30% | LOW | Continue normally |63| 30-50% | MODERATE | Monitor, apply principles |64| > 50% | CRITICAL | Immediate optimization required |6566## Large Output Handling (Claude Code 2.1.2+)6768**Behavior Change**: Large bash command and tool outputs are saved to disk instead of being truncated, and file references are provided for access.6970### Impact on Context Optimization7172| Scenario | Before 2.1.2 | After 2.1.2 |73|----------|--------------|-------------|74| Large test output | Truncated, partial data | Full output via file reference |75| Verbose build logs | Lost after 30K chars | Complete, accessible on-demand |76| Context pressure | Less from truncation | Same - only loaded when read |7778### Best Practices7980- **Avoid pre-emptive reads**: Large outputs arrive as file references and stay out of context until read.81- **Read selectively**: Use `head`, `tail`, or `grep` on file references.82- **Use full data**: Quality gates can access complete test results via files.83- **Monitor growth**: File references are small, but reading the full files adds to context.8485## Integration Points8687- **Token Conservation**: Receives usage strategies, returns MECW-compliant optimizations.88- **CPU/GPU Performance**: Aligns context optimization with resource constraints.89- **MCP Code Execution**: Delegates complex patterns to specialized MCP modules.9091## Resources9293- **MECW Theory**: See `modules/mecw-principles.md` for core concepts, the 50% rule, and quick-start code examples.94- **Context Analysis**: See `modules/mecw-assessment.md` for risk identification.95- **Workflow Delegation**: See `modules/subagent-coordination.md` for decomposition patterns.96- **Context Waiting**: See `modules/context-waiting.md` for deferred loading strategies.97- **Cache Alignment**: See `modules/cache-aligned-prefixes.md` for ordering context so provider KV caches hit (stable prefix first, volatile last).98- **Compression Choice**: See `modules/compression-strategies.md` to pick one99 of `/clear` and `/catchup`, a continuation agent, archive and summarize, or100 delegation, with savings and risk.101- **Large Tool Outputs**: See `modules/reversible-compression.md` for102 archiving an oversized output to a retrievable handle.103- **Pasted Logs**: See `modules/log-debugging-hygiene.md` for filtering a log104 before any compression. `/filter-log` anchors on it.105106## Troubleshooting107108### Common Issues109110If 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.111112## Exit Criteria113114- [ ] Context pressure assessed against the MECW 50% rule115- [ ] A memory tier or routing decision recorded for the current state116- [ ] Large outputs referenced by file or handle, not read in full117- [ ] When the request controls the provider payload, prefix ordering checked118 against `modules/cache-aligned-prefixes.md` (stable first, volatile last)119- [ ] Optimization downgraded to advisory when the harness already caches120 (cache writes cost more than they save on non-repeated prefixes)