/optimize-context
Analyze and optimize context window usage using MECW principles
$ npx -y skills add athola/claude-night-market --agent claude-codeHow 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.mdname: 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
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:-.}"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.
Other commands on claude-night-market.
- /aggregate-logs
Generate LEARNINGS.md from skill execution logs.
Open command - /analyze-skill
Analyze skill file complexity metrics and generate modularization recommendations for splitting or progressive loading.
Open command - /bulletproof-skill
Harden skills against rationalization and bypass behaviors
Open command - /context-report
Generate context optimization report for skill directories
Open command - /create-command
Create slash commands with brainstorming and best practices
Open command - /create-hook
Create hooks with brainstorming and security-first design
Open command

