optimize-context

optimize-context is a command for Claude Code from athola/claude-night-market. It costs 14 tokens per session (624 once invoked), scanned A, original, MIT.

A command that measures how much of the agent's context window is being used and checks it against MECW, or Maximum Effective Context Window, principles.

In plain words
What is it for?
Use it to review context pressure, token usage, and possible reductions for the current session or a specified skill or directory.
Why use it?
It shows when a session, skill, or directory is using too much context and identifies where that usage comes from.

Command for Claude Code

Written for Claude Code: ${CLAUDE_PLUGIN_ROOT} variable. Also seen: mentions Claude Code.

Runs only inside its plugin — its command needs a path that Claude Code sets for a plugin’s own hooks and for nothing else. Install the plugin, not this.

Part of the conserve plugin — 15 skills, 6 commands, 5 agents shipped together

Good fit Use it to review context pressure, token usage, and possible reductions for the current session or a specified skill or directory.

Compare 6 commands from other repositories ↓
Install

Getting it into your agent

This one installs as part of its plugin. Adding the marketplace and installing the plugin brings it with everything else the plugin ships.

Claude Code
/plugin marketplace add athola/claude-night-market
Claude Code
/plugin install conserve

Made for: Claude Code.

Or install conserve, the plugin that ships this one along with the rest of its 15 skills, 6 commands, 5 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for optimize-context

README.md
[![agentmods](https://agentmods.dev/badge/commands/athola/claude-night-market/optimize-context.svg)](https://agentmods.dev/commands/athola/claude-night-market/optimize-context)
Your own site
<a href="https://agentmods.dev/commands/athola/claude-night-market/optimize-context"><img src="https://agentmods.dev/badge/commands/athola/claude-night-market/optimize-context.svg" alt="Measured on agentmods" height="20"></a>
Per session 14 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 624 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00014 $0.00624
Opus 5 $0.00007 $0.00312
Sonnet 5 $0.00003 $0.00125
Haiku 4.5 $0.00001 $0.00062

Measured 4d ago against content hash 789de9e5a743, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

optimize-context scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/conserve/commands/optimize-context.md · 104 lines

How it starts

The opening of the file, as written. The whole thing — 104 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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
    }
  }
}

Read the full file on GitHub · 104 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 104 lines · 14 tokens per session scan A 789de9e5a743

Subscribe to this mod's changes

optimize-context is a command published in the GitHub repository athola/claude-night-market (335 stars, last pushed yesterday), licensed MIT. It adds 14 tokens to every session and 624 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.