Skip to content

Repository files navigation

ctxcraft

License: MITClaude Code

Evaluate and optimize your AI agent's context. Save tokens, cut costs.

ctxcraft analyzes your .claude/ directory structure and provides actionable recommendations to reduce token consumption — without losing any functionality.

The Problem

AI coding agents (Claude Code, Cursor, Windsurf) load context files on every conversation. As your .claude/ directory grows, silent token waste accumulates:

  • Verbose rule files that could be cut in half
  • Duplicated content across rules, skills, and CLAUDE.md
  • Unused skills/agents that are never invoked
  • Always-on files that should be loaded on-demand

ctxcraft finds and fixes all of this.

vs /doctor? Claude Code's built-in /doctor proposes trims for a checked-in CLAUDE.md. ctxcraft audits the whole .claude/ surface — rules/, skills/, agents/, legacy commands/, auto memory — with a quality score, a plan-tier cost axis, and CI integration. Thresholds follow the official docs.

Quick Start

Option 1: Plugin Marketplace (Recommended)

# Add marketplace (one-time)
claude plugin marketplace add warrenth/ctxcraft
# Install plugin (run per project)
claude plugin install ctxcraft@tools

Then in Claude Code:

/ctxcraft:evaluate # Analyze token efficiency
/ctxcraft:optimize # Auto-fix issues
/ctxcraft:token-guide # Best practices reference

Note:claude plugin install must be run in each project. Despite scope: user, Claude Code plugins are not truly global — you need to reinstall when switching to a new project.

Team auto-install via settings.json
{
"extraKnownMarketplaces": {
"ctxcraft": {
"source": { "source": "github", "repo": "warrenth/ctxcraft" }
}
},
"enabledPlugins": { "ctxcraft@tools": true }
}

Option 2: Global Install

curl -sL https://raw.githubusercontent.com/warrenth/ctxcraft/main/install.sh | bash

Then in Claude Code: /evaluate, /optimize, /token-guide

Project-local install
curl -sL https://raw.githubusercontent.com/warrenth/ctxcraft/main/install.sh | bash -s -- --local

/evaluate uses read-only tools (Read, Grep, Glob) — no permission prompts. /optimize additionally uses Write/Edit and always asks before applying any change.

Note: plugin installs don't load the optional always-on rules file (rules/token-efficiency.md) — plugins can't ship rules/. The install.sh path offers to copy it to ~/.claude/rules/ instead.

How It Works

$ /ctxcraft:evaluate
━━━ Phase 1: Token Efficiency Audit ━━━
PASS [ 1] CLAUDE.md size
FAIL [ 2] Always-on tokens → Compress rules, save ~8,848 tokens
FAIL [ 3] Rules file size → Move examples to skills/
PASS [ 4] Rules file count
WARN [ 5] Duplicate sections → Keep in one place only
PASS [ 6] Progressive disclosure
...
PASS [25] Cross-reference validity
━━━ Phase 2: Report ━━━
┌────────────────────┬────────────┬───────┐
│ Category │ Tokens │ Files │
├────────────────────┼────────────┼───────┤
│ Always-on (every) │ 16,848 │ 14 │
│ On-demand (lazy) │ 53,040 │ 46 │
├────────────────────┼────────────┼───────┤
│ Total │ 69,888 │ 60 │
└────────────────────┴────────────┴───────┘
💡 Potential savings: ~9,168 tokens/conversation
━━━ Summary ━━━
Quality: 86/100 (A-)
Cost: Comfortable (Max 5x plan)
PASS 20 WARN 3 FAIL 2

Before / After

┌──────────────────────────────────────────────────┐
│ ctxcraft — Optimization Complete │
│ │
│ Before After Change │
│ Quality 78/100 → 92/100 (+14 pts) │
│ Grade B+ → A │
│ Always-on 16,848 → 9,200 (-7,648 tok) │
│ │
│ PASS 20 → 24 WARN 3 → 1 FAIL 2 → 0 │
└──────────────────────────────────────────────────┘

