Using LeanToken#
LeanToken is a Node.js CLI with no external package dependencies. It requires Node.js 18 or later.
Run from a checkout#
Clone the repository, then run the CLI directly:
For a globally available lean command from the checkout, run npm link in
the repository. To remove the link, run npm unlink -g.
Commands#
-
initconfigures only the AI tools this project or machine uses. A tool counts as used when the repository contains its files with your own content (for exampleCLAUDE.md,.cursor/,.github/copilot-instructions.md), or when the tool is installed for your user (for example~/.claude,~/.gemini, Copilot’s config folder). If nothing is detected, onlyAGENTS.mdis written. The output lists each tool and the reason it was chosen. Files per tool:CLAUDE.md,AGENTS.md,GEMINI.md,.github/copilot-instructions.md,.cursorrules,.windsurf/rules/leantoken.md,.clinerules/leantoken.md,.junie/guidelines.md. For Claude Code,initalso installs the auto-prune hook in.claude/settings.local.json, and adds that file and.lean/to.gitignore. If the hook is already installed user-wide (~/.claude/settings.json), no project copy is installed, and an existing project copy is removed: two copies would prune every output twice.- Re-running upgrades the directive in place (between
leantoken:start/endmarkers) and keeps the content around it. It also deletes files LeanToken created earlier for tools that are no longer used, but only when they hold nothing else. --only=claude,copilot,...picks tools explicitly and--allwrites every tool.--no-hooksskips the hook and--dry-runpreviews.--globalwrites user-level files instead:~/.claude/CLAUDE.md, the hook in~/.claude/settings.json, and~/.gemini/GEMINI.md(Gemini CLI, Antigravity),~/.codex/AGENTS.md,~/.config/opencode/AGENTS.mdand~/.copilot/copilot-instructions.mdwhen those tools are installed.--onlyalso acceptsopencode,codex,antigravityandvscode(GitHub Copilot).
See
docs/11-integration-plan.mdfor which file each tool and editor reads. - Re-running upgrades the directive in place (between
-
doctorchecks Node.js, PATH, detected tools, directive versions, the hook’s file paths,.gitignoreand raw-log disk use. It exits 1 on any error. -
remove [--only=<hosts>] [--purge]undoesinitin this project. Files go back to their content beforeinit, files LeanToken created are deleted, and the hook is removed while your other Claude settings are kept.--purgealso deletes.lean/. -
uninstall [--purge]runsremovein every projectinitwas run in (the list is kept in your OS config folder) and for user-level config, then prints the command that removes the CLI itself. -
hook claudeis called by Claude Code’s hook, not by people. It prunes test runs, builds and installs,git status,git diffand directory listings, and leaves all other output untouched. The command may be preceded by steps that print nothing:cd,pushd,export X=..,$env:X = ..,mkdir, andsource <venv>/bin/activate. For example,cd api && npm testis pruned. Pipes,;/&&chains with other commands, and$(...)leave the output untouched. Claude Code starts the hook only for commands the pruner can shrink, such asnpm,pytest,git status,git diff,python -manddocker build. It does not start it forcat,greporpython script.py, so those cost no extra time. If the agent opens the raw log of the same kind of command twice, that command is no longer pruned in the project (recorded in.lean/learned.json). -
prune <command...>runs a command and condenses its output. When something was removed, the original is saved to.lean/logs/<time>-<command>.logand named in the output’s footer. Only the 20 newest logs are kept. Accumulated statistics are stored in the project’s.lean/stats.json. -
symbols <file|directory>(aliasoutline) extracts lightweight outlines for JavaScript and TypeScript, Python, PHP, Java, C#, Go, Rust, Ruby, Kotlin, Swift, and C/C++. For Markdown it prints the heading tree with each section’s line range and size, for exampleL40-128 ## 4. Architecture (~2.8k tok). Headings inside code fences are ignored, and documents with more than 60 headings show levels 1-3. Read one section withsed -n 40,128p fileor the Read tool’s offset/limit. Other individual files use a generic line-based summary. A directory scan includes supported files in that directory, not nested directories. These lightweight outlines are best-effort and may miss complex or multiline declarations; they are not compiler-grade parsers. -
learn [transcript]reads the project’s 10 newest Claude Code sessions from~/.claude/projects/<project>/(or$CLAUDE_CONFIG_DIR/projects/), or one given.jsonlfile. It writes.lean/MEMORY.mdwith:- the files read 3+ times, each with its section map or signatures;
- the shell commands that failed, with how often and the first error line.
The directive tells agents to use these maps instead of re-reading files. Re-run it to refresh; the file is overwritten.
-
audit [--sessions=N] [--json]measures the newest N (default 20) Claude Code sessions of this project. It reports:- model tokens;
- shell output, how much the hook pruned, and why each other output was not pruned;
- file reads, identical re-reads, and whole-file reads over 8k characters;
- the most-read files.
Token counts use the pruner’s ~3.8 characters-per-token estimate. Model tokens come from the sessions’ own usage records.
-
statsandstatuslinedisplay this project’s measured pruning counters, split by output type.
The CLI’s current command list and option handling are authoritative; check
node bin/lean.js help if documentation and the implementation differ.
Optional shell hooks#
From the repository root, activate the Bash or Zsh hook in the current shell:
For PowerShell, dot-source the hook from the repository root:
For persistent profile integration, source the hook using the location of your checkout; both hooks resolve the CLI relative to their own files.
Hooks redirect selected commands through lean prune; use the CLI directly if
you do not want that shell behavior.
Local data#
LeanToken stores runtime data in .lean/ under the current working directory.
The raw command spool can contain source code, paths, or other command output;
review it before sharing. The repository ignores .lean/logs/*.log and
.lean/stats.json, but other .lean/ files may be project-specific.