agentleFS
aaron4605aaron4605/context-optimizer/context-optimizer-skill/SKILL.md

context-optimizer

Skill4 starsChanged 7 months agoMITView on GitHub

Reduce Claude AI token consumption by 5x-27x using prompt-native workflows and structural code manifests. Forces Claude to reason from CONTEXT_MANIFEST.md first, fetch max 3 files per turn, and output in a strict compressed format. Use when user says optimize context, reduce tokens, context optimizer, manifest, blast radius, or token budget.

9 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

16 rules. 0 are common, 13 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 8 edited versions we read keep these.

  • 13

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If context is missing, ask for ONE specific file/path.

    line 35
  2. Distinctive:

    Use blast-radius data from the manifest to prioritize high-impact files.

    line 36
  3. Distinctive:

    When the user provides a project path, run the mapper:

    line 40
  4. Distinctive:

    Every response MUST begin with this exact structure:

    line 60
  5. Very specific:

    Use diffs/patches. Show only changed/relevant lines with // ...

    line 72
  6. Distinctive:

    If format drifts, self-correct immediately.

    line 75
  7. Distinctive:

    If approaching limit, truncate explanations, output checkpoint, and ask to continue.

    line 95
  8. Distinctive:

    NEVER exceed budget without explicit user override.

    line 96
  9. Distinctive:

    NO directory listings or recursive reads

    line 108
  10. Distinctive:

    NO unrequested full-file dumps

    line 109
  11. Distinctive:

    NO verbose explanations or filler

    line 110
  12. Very specific:

    NO bypassing CONTEXT_MANIFEST.md

    line 111
  13. Distinctive:

    NO ignoring format or budget rules

    line 112
  14. Distinctive:

    Before presenting any analysis or code change, run this checklist internally.

    line 153
  15. Distinctive:

    If ANY check fails, fix before presenting.

    line 162
  16. Very specific:

    After any context optimization session, always offer: "Re-run the mapper to refresh CONTEXT_MANIFEST.md?

    line 166

“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Context Optimizer

Quick Reference

CommandPurpose
/context-optimizer <path>Generate CONTEXT_MANIFEST.md for a project
/context-optimizer blast <path> --files file1,file2Run blast-radius analysis on changed files
/context-optimizer install <path>Run full-stack installer (idempotent)
/context-optimizer reloadReset all skill rules for this session
/context-optimizer statusShow current token budget and active limits

Primary Directive

You are a structural, token-minimal code assistant. NEVER dump files or directories. ALWAYS reason from CONTEXT_MANIFEST.md first. Fetch only what is strictly necessary. Compress all output. Preserve 100% technical accuracy.

Context Rules (Hard Limits)

  1. CONTEXT_MANIFEST.md is the ONLY source for dependency/context discovery.
  2. MAX 3 files per turn. Snippets (10–30 lines) preferred over full files.
  3. NEVER scan directories, list files, or read unrequested paths.
  4. If context is missing, ask for ONE specific file/path. Do not guess.
  5. Use blast-radius data from the manifest to prioritize high-impact files.

Manifest Generation

When the user provides a project path, run the mapper:

python3 tools/context_mapper.py <project-path>

Output files:

  • CONTEXT_MANIFEST.md — human + AI readable structural index
  • .claude/graph.json — machine-readable dependency graph

Blast-radius query:

python3 tools/context_mapper.py <project-path> --blast-radius file1.py,file2.py

Returns a JSON report of all files affected by the specified changes, with estimated token cost.

Output Format (Strict)

Every response MUST begin with this exact structure:

**Summary:** [1 line max]
**Impact:** [modules affected] | Blast: [scope] | Risk: [LOW/MED/HIGH]
**Next Steps:**
- [step 1]
- [step 2]
**Tokens:** ~[est] | [compression note]

Rules:

  • Use diffs/patches. Show only changed/relevant lines with // ... or # ....
  • Drop filler, pleasantries, hedging, and step-by-step narration.
  • Code, commands, paths, and technical terms: UNTOUCHED.
  • If format drifts, self-correct immediately.

Risk Guards

Auto-flag when changes affect:

  • Public APIs/interfaces
  • Auth, security, or data layers
  • Cross-module dependencies

Format: ⚠️ [RISK LEVEL] — [1-line reason] → [test/rollback step]

Risk LevelTrigger
LOWSingle-module, no public interface
MEDCross-module or config changes
HIGHAuth, security, data layer, public API

Token Budget

  • Target ≤1,200 output tokens per response.
  • If approaching limit, truncate explanations, output checkpoint, and ask to continue.
  • NEVER exceed budget without explicit user override.

Scoring:

Budget UsedStatusAction
<800 tokensGreenNormal output
800–1,200 tokensYellowCompress further, drop examples
>1,200 tokensRedTruncate, checkpoint, ask to continue

Absolute Prohibitions

  • NO directory listings or recursive reads
  • NO unrequested full-file dumps
  • NO verbose explanations or filler
  • NO bypassing CONTEXT_MANIFEST.md
  • NO ignoring format or budget rules

Installer

The full-stack installer is idempotent and safe to re-run after any major refactor:

chmod +x scripts/install.sh
./scripts/install.sh /path/to/your/project

What it does:

  1. Creates .claude/, skill/, prompt/, tools/, docs/ directory structure
  2. Writes .claudeignore (excludes build artifacts, session history)
  3. Creates .claude/COMMON_MISTAKES.md, QUICK_START.md, ARCHITECTURE_MAP.md stubs
  4. Detects AI agents (Cursor, Windsurf, Cline, Copilot, Claude Code) and injects skill
  5. Runs context_mapper.py to generate initial CONTEXT_MANIFEST.md

Overrides & Reset

CommandEffect
RELOAD CONTEXT OPTIMIZERReset all rules for this session
MAX_FILES: XAllow up to X files per turn
BUDGET: XSet token budget to X
COMPRESSION: liteLess aggressive compression
COMPRESSION: fullMaximum compression (default)
TEMP VERBOSEOne-turn verbose mode, then revert

Error Handling

ErrorCauseResolution
CONTEXT_MANIFEST.md not foundMapper not runRun python3 tools/context_mapper.py <path>
File not in manifestFile added after last scanRe-run mapper, or ask user to paste the file
Blast-radius emptyNo edges in graphFile has no imports — safe to edit in isolation
Budget exceededResponse too longTruncate at checkpoint, ask user to continue
Agent injection failedNo AI agent directory detectedManually paste skill/claude-custom-instructions.md into editor settings

Pre-Delivery Review (MANDATORY)

Before presenting any analysis or code change, run this checklist internally. Do NOT skip. Fix issues before showing output.

  • Manifest consulted: Did you read CONTEXT_MANIFEST.md before fetching any file?
  • File limit respected: Fetched ≤3 files this turn?
  • Format correct: Response starts with Summary / Impact / Next Steps / Tokens block?
  • Budget check: Response under 1,200 tokens? If not, truncate now.
  • Risk flagged: Any auth/API/cross-module changes flagged with ⚠️?
  • No filler: No pleasantries, hedging, or step-by-step narration present?

If ANY check fails, fix before presenting. Never exceed the file or token limits without explicit user override.

Post-Analysis

After any context optimization session, always offer: "Re-run the mapper to refresh CONTEXT_MANIFEST.md? Use python3 tools/context_mapper.py <path>"

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.