Get Started
Getting Started
Install LeanCTX and add the Cognitive Context Layer to your AI workflow in under 5 minutes. Step-by-step guide for macOS, Linux, and Windows.
LeanCTX (short for Lean Context) puts a context intelligence layer between your AI tools and the model: it decides what agents read, remembers what they learn, guards what they touch, and proves what they save. One Rust binary provides a Shell Hook with 95+ CLI compression patterns, an MCP Server with 76 tools for cached reads and session intelligence, and a Persistent Project Graph for structural code understanding. The receipt: 60–90% fewer tokens per read, up to 99% on cached re-reads.
Prompt Generator
Select your platform and AI tool below. The generated prompt can be pasted into any AI coding assistant - it will walk through the full installation and configuration automatically.
Get Started in 3 Steps
# 1. Install (pick one) curl -fsSL https://leanctx.com/install.sh | sh # universal brew tap yvgude/lean-ctx && brew install lean-ctx # macOS / Linux npm install -g lean-ctx-bin # Node.js cargo install lean-ctx # Rust pi install npm:pi-lean-ctx # Pi Coding Agent # 2. Connect all your AI tools (zero questions) lean-ctx onboard # recommended # or: lean-ctx setup # guided wizard with full control # 3. Restart your shell source ~/.zshrc # or ~/.bashrc
lean-ctx setup automatically detects and configures 30+ AI tools including: Cursor, Claude Code, Windsurf, VS Code / Copilot, Codex CLI, Gemini CLI, Zed, Antigravity, OpenClaw, Augment, OpenCode, Crush, Pi, Kiro, Amp, Qwen, Trae, Amazon Q, JetBrains, Verdent, Cline, Roo, Hermes, Aider, Continue, Qoder, QoderWork, and more. Run lean-ctx doctor integrations to verify everything works.
Detailed installation instructions per platform
Step 1: Install the Binary
Universal Installer (any platform)
The fastest way to install LeanCTX without any prerequisites:
curl -fsSL https://leanctx.com/install.sh | sh The install script detects your OS and architecture, downloads the correct binary, and places it in ~/.local/bin (configurable via LEAN_CTX_INSTALL_DIR). It works on macOS, Linux, and WSL.
If you prefer to review the script before running it:
curl -fsSL https://leanctx.com/install.sh -o install.sh
chmod +x install.sh
./install.sh --download # pre-built binary (no Rust)
./install.sh # build from source (requires Rust) npm (Node.js)
Install the pre-built binary via npm - no Rust toolchain required:
npm install -g lean-ctx-bin This downloads the correct binary for your platform during postinstall with SHA256 verification. Works on macOS (Intel + Apple Silicon), Linux (x86_64), and Windows (x86_64).
macOS
Option A: Homebrew (recommended)
brew tap yvgude/lean-ctx
brew install lean-ctx Homebrew handles updates and PATH automatically.
Option B: Cargo (build from source)
cargo install lean-ctx If lean-ctx isn't found after install, add Cargo's bin directory to your PATH:
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc Option C: Manual binary download
- Download the binary for your architecture from GitHub Releases:
lean-ctx-aarch64-apple-darwin.tar.gz(Apple Silicon / M1+)lean-ctx-x86_64-apple-darwin.tar.gz(Intel)
- Extract and move to PATH:
tar xzf lean-ctx-aarch64-apple-darwin.tar.gz chmod +x lean-ctx sudo mv lean-ctx /usr/local/bin/
If macOS blocks the binary with a Gatekeeper warning, remove the quarantine attribute:
xattr -d com.apple.quarantine /usr/local/bin/lean-ctx Linux
Option A: Homebrew
brew tap yvgude/lean-ctx && brew install lean-ctx Option B: AUR (Arch Linux)
# Source build from crates.io
yay -S lean-ctx
# Or pre-built binary from GitHub
yay -S lean-ctx-bin Works with any AUR helper: yay, paru, trizen, etc.
Option C: Cargo (build from source)
cargo install lean-ctx Requires Rust toolchain. Install via rustup.rs if needed.
Option D: Manual binary download
- Download
lean-ctx-x86_64-unknown-linux-gnu.tar.gzfrom GitHub Releases - Extract and move to PATH:
tar xzf lean-ctx-x86_64-unknown-linux-gnu.tar.gz chmod +x lean-ctx sudo mv lean-ctx /usr/local/bin/
| Command | Method |
|---|---|
lean-ctx-x86_64-unknown-linux-musl.tar.gz | x86_64 - statically linked (musl) |
lean-ctx-aarch64-unknown-linux-musl.tar.gz | ARM64 / aarch64 (Graviton, Raspberry Pi 4+, etc.) - statically linked |
Windows
Option A: Binary download (recommended)
- Download
lean-ctx-x86_64-pc-windows-msvc.zipfrom GitHub Releases - Extract the
.zipfile - Open the extracted folder - you'll see
lean-ctx.exe - Move
lean-ctx.exeto a folder in your PATH, for example:mkdir %USERPROFILE%\bin move lean-ctx.exe %USERPROFILE%\bin\ - Add the folder to your PATH if it isn't already:
- Open Settings → System → About → Advanced system settings
- Click Environment Variables
- Under User variables, select
Path, click Edit, then New - Add the path to your bin folder (e.g. C:\Users\you\bin)
- Open a new PowerShell or CMD window and verify:
lean-ctx --version
Option B: Cargo (build from source)
- Install Rust if not already installed
- Build and install:
cargo install lean-ctx - The binary is placed in
%USERPROFILE%\.cargo\bin\which is usually already in your PATH.
Option C: Build from source (clone & compile)
git clone https://github.com/yvgude/lean-ctx.git
cd lean-ctx\rust
cargo build --release
copy target\release\lean-ctx.exe %USERPROFILE%\bin\ WSL users: If you're running WSL, follow the Linux instructions instead.
Build from Source (any platform)
git clone https://github.com/yvgude/lean-ctx.git
cd lean-ctx/rust
cargo build --release The binary is at target/release/lean-ctx (or lean-ctx.exe on Windows). Copy it to a directory in your PATH.
Step 2: Setup
After installing the binary, run lean-ctx onboard (recommended) or lean-ctx setup (guided wizard) to configure everything automatically:
lean-ctx onboard # recommended: zero questions, connects everything
lean-ctx setup # alternative: guided 12-step wizard with full control This single command:
- Installs shell aliases (git, npm, cargo, docker, kubectl, curl, ls, find, and 95+ more)
- Auto-detects installed editors (Cursor, Claude Code, Windsurf, VS Code/Copilot, Codex CLI, Gemini CLI, Zed, Antigravity, OpenClaw, Augment, OpenCode, Crush, Pi, Kiro, Amp, Qwen, Trae, Amazon Q, JetBrains, Verdent, Cline, Roo, Hermes, Aider, Continue, Qoder, QoderWork)
- Creates MCP config files for each detected editor
- Injects agent rules into every detected tool's global config, instructing the AI to use LeanCTX's MCP tools (
ctx_read,ctx_shell,ctx_search,ctx_tree) instead of native equivalents - Runs
lean-ctx doctorto verify everything
After setup, restart your shell:
| Shell | Restart command |
|---|---|
| Zsh (macOS default) | source ~/.zshrc |
| Bash | source ~/.bashrc |
| Fish | source ~/.config/fish/config.fish |
| PowerShell | Close and reopen PowerShell |
Then restart your editor completely.
Manual alternative
If you prefer to install only shell aliases without editor auto-detection:
lean-ctx init --global Then configure your editor manually using the instructions in Step 3 below.
Eval-based init (recommended)
As an alternative to lean-ctx init --global, you can use the eval pattern - the same method used by starship, zoxide, and atuin. The hook code is printed to stdout by the currently-installed binary, so it's always up-to-date after upgrades:
# bash: add to ~/.bashrc
eval "$(lean-ctx init bash)"
# zsh: add to ~/.zshrc
eval "$(lean-ctx init zsh)"
# fish: add to ~/.config/fish/config.fish
lean-ctx init fish | source
# powershell: add to $PROFILE
lean-ctx init powershell | Invoke-Expression Advantage: The eval method generates hooks from the installed binary at shell startup, so hooks are never stale after a lean-ctx update. No need to run lean-ctx setup again after upgrading.
Step 3: Verify
- Check the binary is installed:
lean-ctx --version # → lean-ctx 3.x.x lean-ctx doctor # checks PATH, config, aliases, MCP - Test the shell hook:
git status # output is now compressed lean-ctx gain # shows token savings so far - Open your AI coding tool and start coding - LeanCTX tools should be available automatically.
Setup complete! What's next?
- Quick Reference — daily cheat sheet for all commands and read modes
- All Tools — explore the full MCP tool catalog
- Configuration — customize behavior, filters, and security
Manual editor configuration
only if lean-ctx setup didn't work
Connect LeanCTX to your AI coding tool by adding it as an MCP server.
Cursor
- Create or edit the MCP config file:
# macOS / Linux: mkdir -p ~/.cursor nano ~/.cursor/mcp.json # Windows (PowerShell): mkdir -Force "$env:USERPROFILE\.cursor" notepad "$env:USERPROFILE\.cursor\mcp.json" - Paste this JSON:
{ "mcpServers": { "lean-ctx": { "command": "lean-ctx" } } } - Restart Cursor completely (Cmd+Q / Alt+F4, then reopen).
- Verify: open the MCP panel in settings - LeanCTX should show as "connected".
Optional: install agent rules to make Cursor prefer LeanCTX tools:
lean-ctx init --agent cursor Claude Code
Claude Code has built-in MCP support. No config file needed:
# Add lean-ctx as MCP server:
claude mcp add lean-ctx lean-ctx
# Install the CLAUDE.md instructions (makes Claude use lean-ctx tools):
lean-ctx init --agent claude The init command registers the MCP server in <code>~/.claude.json</code>, maintains a compact instructions block in <code>~/.claude/CLAUDE.md</code>, and installs the Agent Skill to <code>~/.claude/skills/lean-ctx/</code>.
Claude Code: 2048-Character Limit
Claude Code truncates MCP server instructions to 2048 characters. This means LeanCTX's full instruction set (session management, compression protocols, tool preferences) gets cut off.
LeanCTX handles this automatically: lean-ctx init --agent claude maintains a managed block in ~/.claude/CLAUDE.md and installs an Agent Skill (~/.claude/skills/lean-ctx/) whose full documentation loads on demand. Claude Code loads these without any character cap.
# Automatic (recommended) - run during init:
lean-ctx init --agent claude
# This automatically:
# 1. Registers MCP server in ~/.claude.json
# 2. Maintains a compact instructions block in ~/.claude/CLAUDE.md
# 3. Installs Agent Skill to ~/.claude/skills/lean-ctx/ (full docs, loads on demand) If you installed LeanCTX manually (without init), run lean-ctx init --agent claude to retroactively install the CLAUDE.md block + skill.
GitHub Copilot (VS Code)
Option A: Copilot CLI (.github/mcp.json)
- Create
.github/mcp.jsonin your project root:{ "mcpServers": { "lean-ctx": { "command": "lean-ctx" } } } - Restart VS Code / Copilot CLI.
Option B: VS Code Copilot (.vscode/mcp.json)
- Create
.vscode/mcp.jsonin your project root:{ "servers": { "lean-ctx": { "type": "stdio", "command": "lean-ctx" } } } - Restart VS Code.
Tip: lean-ctx init --agent copilot creates both files automatically.
Note: GitHub Copilot MCP support requires VS Code 1.99+ and the latest Copilot extension. Copilot CLI uses .github/mcp.json with the mcpServers key; VS Code Copilot uses .vscode/mcp.json with the servers key.
Per-project: These configs are per-project. Commit them to share with your team.
Windsurf
- Open the MCP config file:
# macOS: mkdir -p ~/.codeium/windsurf nano ~/.codeium/windsurf/mcp_config.json # Linux: mkdir -p ~/.codeium/windsurf nano ~/.codeium/windsurf/mcp_config.json # Windows: mkdir -Force "$env:USERPROFILE\.codeium\windsurf" notepad "$env:USERPROFILE\.codeium\windsurf\mcp_config.json" - Paste this JSON:
{ "mcpServers": { "lean-ctx": { "command": "/FULL/PATH/TO/lean-ctx" } } }Important: Windsurf requires the full absolute path to the binary. Example for Homebrew on macOS:
{ "mcpServers": { "lean-ctx": { "command": "/opt/homebrew/bin/lean-ctx" } } } - Restart Windsurf completely.
- Check MCP connection in Windsurf settings.
Zed
- Open Zed settings:
# macOS / Linux: ~/.config/zed/settings.json # Windows: %APPDATA%\Zed\settings.json - Add the LeanCTX context server configuration:
{ "context_servers": { "lean-ctx": { "source": "custom", "command": "lean-ctx", "args": [], "env": {} } } }Note: Zed uses
context_servers(notmcpServers) and requiressource: "custom". - Save and restart Zed.
- Verify: LeanCTX tools should appear in the assistant panel.
Tip: Zed auto-restarts MCP servers after saving settings.json. No additional rules injection needed — Zed receives tool preferences via the MCP server instructions.
OpenAI Codex CLI
- Create or edit the Codex config file:
# macOS / Linux: mkdir -p ~/.codex nano ~/.codex/config.toml # Windows: mkdir -Force "$env:USERPROFILE\.codex" notepad "$env:USERPROFILE\.codex\config.toml" - Add the MCP server entry:
[mcp_servers.lean-ctx] command = "lean-ctx" args = [] - Restart Codex CLI.
Alternative: use the Codex CLI built-in command:
codex mcp add lean-ctx Install agent instructions for Codex:
lean-ctx init --agent codex Gemini CLI
- Create or edit the Gemini MCP config:
# macOS / Linux: mkdir -p ~/.gemini nano ~/.gemini/settings.json # Windows (PowerShell): mkdir -Force "$env:USERPROFILE\.gemini" notepad "$env:USERPROFILE\.gemini\settings.json" - Add the MCP server configuration:
{ "mcpServers": { "lean-ctx": { "command": "lean-ctx" } } }Important: If Gemini can't find the binary, use the full path. Example for Homebrew on macOS:
{ "mcpServers": { "lean-ctx": { "command": "/opt/homebrew/bin/lean-ctx" } } } - Restart Gemini CLI.
- Verify with a prompt that triggers tool use.
Known issue: Gemini CLI may not always invoke MCP tools consistently. If tools aren't triggered, try adding lean-ctx init --agent gemini to install a GEMINI.md with usage instructions.
Antigravity IDE
Antigravity IDE uses ~/.gemini/antigravity/mcp_config.json. Auto-detected by lean-ctx setup.
- Create the config directory and file:
# macOS / Linux: mkdir -p ~/.gemini/antigravity nano ~/.gemini/antigravity/mcp_config.json # Windows (PowerShell): mkdir -Force "$env:USERPROFILE\.gemini\antigravity" notepad "$env:USERPROFILE\.gemini\antigravity\mcp_config.json" - Add the MCP server entry:
{ "mcpServers": { "lean-ctx": { "command": "lean-ctx" } } }If
lean-ctxis not in your PATH, use the full path (runwhich lean-ctxto find it). - Run
lean-ctx init --agent antigravityto auto-configure. - Restart Antigravity IDE.
Antigravity CLI 2.0
Antigravity CLI uses a separate config at ~/.gemini/antigravity-cli/mcp_config.json.
- Create the config directory and file:
# macOS / Linux: mkdir -p ~/.gemini/antigravity-cli nano ~/.gemini/antigravity-cli/mcp_config.json # Windows (PowerShell): mkdir -Force "$env:USERPROFILE\.gemini\antigravity-cli" notepad "$env:USERPROFILE\.gemini\antigravity-cli\mcp_config.json" - Add the MCP server entry:
{ "mcpServers": { "lean-ctx": { "command": "lean-ctx" } } } - Run
lean-ctx init --agent antigravity-clito auto-configure. - Restart Antigravity CLI.
OpenCode
- Create or edit the OpenCode config file:
# macOS / Linux: mkdir -p ~/.config/opencode nano ~/.config/opencode/opencode.json - Add the MCP server configuration:
{ "$schema": "https://opencode.ai/config.json", "mcp": { "lean-ctx": { "type": "local", "command": ["lean-ctx"], "enabled": true } } } - Restart OpenCode.
OpenClaw
OpenClaw supports MCP servers natively. Run one command to configure everything:
- Run
lean-ctx init --agent openclaw - Restart OpenClaw to activate.
- Verify with
openclaw mcp list.
This writes the MCP entry to ~/.openclaw/openclaw.json, installs rules, and copies the LeanCTX skill to ~/.openclaw/skills/lean-ctx/.
Pi
Pi has a dedicated LeanCTX plugin (pi-lean-ctx) that integrates automatically.
- Make sure LeanCTX is installed:
cargo install lean-ctx - Install the Pi plugin:
pi install npm:pi-lean-ctxOr use LeanCTX's built-in command:
lean-ctx init --agent pi - Restart Pi.
- Verify: LeanCTX tools should appear in Pi's tool list.
Note: Pi's smart reads automatically use LeanCTX when the plugin is installed. No additional configuration needed.
AWS Kiro
AWS Kiro requires both an MCP config and a steering file to use LeanCTX tools instead of native equivalents.
- Run
lean-ctx setup- Kiro is auto-detected and both MCP config + steering file are created. - Or use the dedicated command (creates both files):
lean-ctx init --agent kiro - This creates two files:
~/.kiro/settings/mcp.json- MCP server connection.kiro/steering/lean-ctx.md- Steering file that tells Kiro to prefermcp_lean_ctx_ctx_readoverreadFile, etc.
- Restart Kiro to activate.
Important: The steering file (.kiro/steering/lean-ctx.md) is per-project. Without it, Kiro will default to its native tools and ignore the MCP server for reads and searches.
Verdent
Verdent supports MCP servers via configuration or CLI.
- Open Verdent settings or navigate to the MCP section.
- Run the init command:
lean-ctx init --agent verdent - Or manually create the MCP config:
{ "mcpServers": { "lean-ctx": { "command": "lean-ctx" } } } - Restart Verdent to activate.
Note: Verdent's MCP support may require a recent version. Update Verdent if tools don't appear.
Other MCP-compatible tools
Any tool that supports the Model Context Protocol can use LeanCTX. The standard MCP config format is:
{
"mcpServers": {
"lean-ctx": {
"command": "lean-ctx"
}
}
} Key points:
- The
commandmust point to the LeanCTX binary (use full path if not in PATH). - No
argsorenvare required - LeanCTX auto-configures. - The binary communicates via stdio (standard MCP transport).
- After adding the config, restart your tool and verify LeanCTX tools appear.
Docker Installation
To use LeanCTX inside a Docker container (e.g. with Claude Code, Codex, or other AI agents), use the statically-linked musl binary and set BASH_ENV so the shell hook loads in non-interactive shells.
ARG LEAN_CTX_VERSION=3.8.7
# XDG layout (3.8.x): config (incl. env.sh) lives under $XDG_CONFIG_HOME/lean-ctx,
# data (sessions, graphs, knowledge, stats.json) under $XDG_DATA_HOME/lean-ctx.
# Set these before init so the hook + data land in predictable paths.
ENV XDG_CONFIG_HOME="/root/.config" \
XDG_DATA_HOME="/root/.local/share"
# Download the musl binary (statically linked, no glibc dependency)
RUN curl -fsSL \
"https://github.com/yvgude/lean-ctx/releases/download/v${LEAN_CTX_VERSION}/lean-ctx-x86_64-unknown-linux-musl.tar.gz" \
| tar -xz -C /usr/local/bin lean-ctx && \
chmod +x /usr/local/bin/lean-ctx
# Install shell hook (non-interactive) + configure your AI tool
RUN lean-ctx init --global && \
lean-ctx init --agent claude
# Load shell hook in non-interactive shells (env.sh is a config file → XDG config dir)
ENV BASH_ENV="/root/.config/lean-ctx/env.sh"
# Claude Code: sources this file before each command
ENV CLAUDE_ENV_FILE="/root/.config/lean-ctx/env.sh" For ARM64 hosts (AWS Graviton, Apple Silicon via Docker), use the aarch64 binary instead:
# For ARM64 (Apple Silicon / Graviton), use the aarch64 binary:
RUN curl -fsSL \
"https://github.com/yvgude/lean-ctx/releases/download/v${LEAN_CTX_VERSION}/lean-ctx-aarch64-unknown-linux-musl.tar.gz" \
| tar -xz -C /usr/local/bin lean-ctx Why this works
| Step | Purpose |
|---|---|
musl binary | Statically linked - works on any Linux distro without installing gcc-libs or glibc |
lean-ctx init --global | Installs shell hook into ~/.bashrc (non-interactive, unlike lean-ctx setup) |
lean-ctx init --agent claude | Writes MCP server config to ~/.claude.json. Replace claude with your agent: cursor, codex, gemini, etc. |
BASH_ENV | Generic non-interactive shells (bash -c) source this file. Most ~/.bashrc files exit early in non-interactive mode - env.sh has no such guard. |
CLAUDE_ENV_FILE | Claude Code sources this file before every command it runs. This is the officially recommended way to configure the shell environment for Claude Code. |
Project Identity in Docker
When multiple projects share the same /workspace mount path inside Docker containers,
LeanCTX may confuse their data (graph index, semantic cache, etc.) because it uses the path to
identify projects. To solve this, create a .lean-ctx-id file in your project root:
# In your project root (before building the Docker image)
echo "my-unique-project-name" > .lean-ctx-id
This file takes highest priority for project identification, above git remote, package.json,
and directory name. Include it in your Dockerfile or mount it as a volume.
Existing data is automatically migrated from old hash directories when the identity changes.
Common issues
| Error | Cause | Fix |
|---|---|---|
command not found: _lc | BASH_ENV not set - shell hook not loaded | Add ENV BASH_ENV="/root/.lean-ctx/env.sh" (adjust path for non-root users) |
lean-ctx setup hangs | Interactive prompt with no stdin in Docker | Use lean-ctx init --global instead |
| Binary not found / exec format error | Wrong architecture or using gnu binary without glibc | Use the musl tarball for minimal containers |
Monitor Savings
# Terminal dashboard (colors, bars, sparklines)
lean-ctx gain
# Web dashboard with charts
lean-ctx dashboard
# Find uncompressed commands in shell history
lean-ctx discover
# Run a real benchmark on your project
lean-ctx benchmark run Agent Hooks & Editor Integration
Configure LeanCTX for your specific AI agent or editor. The init command sets up MCP configuration, shell hooks, and verifies everything works. Use doctor to diagnose and auto-fix issues.
# Configure a specific AI tool (mode auto-detected; override with --mode)
lean-ctx init --agent cursor
lean-ctx init --agent claude
lean-ctx init --agent codex
lean-ctx init --agent gemini
lean-ctx init --agent hermes
lean-ctx init --agent pi # or: pi install npm:pi-lean-ctx
lean-ctx init --agent qoder
lean-ctx init --agent qoderwork
# Force MCP tools if you prefer ctx_* calls
lean-ctx init --agent cursor --mode mcp
# Run diagnostics and auto-fix issues
lean-ctx doctor --fix
# Check current status (MCP, shell, editors)
lean-ctx status --json Updating
The fastest way to update LeanCTX:
lean-ctx update This auto-detects your installation method, downloads the latest version, and replaces the binary.
You can also update manually using the original installation method:
| Method | Command |
|---|---|
| Homebrew | brew update && brew upgrade lean-ctx |
| Cargo | cargo install lean-ctx |
| npm | npm update -g lean-ctx-bin |
| AUR | yay -Syu lean-ctx |
| Pi | pi install npm:pi-lean-ctx |
| install.sh | Re-run curl -fsSL https://leanctx.com/install.sh | sh |
| Binary | Download latest from GitHub Releases |
After updating, re-run lean-ctx setup to ensure shell hooks and editor configs are up to date:
lean-ctx setup # re-configures shell + editors
source ~/.zshrc # restart shell Uninstalling
To fully remove LeanCTX from your system:
lean-ctx uninstall This removes:
- Shell hook entries from
~/.zshrc,~/.bashrc,~/.config/fish/config.fish, and PowerShell profiles - Agent rules files (
CLAUDE.md,.cursorrules, etc.) - Cache and config files in
~/.lean-ctx/
Then remove the binary itself:
| Installed via | Remove command |
|---|---|
| Cargo | cargo uninstall lean-ctx |
| Homebrew | brew uninstall lean-ctx |
| AUR | yay -R lean-ctx |
| Pi | pi uninstall npm:pi-lean-ctx |
| Manual binary | rm $(which lean-ctx) |
Restart your terminal and AI coding tool to complete the uninstallation.
Agent Rules
Agent rules tell your AI coding tool to prefer LeanCTX MCP tools (ctx_read, ctx_shell, ctx_search, ctx_tree) over native file reads, shell commands, and search. Run lean-ctx init --agent <name> to install them automatically.
How it works
lean-ctx init --agent <name>writes a rules/instructions file to the agent's expected location.- The rules file teaches the AI to use
ctx_read,ctx_shell,ctx_search, andctx_treeinstead of native equivalents. - This is optional - LeanCTX works without agent rules, but performance improves when the AI actively uses LeanCTX tools.
- The rules are idempotent - running
initagain updates them without duplicating content.
What gets injected
The rules tell the AI agent to use LeanCTX MCP tools instead of native equivalents:
| Instead of | Use | Why |
|---|---|---|
Read / cat | ctx_read | Cached, 10 read modes, re-reads cost ~13 tokens |
Shell / bash | ctx_shell | Pattern compression for git, npm, cargo, docker output |
Grep / search | ctx_search | Compact, token-efficient results |
ls / find | ctx_tree | Compact directory maps with file counts |
Note: Write, StrReplace, Delete, and Glob have no LeanCTX replacement - the rules tell the AI to keep using native tools for those.
Where are rules installed?
| AI Tool | Rules File |
|---|---|
| Claude Code | ~/.claude/CLAUDE.md (managed block) + skill |
| Codex CLI | ~/.codex/instructions.md |
| Cursor | ~/.cursor/rules/lean-ctx.mdc |
| Windsurf | ~/.codeium/windsurf/rules/lean-ctx.md |
| Gemini CLI | ~/.gemini/settings.json (MCP instructions) |
| VS Code / Copilot | .github/copilot-instructions.md |
| OpenCode | ~/.config/opencode/AGENTS.md |
| Pi | pi-lean-ctx package (built-in via pi.dev) |
| Kiro | ~/.kiro/steering/lean-ctx.md |
| Qoder | ~/.qoder/settings.json (PreToolUse hooks) |
Manual rules (fallback)
If your AI tool doesn't support agent rules, you can paste these instructions into the system prompt or a rules file:
# lean-ctx - Context Layer
Hybrid mode (default):
- Use MCP tools for reads/search (cached, token-efficient):
- ctx_read instead of Read/cat for file reads
- ctx_search instead of Grep/search for code search
- Use lean-ctx -c "<cmd>" for compressed shell output
MCP-only mode:
- Use ctx_* tools for everything:
- ctx_read for file reads
- ctx_shell for shell commands
- ctx_search for code search
- ctx_tree for directory listing
Keep using native tools for: Write, StrReplace, Delete, Glob (no lean-ctx replacement).
Do NOT fall back to native tools for reading/shell/search/tree when a lean-ctx path is available. Cursor users: Save this as .cursor/rules/lean-ctx.mdc in your project root for project-level rules, or ~/.cursor/rules/lean-ctx.mdc for global rules.
Setup Commands Reference (onboard, setup, install, bootstrap, init, doctor, status)
lean-ctx onboard, the recommended first command
Connects every AI tool found on your machine using sensible defaults, with zero questions, then prints one clear "you're connected" message.
lean-ctx onboard Under the hood, onboard runs the same engine as the full setup wizard, but in non-interactive mode, it makes every decision for you. Files changed: MCP config for each detected editor, the shell RC hook, and ~/.lean-ctx/ is created.
lean-ctx setup — the guided wizard (full control)
An interactive, 12-step wizard. Use it when you want to decide about the proxy, telemetry, auto-updates, compression level, and tool profile.
lean-ctx setup The 12 steps
| Step | Name | What it does |
|---|---|---|
| 1 | Shell Hook | Installs aliases + the universal hook in ~/.zshenv, RC files |
| 2 | Daemon | Starts/restarts the IPC daemon for fast CLI routing |
| 3 | AI Tool Detection | Detects installed editors, writes each one's MCP config |
| 4 | Agent Rules | Injects lean-ctx rules (only if opted in) |
| 5 | API Proxy | Optional — installs proxy autostart + env vars |
| 6 | Skill Files | Installs SKILL.md (only if opted in) |
| 7 | Environment Check | Ensures data dir, migrates, runs compact doctor |
| 8 | Help Improve | Asks for anonymous stats sharing |
| 9 | Auto-Updates | Installs the 6-hourly update scheduler |
| 10 | Tool Profile | Choose minimal/standard/power MCP tool set |
| 11 | Advanced Tuning | Optional — compression level + tool-result archive |
| 12 | Code Intelligence | Builds the property graph in the background |
First-run menu
| Choice | Rules | Skills | Meaning |
|---|---|---|---|
| [1] Minimal (default) | No | No | Just MCP tools, no config-file edits |
| [2] Standard | Yes | No | MCP tools + agent rules for optimal mode selection |
| [3] Full | Yes | Yes | Tools + rules + skills + shell hooks |
lean-ctx install
lean-ctx install runs the guided setup. install --repair (or --fix) runs the non-interactive, merge-based refresh.
lean-ctx install # = lean-ctx setup
lean-ctx install --repair # non-interactive repair (no deletes) lean-ctx bootstrap — zero-config CI/scripts
Non-interactive setup + fix with sensible defaults. Identical to install --repair but named for automation.
lean-ctx bootstrap [--json] lean-ctx init
lean-ctx init --global— installs only the shell aliases/hook into your shell RClean-ctx init --agent <name>— configures MCP + rules + skill for one specific agent (e.g.cursor,claude,codex,gemini)
lean-ctx doctor
Runs ~27 diagnostic checks across binary, data dir, MCP configs, shell hook, daemon, proxy, caches, and memory.
lean-ctx doctor # full diagnostics
lean-ctx doctor --fix # auto-repair what's fixable
lean-ctx doctor --json # machine-readable
lean-ctx doctor integrations # per-IDE wiring health lean-ctx status
A lighter-weight "am I connected?" report. Use status for a fast yes/no; use doctor for deep diagnostics.
lean-ctx status
lean-ctx status --json Troubleshooting
LeanCTX: command not found
The binary isn't in your PATH. Check where it was installed:
# Cargo installs here:
ls ~/.cargo/bin/lean-ctx
# Homebrew installs here (macOS):
ls /opt/homebrew/bin/lean-ctx
# Manual installs - wherever you placed it:
ls /usr/local/bin/lean-ctx Add the correct directory to your PATH in your shell profile.
AI isn't using LeanCTX tools
If the AI keeps using native Read/Shell instead of ctx_read/ctx_shell:
- Run
lean-ctx init --agent <name>to install agent rules - Restart the AI tool completely (not just reload)
- Check that the MCP server is connected (look for LeanCTX in the tool's MCP panel)
- Try prompting explicitly: "use ctx_read to read this file"
No LeanCTX tools appearing
- Verify the binary path is correct in your MCP config
- Run
lean-ctx doctorto check for issues - Check the AI tool's MCP logs for connection errors
- Try using the full absolute path to
lean-ctxin the config
Shell hook causes hangs
If commands hang after installing the shell hook, set the LEAN_CTX_ACTIVE environment variable to bypass compression for specific commands:
LEAN_CTX_ACTIVE=1 cargo test This disables LeanCTX compression for that command. Useful for CI/CD scripts and long-running processes.
macOS Gatekeeper blocks lean-ctx
xattr -d com.apple.quarantine $(which lean-ctx) Windows: PowerShell vs cmd.exe
LeanCTX prioritizes PowerShell on Windows. If you experience issues with cmd.exe, set the LEAN_CTX_SHELL environment variable to force PowerShell: $env:LEAN_CTX_SHELL = "powershell"
Next Steps
- Project Intelligence Graph - build and query your project's dependency graph
- CEP Protocol - cognitive efficiency scoring for leaner AI responses
- CCP Protocol - cross-session context continuity
- TDD Protocol - token-dense dialect for maximum compression
- All 76 Tools Reference
- CLI Reference