What /optimize Does

  1. Compress — Shrink verbose rules and CLAUDE.md while preserving meaning
  2. Deduplicate — Merge overlapping rules into a single source of truth
  3. Clean up — Identify and remove unused skills/agents
  4. Restructure — Move always-on content to on-demand skills
  5. Split references — Extract details from large SKILL.md (>250 lines) into references/
  6. Self-clean — Remove temporary scratch files after optimization (never the plugin itself)

All changes require user confirmation before applying.

25 Checks

Token Efficiency (1–8)

#CheckThresholdWhat it measures
1CLAUDE.md size≤ 200 lines (official)Core file loaded every conversation; > 500 fails
2Always-on tokens≤ 8,000CLAUDE.md (+ @imports) + non-scoped rules/
3Rules file size≤ 150 linesIndividual rule file bloat
4Rules file count≤ 15Too many rules → consolidate
5Duplicate sections0Overlap between CLAUDE.md ↔ rules/
6Progressive disclosureOn-demand 50%+Always-on vs on-demand ratio
7Skills file size≤ 500 lines (official; 150 strict)Individual skill file bloat
8Token allocation ratioAlways-on ≤ 30%Always-on share of total context
Structural Validity (9–25)
#CheckWhat it measures
9Agent frontmatterYAML --- block validity
10Agent required fieldsname/description presence (tools optional per spec)
11Skill frontmatterYAML --- block validity
12Skill references linksreferences/*.md link validity
13Rules skill referencesDeep-dive /skill-name links
14Rules conditional loadingpaths: frontmatter usage (official lazy-load)
15Skills orphan directoriesSKILL.md must exist in each dir
16Skill description lengthdescription + when_to_use ≤ 1,536 chars
17Agent skills referencesskills/ directory exists
18Agent least privilegeRead-only agents don't get Write/Edit
19Rules enforcement keywordsMUST/SHOULD/NEVER (RFC 2119)
20CLAUDE.md ↔ Skills syncReferenced skills actually exist
21Auto memoryMEMORY.md within its 200-line/25KB load limit
22Agent model specifiedModel field for cost control
23Context savingscratch dir + save rules
24Agent model costopus ≤ 2 agents (weighted cost)
25Cross-reference validityNo broken /skill-name references

Scoring

ctxcraft uses a 2-axis system — quality (universal) and cost (plan-dependent).

Quality measures structural health (N/A checks are excluded — no free points):

PASS = 10, WARN = 5, FAIL = 0 per check
Quality = earned points / (scored checks × 10) × 100
GradeScoreMeaning
A90–100Excellent
A-80–89Great
B+70–79Good
B60–69Fair
C50–59Needs work
D40–49Poor
F0–39Optimize now

Cost shows token budget usage per plan:

PlanComfortableWarningCritical
Pro< 15K15K–25K> 25K
Max 5x< 20K20K–35K> 35K
Max 20x< 25K25K–40K> 40K
Team< 20K20K–35K> 35K
Opus 1M< 50K50K–80K> 80K

On-demand skills/agents are NOT penalized — they load only when needed.

Project Structure

ctxcraft/
├── .claude-plugin/
│ ├── plugin.json # Plugin manifest
│ └── marketplace.json # Marketplace catalog
├── skills/
│ ├── evaluate/SKILL.md # /ctxcraft:evaluate
│ ├── optimize/SKILL.md # /ctxcraft:optimize
│ └── token-guide/SKILL.md # Token efficiency reference
├── agents/
│ └── token-auditor.md # Dedicated analysis agent
├── rules/
│ └── token-efficiency.md # Token efficiency rules
├── action.yml # GitHub Actions integration
├── evaluate.sh # One-liner evaluation script
└── install.sh # Global/local installer

Supported Environments

  • Claude Code — full support (rules/, skills/, agents/, plugin, CI action)
  • Agent Skills-compatible tools (Cursor, GitHub Copilot, Gemini CLI, OpenAI Codex, …) — ctxcraft's skills follow the Agent Skills open standard, so the evaluate/optimize skills load in any compatible tool. Evaluation of those tools' own config layouts is planned
  • Windsurf / Cline config layouts (planned)

Contributing

Contributions are welcome! Feel free to open issues and pull requests.

License

MIT

About

Evaluate and optimize your AI agent context. Save tokens, save money.

Topics

Resources

Stars

13 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages