yvgude/lean-ctx
GitHub: yvgude/lean-ctx
Stars: 2494 | Forks: 255
██╗ ███████╗ █████╗ ███╗ ██╗ ██████╗████████╗██╗ ██╗ ██║ ██╔════╝██╔══██╗████╗ ██║ ██╔════╝╚══██╔══╝╚██╗██╔╝ ██║ █████╗ ███████║██╔██╗ ██║ ██║ ██║ ╚███╔╝ ██║ ██╔══╝ ██╔══██║██║╚██╗██║ ██║ ██║ ██╔██╗ ███████╗███████╗██║ ██║██║ ╚████║ ╚██████╗ ██║ ██╔╝ ██╗ ╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ **The Cognitive Context Layer for AI coding agents** Your AI coding agent wastes thousands of tokens rereading files, parsing noisy shell output, and losing context between sessions — and you have no control over any of it. **LeanCTX is the operating system for that context.** One local binary that governs every token between your code and the model: it **compresses** what the AI reads, **remembers** what matters across sessions, **routes** each read to the right fidelity, and **verifies** what comes back. Zero config required. Local-first. | Problem | With LeanCTX | |---------|-------------| | Repeated file reads: ~2000 tokens each | Cached re-reads: **~13 tokens** | | Raw `git status`: ~800 tokens | Compressed: **~120 tokens** | | Context resets every chat | Session memory persists across chats | | No visibility into context usage | Real-time dashboard + budget control |Website · Docs · Install · Scenarios · Demo · Benchmarks · Cookbook · Security · Changelog
See it in action:
Read + Shell Map-mode reads + compressed CLI output |
Gain (live) Tokens + USD savings in real time |
Benchmark proof Measure compression by language + mode |
All GIFs are generated from reproducible VHS tapes in demo/.
Saves you tokens? Give it a star — it helps others discover LeanCTX.
## What it does — the four dimensions of context LeanCTX treats context as a managed resource, not an afterthought. One binary covers the four dimensions that decide how well an AI agent actually performs: ### 1. Compression — input efficiency ### 2. Routing — the right fidelity per read Not every file needs the same depth. LeanCTX sends the signal, not the noise. - **10 read modes**: from full content down to AST signatures and entropy-filtered views - **Adaptive `ModePredictor`**: learns the optimal read mode per file type from past sessions - **`IntentEngine`**: classifies query complexity so simple lookups stay cheap ### 3. Memory — context that persists Context doesn't disappear between chats anymore. - **Session memory (CCP)**: persist task/facts/decisions across chats — structured recovery queries survive compaction - **Knowledge graph**: temporal facts with validity windows, episodic + procedural memory - **Property Graph**: multi-edge code graph (imports, calls, exports, type_ref) powers impact analysis and search ranking ### 4. Verification — control what reaches the model Performance is accuracy, not just speed. You stay in control of the window. - **Context Manager**: browser dashboard with real-time token tracking, compression stats, utilization gauge - **Budgets & SLOs**: profiles, roles, per-agent budgets, and throttling policies - **Context Proof** (`ctx_proof`, `ctx_verify`): 4-layer verification engine with CI drift gatesFull feature list (67 MCP tools)
- **Graph-Powered Intelligence**: hybrid search (BM25 + embeddings + graph proximity via RRF), incremental git-diff updates - **LSP Refactoring** (`ctx_refactor`): language-server-powered rename, references, go-to-definition via rust-analyzer, typescript-language-server, pylsp, gopls - **Multi-Agent** (`ctx_agent`, `ctx_handoff`): agent handoff with context transfer bundles, diary system, synchronized shared state - **Archive Full-Text Search** (`ctx_expand search_all`): FTS5-powered cross-archive search over all previously archived tool outputs - **PR Context Packs**: `lean-ctx pack --pr` builds a PR-ready context pack (changed files, related tests, impact, artifacts) - **Context Packages**: `lean-ctx pack create` bundles Knowledge + Graph + Session into portable `.ctxpkg` files with SHA-256 integrity - **Observability**: `lean-ctx gain --live` for real-time savings, `lean-ctx wrapped` for weekly/monthly summaries (`gain --svg`/`--share` for a shareable card or self-hostable page), `lean-ctx watch` for TUI monitoring - **Verified savings**: `lean-ctx savings` is an auditable, per-event ledger (tokenizer transparency, bounce-netting, tamper-evident SHA-256 chain) — local-only, on by default - **HTTP mode**: `lean-ctx serve` for Streamable HTTP MCP + `/v1/tools/call` (used by the Cookbook + SDK)Troubleshooting / Safety
- Disable immediately (current shell): `lean-ctx-off` - Run a single command uncompressed: `lean-ctx -c --raw "git status"` - Only activate in AI agent sessions: set `shell_activation = "agents-only"` in `~/.config/lean-ctx/config.toml` - Per-project config override: create `.lean-ctx.toml` in your project root (auto-merged with global config) - Docker projects sharing `/workspace`: create `.lean-ctx-id` with a unique name to prevent context collisions - Update: `lean-ctx update` - Diagnose (shareable): `lean-ctx doctor --json`| ### 🟢 Your first 60 seconds *"I just installed it — now what?"* lean-ctx onboard # connect every detected AI tool lean-ctx doctor # confirm you're wired up One command auto-detects Cursor/Claude/Codex/… and configures MCP + hooks. → **[Journey 1 — Setup & Onboarding](docs/reference/01-setup-and-onboarding.md)** | ### 📖 Coding every day *"Stop re-reading the same files."* lean-ctx read src/server.rs -m map # API surface, ~13 tok on re-read lean-ctx -c "git status" # compressed shell output |
| ### 🧠 Resume where you left off *"My new chat forgot everything."* lean-ctx overview # task-aware project recap lean-ctx knowledge recall "auth" # facts that survive resets Session memory + a project knowledge graph persist across chats. → **[Journey 3 — Memory & Knowledge](docs/reference/03-memory-and-knowledge.md)** | ### 🗺️ Understand a new codebase *"Where does this function ripple to?"* lean-ctx graph impact src/auth.rs # blast radius lean-ctx smells scan # code-smell hotspots A multi-edge property graph powers impact analysis + ranked search. → **[Journey 4 — Code Intelligence](docs/reference/04-code-intelligence.md)** |
| ### 🔌 Wire in proxy, providers, plugins *"Pull in GitHub issues and our Postgres schema."* lean-ctx provider list lean-ctx serve --root ./api --root ./web # multi-repo External data flows through the same consolidation pipeline. → **[Journey 5 — Advanced & Integrations](docs/reference/05-advanced.md)** | ### 🛠️ Keep it healthy *"Update, fix, or cleanly remove."* lean-ctx doctor --fix lean-ctx update Self-healing diagnostics; surgical uninstall that only removes its own blocks. → **[Journey 6 — Lifecycle & Troubleshooting](docs/reference/06-lifecycle.md)** |
| ### 🎛️ Take control of the window *"Budget my context like a pro."* lean-ctx plan "refactor billing" --budget 8000 lean-ctx compile --mode balanced Phi-scored planning + knapsack compilation + a context ledger. → **[Journey 7 — Context Engineering](docs/reference/07-context-engineering.md)** | ### 🤝 Run a team of agents *"Planner + coder + reviewer on one repo."* ctx_agent action=register role=dev ctx_handoff action=create # baton-pass with full context Shared message bus, diaries, knowledge, and deterministic handoffs. → **[Journey 8 — Multi-Agent Collaboration](docs/reference/08-multi-agent.md)** |
| ### 🏢 Share across a team / CI *"One shared index, headless in pipelines."* lean-ctx team serve --config team.toml lean-ctx bootstrap # zero-prompt CI setup Scoped tokens, optional cloud sync, verifiable context gates. → **[Journey 9 — Team, Cloud & CI](docs/reference/09-team-cloud-ci.md)** | ### 🎚️ Tune & govern *"Make it behave exactly how we want."* lean-ctx compression standard lean-ctx harden # enforce token discipline Compression levels, tool profiles, themes, and rules governance. → **[Journey 10 — Customization & Governance](docs/reference/10-customization-and-governance.md)** |
| ### 📊 Prove the payoff *"Show me the numbers."* lean-ctx gain --deep # savings, cost, per-agent, heatmap lean-ctx wrapped # shareable recap (also: gain --svg / gain --share) lean-ctx savings # verified per-event ledger (auditable; savings verify) All analytics live in the CLI/dashboard — never burning agent tokens. → **[Journey 11 — Analytics & Insights](docs/reference/11-analytics-and-insights.md)** | ### 📚 The full reference *"I want to read everything."* Every command and all 67 MCP tools, organized as user journeys, plus appendices for the [CLI map](docs/reference/appendix-cli-map.md), [MCP tools](docs/reference/appendix-mcp-tools.md), and [paths & config](docs/reference/appendix-paths-and-config.md). → **[Reference index](docs/reference/README.md)** |
标签:通知系统