Context optimization

From athola/claude-night-market · View interactive version

Context optimization is an AI agent skill from the GitHub repository athola/claude-night-market. Optimizes context window via MECW principles and memory tiering. Use when context exceeds 30% or before long multi-step tasks.

How to use this skill

Skill file

Context Optimization Hub

When To Use

When NOT To Use

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

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

Integration Points

Resources

of /clear and /catchup, a continuation agent, archive and summarize, or

delegation, with savings and risk.

archiving an oversized output to a retrievable handle.

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

against modules/cache-aligned-prefixes.md (stable first, volatile last)

(cache writes cost more than they save on non-repeated prefixes)

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.