Skip to content
Skills Library
AI & agents · Planning

context-optimization

/context-optimization

Optimizes context window via MECW principles and memory tiering. Use when context exceeds 30% or before long multi-step tasks.

Licence
MIT
Last repository change
01.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
13
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 01.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Optimizes context window via MECW principles and memory tiering. Use when context exceeds 30% or before long multi-step tasks.

Original author description

Optimizes context window via MECW principles and memory tiering. Use when context exceeds 30% or before long multi-step tasks.

How it works

  1. When To Use
  2. When NOT To Use
  3. Core Hub Responsibilities
  4. Module Selection Strategy
  5. Context Classification
  6. Large Output Handling (Claude Code 2.1.2+)
  7. Integration Points
  8. Resources
  9. Troubleshooting
  10. Exit Criteria
Original SKILL.md headings · 97 lines, 576 words
SKILL.md preview
---
name: context-optimization
description: Optimizes context window via MECW principles and memory tiering. Use when context exceeds 30% or before long multi-step tasks.
alwaysApply: false
category: conservation
token_budget: 150
progressive_loading: true
modules:
- modules/context-waiting.md
- modules/findings-format.md
- modules/mecw-assessment.md
- modules/mecw-principles.md
- modules/memory-tiers.md
- modules/session-routing.md
- modules/subagent-coordination.md
- modules/belief-clarity.md
- modules/cache-aligned-prefixes.md
- modules/compression-strategies.md
- modules/reversible-compression.md
- modules/log-debugging-hygiene.md
hooks:
  PreToolUse:
  - matcher: Read
    command: 'echo "[skill:context-optimization] 📊 Context analysis started: $(date)"
      >> ${CLAUDE_CODE_TMPDIR:-/tmp}/skill-audit.log

      '
    once: true
  PostToolUse:
  - matcher: Bash
    command: "# Track context analysis tools\nif jq -r '.tool_input.command // empty' | grep\
      \ -qE \"(wc|tokei|cloc|context)\"; then\n  echo \"[skill:context-optimization]\
      \ Context measurement executed: $(date)\" >> ${CLAUDE_CODE_TMPDIR:-/tmp}/skill-audit.log\n\
      fi\n"
  Stop:
  - command: 'echo "[skill:context-optimization] === Optimization completed at $(date)
      ===" >> ${CLAUDE_CODE_TMPDIR:-/tmp}/skill-audit.log

      # Could export: context pressure events over time

      '
model_hint: standard
role: hook-target
---

# 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

1. Assess context pressure and MECW compliance.
2. Route to appropriate specialized modules.
3. Coordinate subagent-based workflows.
4. Manage token budget allocation across modules.
5. Synthesize results from modular execution.

## Module Selection Strategy

```python
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`, 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

- [ ] 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)
Files in this package (13)
  • SKILL.md 6 KB
  • modules/belief-clarity.md 4 KB
  • modules/cache-aligned-prefixes.md 4 KB
  • modules/compression-strategies.md 3 KB
  • modules/context-waiting.md 9 KB
  • modules/findings-format.md 2 KB
  • modules/log-debugging-hygiene.md 8 KB
  • modules/mecw-assessment.md 5 KB
  • modules/mecw-principles.md 17 KB
  • modules/memory-tiers.md 2 KB
  • modules/reversible-compression.md 6 KB
  • modules/session-routing.md 3 KB
  • modules/subagent-coordination.md 24 KB

Versions

RepositoryScoreLicence
This page · athola/claude-night-market100MIT
atretyak1985/swarmery100Apache-2.0
dhar174/langgraph_system_generator100MIT
AbdullahMalik17/Digital-FTE100MIT
seb1n/awesome-ai-agent-skills100MIT
bcastelino/agent-skills-kit100MIT
viktorbezdek/skillstack100MIT
VoDaiLocz/kilo-kit-mcp90Apache-2.0

Database snapshot: 13.11.2026 · package version 827fefd38710 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 86cw
    Inspects and compacts the active LLM context window, KV cache prefix, stale file reads, and noisy tool outputs via contextWatcher (`cw`). Use when context exceeds 80k tokens, health score drops, or the user asks to optimize/compact context.
  • 86context-watcher
    Inspects and compacts the active LLM context window, KV cache prefix, stale file reads, and noisy tool outputs via contextWatcher (`cw`). Use when context exceeds 80k tokens, health score drops, or the user asks to optimize/compact context.
  • 90agent-map-reduce
    Split a large task across parallel agents that each handle one slice, then merge their outputs deliberately. Use when the work exceeds one context window or would take too long serially.
  • 100context-engineering
    Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.
  • 95context-engineering
    Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.
  • 100context-engineering
    Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.