Skip to content
Development
Command

/optimize-context

Analyze and optimize context window usage using MECW principles

From plugin
claude-night-market
325163 skills59 agents163 commands1 MCP
Install
$ npx -y skills add athola/claude-night-market --agent claude-code

How it fires

How this command gets triggered: by you, by Claude, or both.

  • Fires itselfClaude auto-loads it when your prompt matches the work.
  • You can call itInvoke it directly when you want it.
  • Slash command/optimize-context

Context preview

What this command does when you run it.

Analyze and optimize context window usage using MECW principles

Command definition

optimize-context.md
name: optimize-context
description: Analyze and optimize context window usage using MECW principles
usage: /optimize-context [path]

Optimize Context Usage

Analyzes context window usage and provides optimization recommendations based on Maximum Effective Context Window (MECW) principles.

Usage

# Analyze current session context
/optimize-context

# Analyze specific skill or directory
/optimize-context skills/my-skill

# Deep analysis with recommendations
/optimize-context --detailed

What It Does

1. **Context Pressure Assessment**: Evaluates current context utilization 2. **MECW Compliance Check**: Validates against MECW principles 3. **Optimization Recommendations**: Suggests specific improvements 4. **Token Budget Analysis**: Breaks down token usage by component

MECW Thresholds

| Utilization | Status | Action | |-------------|--------|--------| | < 30% | Optimal | No action needed | | 30-50% | Good | Monitor growth | | 50-70% | Warning | Consider optimization | | > 70% | Critical | Immediate action required |

Examples

/optimize-context
# Output:
# Context Optimization Report
# ==========================
# Current Usage: 45% (Good)
# Estimated Tokens: 12,500
#
# Recommendations:
# - Consider extracting code examples to scripts/
# - 3 skills exceed recommended token budget

/optimize-context skills/context-optimization --detailed
# Full breakdown with per-module analysis

Headless Mode (Non-Interactive)

For reading context in headless/automated Claude Code sessions:

# Get context breakdown with JSON output
claude -p "run /context" --verbose --output-format json

# Two-call pattern for reliable execution
# (Claude doesn't always execute /context on first prompt)
SESSION_ID=$(claude -p "ready" --output-format json | jq -r '.session_id')
claude --continue "$SESSION_ID" -p "/context" --verbose --output-format json

**Key flags:**

  • `--verbose`: Includes categorical token breakdown
  • `--output-format json`: Machine-parseable output
  • `--continue`: Resumes existing session for reliable command execution

**Example JSON output:**

{
  "context": {
    "total_tokens": 45000,
    "usage_percent": 22.5,
    "breakdown": {
      "system": 8000,
      "conversation": 32000,
      "tools": 5000
    }
  }
}

Integration

Works with conservation plugin skills:

  • `context-optimization` - Core MECW implementation
  • `token-conservation` - Token reduction strategies
  • `optimizing-large-skills` - Modularization patterns

Implementation

python3 ${CLAUDE_PLUGIN_ROOT}/scripts/growth_analyzer.py "${1:-.}"
Read more
Ships withclaude-night-market

A plugin marketplace for Claude Code. Install only the plugins you need to run git workflows, code review, spec-driven development, and autonomous agents from inside your Claude Code session.

Get the whole plugin, auto-invoked
Stats
325
Stars
0
Views
35
Forks
Active
Maintenance
Python
Language
MIT
License
1d ago
Last commit
8mo ago
Created

Repo: athola/claude-night-market