Skip to main content

LeanToken Integration Plan (v0.2)#

Status date: 2026-11-26 Applies to: lean init in v0.2.0 and later

1. Why this plan changed#

v0.1 assumed that writing a directive into CLAUDE.md was enough. A replay of 4 real Claude Code sessions (test-results/aricon-real-performance-2026-11-26.md) showed otherwise:

  • Claude ran lean in 2 of 104 shell commands, and both were during setup.
  • The directive said LeanToken “automatically prunes”, which was false without a hook.
  • Pruning that keys off the command name damaged output. For example, cat test/x.js was routed as a test run.

v0.2 rests on three rules:

  1. Instructions are not integration. A directive only helps if the agent can run lean. Pruning is automatic only where a host hook exists.
  2. Never prune content the agent asked for. Automatic pruning covers only output that is mostly noise: test runs, builds and installs, git status, git diff and directory listings, run as one simple command. File reads, grep, JSON and git log pass through untouched.
  3. Fail open. Any hook error returns the original output. A hook never blocks a tool call and never changes permissions.

2. Two integration layers#

LayerWhat it doesMechanismHosts
A. DirectiveTells the agent to keep diffs minimal, answer concisely, ground claims in evidence, and run noisy commands through lean pruneInstruction file written by lean initEvery host in §3
B. Auto-prune hookPrunes noisy shell output before the agent reads it, with no agent cooperation neededHost hook calls lean hook <host>Claude Code now; others in §5

Where layer B is installed, that host’s directive says pruning is automatic and the agent should not wrap commands itself. Everywhere else it says to run lean prune <command>. Layer A also needs lean on PATH; init warns when it is not.

3. Coverage: AI hosts#

lean init writes only the hosts it detects: repo files with non-LeanToken content, or the tool’s folder in your home directory. AGENTS.md is the fallback when nothing is detected. --only=<keys> picks hosts explicitly; --all writes every row.

KeyFile writtenAI hosts that read itStatus
claudeCLAUDE.md + hook in .claude/settings.local.jsonClaude Code (CLI, VS Code, JetBrains)Live-verified: hook applied in a headless session (−59% on git status)
agentsAGENTS.mdOpenAI Codex, OpenCode, GitHub Copilot agent (VS Code), Cursor, Zed, Antigravity, Gemini in Android StudioFile written; not live-tested per host
geminiGEMINI.mdGemini CLI, Gemini Code Assist, AntigravityFile written; not live-tested
copilot.github/copilot-instructions.mdGitHub Copilot in VS Code, Visual Studio, JetBrains IDEs (incl. Android Studio), Xcode, github.comFile written; not live-tested
cursor.cursorrulesCursor (legacy format, still read)File written; not live-tested
windsurf.windsurf/rules/leantoken.md (trigger: always_on)WindsurfFile written; not live-tested
cline.clinerules/leantoken.mdCline (VS Code)File written; not live-tested
junie.junie/guidelines.mdJetBrains JunieFile written; not live-tested

--global writes user-level files instead: ~/.claude/CLAUDE.md plus the hook in ~/.claude/settings.json. It also writes ~/.gemini/GEMINI.md, ~/.codex/AGENTS.md and ~/.config/opencode/AGENTS.md, but only for tools whose config folder already exists.

4. Coverage: editors#

An editor is covered through the AI host running inside it, not by itself.

EditorAI hosts commonly usedLeanToken files that apply
VS CodeCopilot, Claude Code, Cline, Gemini Code Assist, Codexcopilot-instructions, CLAUDE.md + hook, .clinerules, GEMINI.md, AGENTS.md
CursorCursor agent, Claude Code.cursorrules, AGENTS.md, CLAUDE.md + hook
WindsurfCascade.windsurf/rules
Android Studio / IntelliJGemini in Android Studio, Copilot, Junie, Claude CodeAGENTS.md, copilot-instructions, .junie/guidelines.md, CLAUDE.md + hook
Visual StudioCopilotcopilot-instructions
ZedZed agent, Claude CodeAGENTS.md, CLAUDE.md + hook
AntigravityAntigravity agentGEMINI.md, AGENTS.md
TerminalClaude Code, Codex, OpenCode, Gemini CLIthe host’s file; lean prune

5. Roadmap#

Phase 1 — shipped in v0.2.0 (done)#

  • Multi-host init with in-place upgrades: the directive sits between leantoken:start/end markers, legacy v0.1.0 blocks are migrated, and repeat runs change nothing.
  • Truthful directive: one variant for hosts with the hook, one for hosts without.
  • Claude Code PostToolUse hook using updatedToolOutput. The tool runs unchanged, so permissions are untouched; only the output Claude sees is pruned.
  • Routing fixes: test detection needs an actual test-runner command; listing folds match whole path segments only; failure detection is broader.
  • .gitignore gets .lean/ and .claude/settings.local.json.
  • Host detection: only tools the project or machine uses get files. Re-running init deletes LeanToken-only files for tools no longer detected.
  • No up-front .lean/. Raw logs are written only when output was pruned, one per run, capped at 20.
  • Adaptive back-off: two raw-log reads of the same command stop pruning it in that project.
  • Build/install route; terminal output (CRLF, ANSI, progress redraws) normalized the same on every OS.
  • Lifecycle: lean doctor, lean remove, lean uninstall; hook calls Node by absolute path, and is skipped when run from npx.
  • Versioning: CHANGELOG.md (Keep a Changelog), npm version stamps it, prepublishOnly and CI refuse a version without an entry.
  • CI on Ubuntu, Windows and macOS, Node 18/20/22.

Phase 2 — more hosts get automatic pruning#

For each host, confirm the hook API against current docs before building. Each needs its own lean hook <host> adapter and a live session test.

HostCandidate mechanismUnknown to verify first
OpenCodePlugin with a tool execute-after handlerCan the handler replace tool output?
Gemini CLIHooksEvent names; output-replacement support
Copilot (VS Code agent)Agent hooks (preview)Is the format compatible with Claude’s; can it replace output?
Cursor.cursor/hooks.jsonIs there an after-shell event that can rewrite output?
Codex / Windsurf / Cline / Junie—No known output hook; stay on layer A

Phase 3 — bigger savings (based on the aricon data)#

  1. MCP tool output. The largest single output in aricon was about 10.8k tokens from one MCP tool. Claude’s updatedToolOutput also works for MCP tools, so add a size-capped JSON summarizer with the raw output spooled.
  2. One spool file per run. Done: raw output is saved to .lean/logs/<time>-<command>.log, capped at 20 files.
  3. Fewer duplicate directives. Some hosts read two files (for example, Copilot in VS Code reads both AGENTS.md and copilot-instructions), which costs about 300 tokens twice per session. Make secondary files short pointers where the host supports imports.
  4. Cursor rule format. Move from .cursorrules to .cursor/rules/leantoken.mdc (alwaysApply: true) and migrate existing blocks.

Phase 4 — certification per host#

Each host moves from “file written” to “live-verified” only with evidence of a real session in that host showing the directive loaded and, where a hook exists, a pruned tool result. Every claim needs that evidence, the same way the Claude Code result in §3 was earned.

6. Known limitations#

  • The hook command is an absolute path to bin/lean.js. Re-run lean init after moving or reinstalling LeanToken.
  • The output shape of Claude Code’s PowerShell tool is assumed to match Bash (stdout string). The hook skips any output without one, so this fails safe.
  • Realistic savings depend on workload. Projects that mostly read documents (like aricon) save little. Projects that run tests and builds often save the most.