LeanCTX — Context Gateway for AI Systems skill
Pick the right lean-ctx tool for reading, searching, understanding and running code with fewer tokens and fewer round trips.
by yvgude·Apache-2.0 license·★ 3,868 Stars on the repo·GitHub ↗
npx degit yvgude/lean-ctx/skills/lean-ctx#main ~/.claude/skills/lean-ctxChecked ·commit main
Files of LeanCTX — Context Gateway for AI Systems
Show the full text82 lines
LeanCTX — Context Gateway for AI Systems
Control what your AI can see. LeanCTX Engine provides local context selection, supported access and content controls, and evidence of observed context operations for existing agents: Select → Control → Prove. Recovery depends on source or archive availability and access permissions. LeanCTX SDK is the separate integration surface for applications.
lean-ctx shapes context before it reaches you: cached reads, compressed shell output, focused search, recovery to exact source. Two rules beat every detail:
- Fewer round trips beat smaller outputs. One call that answers the question is cheaper than three small ones. Never add a call just to save a few hundred tokens.
- Never wait by polling. Do not loop
sleep+ status checks (see below).
Intent → tool
| You want to… | Call |
|---|---|
| Understand how something works (unknown location) | ctx_compose(task) — ranked files + source in one call; use it FIRST instead of search→read→read |
| Find the exact definition of a symbol | ctx_search(action="symbol", name=…) |
| Find code by meaning | ctx_search(action="semantic", query=…) |
| Find a text/regex pattern | ctx_search(pattern=…, path=…) |
| Who calls X / what calls X makes | `ctx_callgraph(action="callers" |
| Read a file you will edit | ctx_read(path, mode="anchored") → edit with ctx_patch, or the host's native edit tool |
| Read a file only for context | `ctx_read(path, mode="signatures" |
| Re-check a file after editing | ctx_read(path, mode="diff") |
| Run a command (build, test, git, …) | ctx_shell(command) — output is compressed |
| List files / directory shape | ctx_glob(pattern) / ctx_tree(path, depth) |
| Remember across sessions | `ctx_session(action="finding" |
Do not read or search through ctx_shell (cat, sed -n, grep, rg):
that bypasses the read cache and symbol index. Use ctx_read / ctx_search.
Deferred tools (ToolSearch)
If the host lists lean-ctx tools by name only, load what the task needs in
one call, e.g. select:mcp__lean-ctx__ctx_compose,mcp__lean-ctx__ctx_search,mcp__lean-ctx__ctx_read.
Do not fall back to ctx_shell for everything because it happens to be loaded.
A tool named here that your tool list lacks (the default profile shows a
small core) is still callable: ctx_call(name="ctx_knowledge", arguments={…}).
ctx_call(name="ctx_discover_tools", arguments={"query": "…"}) lists all of them.
Long-running commands
- Prefer the host's own background execution that notifies on completion
(Claude Code:
Bashwithrun_in_background, orMonitor). Start it, then continue other work or end the turn — you will be told when it finishes. ctx_shell(run_in_background=true)jobs do not notify by themselves. Check a job at most once when you actually need its result; neversleepin a loop.
Truncated output
Compressed or archived output ends with a recovery handle. Fetch only the
slice you need: ctx_expand(id, search=… | head=N | json_path=…), or
ctx_read(path, raw=true) for exact bytes. Do not re-run the command.
Without MCP (CLI)
lean-ctx read <file> -m signatures # or map | diff | lines:N-M
lean-ctx grep <pattern> [path]
lean-ctx -c "<command>" # only where the shell is not already wrapped
lean-ctx raw "<command>" # exact, uncompressed output
Setup
which lean-ctx || curl -fsSL https://raw.githubusercontent.com/yvgude/lean-ctx/main/skills/lean-ctx/scripts/install.sh | bash
lean-ctx setup # editor wiring, hooks, rules, this skill
lean-ctx doctor # verify
Docs: https://leanctx.com/docs
| 1 | |
| 2 | name lean-ctx |
| 3 | description Pick the right lean-ctx tool for reading, searching, understanding and running code with fewer tokens and fewer round trips. Use when lean-ctx MCP tools (ctx_*) are available or when a command output, file read or search would be large. |
| 4 | |
| 5 | |
| 6 | # LeanCTX — Context Gateway for AI Systems |
| 7 | |
| 8 | Control what your AI can see. LeanCTX Engine provides local context selection, |
| 9 | supported access and content controls, and evidence of observed context operations |
| 10 | for existing agents: Select → Control → Prove. Recovery depends on source or |
| 11 | archive availability and access permissions. LeanCTX SDK is the separate |
| 12 | integration surface for applications. |
| 13 | |
| 14 | lean-ctx shapes context before it reaches you: cached reads, compressed shell |
| 15 | output, focused search, recovery to exact source. Two rules beat every detail: |
| 16 | |
| 17 | **Fewer round trips beat smaller outputs.** One call that answers the |
| 18 | question is cheaper than three small ones. Never add a call just to save a |
| 19 | few hundred tokens. |
| 20 | **Never wait by polling.** Do not loop `sleep` + status checks (see below). |
| 21 | |
| 22 | ## Intent → tool |
| 23 | |
| 24 | | You want to… | Call | |
| 25 | |---|---| |
| 26 | | Understand how something works (unknown location) | `ctx_compose(task)` — ranked files + source in one call; use it FIRST instead of search→read→read | |
| 27 | | Find the exact definition of a symbol | `ctx_search(action="symbol", name=…)` | |
| 28 | | Find code by meaning | `ctx_search(action="semantic", query=…)` | |
| 29 | | Find a text/regex pattern | `ctx_search(pattern=…, path=…)` | |
| 30 | | Who calls X / what calls X makes | `ctx_callgraph(action="callers"|"callees", symbol=…)` | |
| 31 | | Read a file you will edit | `ctx_read(path, mode="anchored")` → edit with `ctx_patch`, or the host's native edit tool | |
| 32 | | Read a file only for context | `ctx_read(path, mode="signatures"|"map")`; a range: `mode="lines:N-M"` | |
| 33 | | Re-check a file after editing | `ctx_read(path, mode="diff")` | |
| 34 | | Run a command (build, test, git, …) | `ctx_shell(command)` — output is compressed | |
| 35 | | List files / directory shape | `ctx_glob(pattern)` / `ctx_tree(path, depth)` | |
| 36 | | Remember across sessions | `ctx_session(action="finding"|"decision"|"task", value=…)`; durable project facts: `ctx_knowledge(action="remember", …)` | |
| 37 | |
| 38 | Do not read or search through `ctx_shell` (`cat`, `sed -n`, `grep`, `rg`): |
| 39 | that bypasses the read cache and symbol index. Use `ctx_read` / `ctx_search`. |
| 40 | |
| 41 | ## Deferred tools (ToolSearch) |
| 42 | |
| 43 | If the host lists lean-ctx tools by name only, load what the task needs in |
| 44 | **one** call, e.g. `select:mcp__lean-ctx__ctx_compose,mcp__lean-ctx__ctx_search,mcp__lean-ctx__ctx_read`. |
| 45 | Do not fall back to `ctx_shell` for everything because it happens to be loaded. |
| 46 | A tool named here that your tool list lacks (the default profile shows a |
| 47 | small core) is still callable: `ctx_call(name="ctx_knowledge", arguments={…})`. |
| 48 | `ctx_call(name="ctx_discover_tools", arguments={"query": "…"})` lists all of them. |
| 49 | |
| 50 | ## Long-running commands |
| 51 | |
| 52 | Prefer the host's own background execution that notifies on completion |
| 53 | (Claude Code: `Bash` with `run_in_background`, or `Monitor`). Start it, then |
| 54 | continue other work or end the turn — you will be told when it finishes. |
| 55 | `ctx_shell(run_in_background=true)` jobs do not notify by themselves. Check |
| 56 | a job at most once when you actually need its result; never `sleep` in a loop. |
| 57 | |
| 58 | ## Truncated output |
| 59 | |
| 60 | Compressed or archived output ends with a recovery handle. Fetch only the |
| 61 | slice you need: `ctx_expand(id, search=… | head=N | json_path=…)`, or |
| 62 | `ctx_read(path, raw=true)` for exact bytes. Do not re-run the command. |
| 63 | |
| 64 | ## Without MCP (CLI) |
| 65 | |
| 66 | |
| 67 | lean-ctx read <file> -m signatures # or map | diff | lines:N-M |
| 68 | lean-ctx grep <pattern> [path] |
| 69 | lean-ctx -c "<command>" # only where the shell is not already wrapped |
| 70 | lean-ctx raw "<command>" # exact, uncompressed output |
| 71 | |
| 72 | |
| 73 | ## Setup |
| 74 | |
| 75 | |
| 76 | which lean-ctx || curl -fsSL https://raw.githubusercontent.com/yvgude/lean-ctx/main/skills/lean-ctx/scripts/install.sh | bash |
| 77 | lean-ctx setup # editor wiring, hooks, rules, this skill |
| 78 | lean-ctx doctor # verify |
| 79 | |
| 80 | |
| 81 | Docs: https://leanctx.com/docs |
| 82 |
Discussion
Browse more free Claude skills.