lean-ctx
AGENTS.md3.9k starsChanged 4 months agoApache-2.0View on GitHub
LeanCTX Engine selects context, applies supported access and content controls, and records observable context operations; compression is one capability within that path. For every substantive task in this repository, load and follow docs/internal/skills/agent-orchestration.md before taking task actions. The routing decision is mandatory; a swarm is not. The lead uses 0 to 15 workers (0 = direct execution) and picks the path with the shortest accepted-result time that keeps the full quality bar — the routing gate in the skill defines…
- Commits and pushes
Trending
Less talk lately.about the whole repository
Who's talking about yvgude/lean-ctx
- @rusttrending.bsky.social“yvgude / lean-ctx: Lean Cortex -- the cognitive context layer for agentic systems. 51+ MCP tools, 10 read …”Bluesky · May 24, 2026 · 6 likes
- @qdrddr.bsky.social“Context reduction for local #development. #MCP tools, #CLI, Hooks to #Harness #codeagents. Build-in …”Bluesky · May 9, 2026 · 5 likes
- dirge-code/dirge“feat: Janet compression plugin + /plugins slash command”GitHub · Jun 10, 2026 · 1 reactions
- Amitro123/knowledgeBase-Agent“Clean up the Google Sheet so the graph gets real topics (Category values, duplicates, empty tabs)”GitHub · Oct 4, 2026
- sudosubin/agents.nix“agent-skills.github.yvgude.lean-ctx: 3.10.2 → 3.10.5”GitHub · Oct 4, 2026
The biggest 5 of 44 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 44
Talked about on GitHub and Bluesky (44 times).
On GitHub · 41
- Jun 10, 2026feat: Janet compression plugin + /plugins slash command — dirge-code/dirge1 reaction · 2 comments
- Oct 4, 2026Clean up the Google Sheet so the graph gets real topics (Category values, duplicates, empty tabs) — Amitro123/knowledgeBase-Agent0 reactions · 3 comments
- Oct 4, 2026agent-skills.github.yvgude.lean-ctx: 3.10.2 → 3.10.5 — sudosubin/agents.nix0 reactions
- Oct 3, 2026agent-skills.github.yvgude.lean-ctx: init at 3.10.2 — sudosubin/agents.nix0 reactions
- Sep 20, 2026Freshness: lean-ctx v3.10.1 -> v3.10.5 — thoroc/context-radar0 reactions
36 more on GitHub
- Sep 17, 2026Feature request: add lean-ctx as a Token Saver (external /v1/compress — verified compatible with the Headroom slot) — decolua/9router0 reactions
- Sep 6, 2026Feature request: MCP Tasks support for background ctx_shell jobs with polling fallback and standardized status notifications — tryweb/ai-engkit0 reactions · 2 comments
- Aug 30, 2026feat: add custom agent tool SDK — Thinkery-AG/leanctx-sdk0 reactions
- Aug 14, 2026claude-proxy-rs: expand text-noise pattern catalog (LeanCTX-inspired) — tstapler/consolette0 reactions · 1 comment
- Aug 11, 2026Add lean-ctx — conda-forge/staged-recipes0 reactions · 2 comments
- Aug 11, 2026claude-proxy-rs: expand text-noise pattern catalog (LeanCTX-inspired) — tstapler/dotfiles0 reactions · 1 comment
- Aug 2, 2026Freshness: lean-ctx v3.9.12 -> v3.10.1 — thoroc/context-radar0 reactions
- Jul 30, 2026Token Optimizer List — haseeb-heaven/token-zero-studio0 reactions · 1 comment
- Jul 26, 2026docs(rules): correct lean-ctx tool-denial claims and cap's per-project skill assertion — arjaygg/dotfiles-omerxx0 reactions
- Jul 19, 2026Freshness: lean-ctx v3.9.11 -> v3.9.12 — thoroc/context-radar0 reactions
- Jul 17, 2026renovate(mise): Update dependency github:yvgude/lean-ctx to v3.9.5 — y-miyazaki/config0 reactions
- Jul 16, 2026Freshness: lean-ctx unrecorded -> v3.9.11 — thoroc/context-radar0 reactions · 1 comment
- Jul 15, 2026fix(github-release): update release github:yvgude/lean-ctx ( v3.9.8 → v3.9.10 ) — david-driscoll/home-operations0 reactions · 1 comment
- Jul 14, 2026Update dependency github:yvgude/lean-ctx to v3.9.9 - autoclosed — david-driscoll/dotfiles0 reactions · 1 comment
- Jul 11, 2026ci: add clippy, fmt, and cargo-deny gates behind a CI Green aggregator — getappz/agentflare0 reactions · 2 comments
- Jul 10, 2026Update dependency github:yvgude/lean-ctx to v3.9.5 — david-driscoll/dotfiles0 reactions · 1 comment
- Jul 8, 2026[Bug]: WSL agent discovery fails when claude/codex are shell aliases; please use type -P or absolute path detection — stablyai/orca0 reactions · 1 comment
- Jul 8, 2026[Build Infra] lean-ctx install step fails with HTTP 403 — GitHub API rate limit blocks CI — tryweb/ai-engkit0 reactions · 1 comment
- Jul 6, 2026fix(github-release): update release github:yvgude/lean-ctx ( v3.9.0 → v3.9.1 ) — david-driscoll/home-operations0 reactions · 1 comment
- Jul 5, 2026lean-ctx Integration — toon-format/toon-rust0 reactions · 1 comment
- Jul 2, 2026docs(readme): update lean-ctx comparison row — headroomlabs-ai/headroom0 reactions · 1 comment
- Jul 2, 2026docs(readme): fix lean-ctx Reversible column — it ships 5 recovery paths — headroomlabs-ai/headroom0 reactions · 2 comments
- Jul 2, 2026README "Compared to" table: lean-ctx row lists Reversible: No — it ships five recovery paths — headroomlabs-ai/headroom0 reactions
- Jul 2, 2026fix: Verifiable Memory Vault: external time-anchor (RFC 3161 + transparency log) + C2PA composition (fixes #1740) — alex-place/lantern-os0 reactions · 4 comments
- Jun 30, 2026Verifiable Memory Vault: external time-anchor (RFC 3161 + transparency log) + C2PA composition — alex-place/lantern-os0 reactions · 3 comments
- Jun 19, 2026[Request]: LeanCTX — ScoopInstaller/Main0 reactions
- Jun 12, 2026Stack with lean-ctx — paql4711/agent-space0 reactions
- Jun 6, 2026content(mcp): add LeanCTX MCP Server — JSONbored/awesome-claude0 reactions · 2 comments
- Jun 5, 2026Lean-Ctx support — cortexkit/aft0 reactions · 3 comments
- May 25, 2026refactor: replace RTK/Reasonix with lean-ctx, fix config schema — alfathhh/hataf-hermes0 reactions
- May 25, 2026refactor: replace RTK + Reasonix with lean-ctx, fix config schema — alfathhh/hataf-hermes0 reactions
- May 21, 2026Investigate LeanCTX — mnemosyne-systems/orangu0 reactions
- May 9, 2026Lean-ctx — github/gh-aw-firewall0 reactions
- Apr 28, 2026Add lean-ctx to Tools section — jim-schwoebel/awesome_ai_agents0 reactions
- Apr 24, 2026[FEATURE] Ability to replace rtk with lean-ctx — headroomlabs-ai/headroom0 reactions · 1 comment
- Apr 17, 2026Plugin proposal: lean-ctx — Claude Code context optimization MCP (649⭐, Rust, zero telemetry) — EnterOS-AI/enter-os-core0 reactions · 1 comment
On Bluesky · 3
- May 24, 2026yvgude / lean-ctx: Lean Cortex -- the cognitive context layer for agentic systems. 51+ MCP tools, 10 read modes, 95+ shell patterns. Up to… — @rusttrending.bsky.social6 likes and reposts
- May 9, 2026Context reduction for local #development. #MCP tools, #CLI, Hooks to #Harness #codeagents. Build-in #knowledgegraph, BM25 & Vector search.… — @qdrddr.bsky.social5 likes and reposts
- Jun 10, 2026公式READMEは、通常の削減を 60-90%、99%級は cached re-reads と案内している。しかも「session memory persists across chats」「knowledge graph」とも書いている。💎… — @sara-echosphere.bsky.socialsays it tested it0 likes and reposts · 1 reply
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository7 other files it gives its agents.
- rust/AGENTS.mdAGENTS.md
- rust/CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/compression-safety.mdcCursor rule
- llms.txtllms.txt
- lean-ctx-reviewSkill
- lean-ctxSkill
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
20 rules. About 0 are common, 6 are distinctive, and 14 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
14
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 21
Runtime: every Codex CLI agent MUST use --model gpt-6-luna and -c 'model_reasoning_effort="max"'.
- Very specific: line 23
LeanCTX coordination: every agent registers on the lean-ctx agent bus, checks directives, and uses lean-ctx context tools.
- Distinctive: line 30
Safe ownership: only one agent may edit a given file or shared worktree at a time.
- Very specific: line 60
Always set readonly: false when the subagent needs ctx_* tools
- Very specific: line 61
Use subagent_type: "generalPurpose" — NOT "explore" (always readonly)
- Very specific: line 77
When working on lean-ctx itself:
- Very specific: line 83
Do not run lean-ctx stop before builds or tests.
- Distinctive: line 103
After completing a significant task (implementation, bugfix, refactoring):
- Distinctive: line 108
After 30+ tool calls without documentation:
- Distinctive: line 115
All provider data flows through the same consolidation pipeline:
- Very specific: line 126
Every ephemeral coding worker MUST register through the local MCP bus as its first MCP operation: call ctx_agent with action="register", …
- Very specific: line 160
Never: use git show commit:file > file without LEAN_CTX_DISABLED=1.
- Distinctive: line 168
No mock data, no placeholders, no stubs
- Distinctive: line 180
Feature / contract change: test the public behaviour and the contract (inputs → outputs, error paths, security boundaries), not internals.
- Very specific: line 182
Extend before adding: put new cases into the nearest existing test module or table-driven test.
- Very specific: line 204
Before every commit, all checks must pass (run from rust/):
- Very specific: line 213
Never judge a run by | tail: a single red test scrolls past unnoticed.
- Very specific: line 214
Before pushing, PREFLIGHT_BASE=github/main bash scripts/preflight.sh runs the change-aware fast gate (the pre-push hook runs it too).
- Very specific: line 223
No timestamps/counters in output bodies.
- Very specific: line 239
No repeating what the user said <!-- /lean-ctx-compression -->
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
LeanCTX — Context Gateway for AI Systems
LeanCTX Engine selects context, applies supported access and content controls, and records observable context operations; compression is one capability within that path.
Mandatory Routing Decision (Direct or Swarm)
For every substantive task in this repository, load and follow
docs/internal/skills/agent-orchestration.md before taking task actions. The
routing decision is mandatory; a swarm is not. The lead uses 0 to 15
workers (0 = direct execution) and picks the path with the shortest
accepted-result time that keeps the full quality bar — the routing gate in the
skill defines how. Fifteen agents is a hard concurrent maximum; every worker
gets a distinct role. Security, redaction, public contracts/schemas,
migrations, releases, and data-loss risk normally get an independent reviewer.
This rule is owned by the orchestration lead. Agents with a concrete delegated subtask are swarm workers: they coordinate through lean-ctx and complete their assigned role, but do not recursively launch another swarm unless the lead explicitly asks them to do so.
- Runtime: every Codex CLI agent MUST use
--model gpt-6-lunaand-c 'model_reasoning_effort="max"'. - LeanCTX coordination: every agent registers on the lean-ctx agent bus, checks directives, and uses lean-ctx context tools; the lead records the integrated decision and progress through lean-ctx.
- Topology: assign independent, non-duplicative roles. When a reviewer is used on a non-parallel change, it validates the implementer's result after it is ready — including whether each new test earns its place (see Test Policy).
- Safe ownership: only one agent may edit a given file or shared worktree at a time. Parallel agents investigate, test, or review in isolation unless explicit file ownership or separate worktrees are assigned.
- Completion: the lead integrates the findings, runs the relevant quality gates, and reports the agents' evidence. A task is not complete merely because an agent returned successfully.
Direct conversational answers, status updates, and clarification questions are not substantive tasks and do not require a swarm. The user may explicitly request a different runtime or a single-agent exception.
Integration Mode: Replace
Native Read/Grep/Glob/Shell are denied by policy. lean-ctx MCP tools are the only path for reading files and running commands:
- Reads/Search →
ctx_read,ctx_search,ctx_compose(cached, 10 modes, images via ContentBlock) - Shell commands →
ctx_shell(95+ compression patterns) - File editing → native Edit/StrReplace (lean-ctx only handles READ operations)
- File finding →
ctx_glob,ctx_tree
Native tools will return a deny error with instructions to use ctx_* equivalents.
Override: set hook_mode = "hybrid" in ~/.config/lean-ctx/config.toml.
Subagent Compatibility (Cursor / Claude Code)
Cursor blocks MCP tools in readonly: true subagents (Task tool).
lean-ctx tools are MCP tools → they WILL FAIL in readonly subagents.
Rules for spawning subagents:
- Always set
readonly: falsewhen the subagent needs ctx_* tools - Use
subagent_type: "generalPurpose"— NOT"explore"(always readonly) - lean-ctx tools declare
readOnlyHint: truein MCP annotations
Fallback (MCP unavailable): deny hook detects MCP-down and allows native tools.
CLI commands (optimized shell, lower overhead)
git status # compressed by configured agent shell/wrapper
cargo test # compressed by configured agent shell/wrapper
lean-ctx -c "git status" # only if explicitly requested / documented unwrapped
lean-ctx ls src/ # directory mapDevelopment Workflow
When working on lean-ctx itself:
- Build without stopping the installed runtime:
cd rust && cargo build --release - Test without stopping the installed runtime:
cargo test --lib+cargo clippy --all-features -- -D warnings+cargo fmt --check - Install:
lean-ctx dev-install(build→atomic stop/install→restart)
Do not run lean-ctx stop before builds or tests. It unloads the user's global
proxy and daemon even though Cargo writes only to the worktree's target directory.
lean-ctx dev-install performs the required short stop immediately before replacing
the installed binary and restores autostart afterward.
Session Continuity
lean-ctx automatically persists session context across restarts:
- Findings: Recent tool results (reads, searches, test outcomes)
- Decisions: Architecture choices made during the session
- Files: Touched files with summaries and modification status
- Progress: Task completion state and next steps
This data is delivered through the first tool call's --- AUTO CONTEXT ---
briefing (default minimal_overhead = true: initialize instructions stay
byte-stable for provider prompt caching, #498). With minimal_overhead = false
it is additionally injected at session start via the ACTIVE SESSION LITM block.
Active Documentation (Agent Responsibility)
After completing a significant task (implementation, bugfix, refactoring):
- Record the decision:
ctx_knowledge(action="remember", category="decision", content="...") - Record progress:
ctx_session(action="task", value="<current task> [N%]") - Record blockers:
ctx_knowledge(action="remember", category="blocker", content="...")
After 30+ tool calls without documentation:
- lean-ctx will prompt with
[CHECKPOINT: please document current progress] - Respond by calling
ctx_session(action="task")with current status
Provider Pipeline (Context Engine)
External data sources (GitHub, GitLab, Jira, Postgres, MCP bridges, custom REST) are first-class citizens. All provider data flows through the same consolidation pipeline:
ContextProvider::execute()→ rawProviderResultconsolidation::consolidate()→ConsolidationArtifacts(BM25 chunks, graph edges, knowledge facts, cache entries)apply_artifacts_to_stores()→ persists to BM25 index, Graph index, ProjectKnowledge, Session cache (background thread)
This means ctx_semantic_search finds issues/PRs/tickets, ctx_knowledge recalls provider facts,
and ctx_read shows cross-source hints (e.g. "Issue #42 references this file").
Agent Bus Registration (mandatory, first action)
Every ephemeral coding worker MUST register through the local MCP bus as its
first MCP operation: call ctx_agent with action="register", its host type
(codex, cursor, or claude), and its assigned role. Retain the returned
local ID, then call ctx_agent with action="read" to check directives.
lean-ctx agent register --id "<type>-$$" ... is intentionally not for
ephemeral workers: it creates a durable, attested identity and using a shell
PID there turns normal short-lived worker history into misleading "active
agents". Reserve that CLI command for a deliberately provisioned, long-lived
identity with an owner. Use ctx_agent action="list" for project-scoped
workers, or lean-ctx agent presence for the local process view.
Branch Hygiene (mandatory)
GitHub remote must stay clean: only main + cla-signatures + max 1 active PR branch per agent.
- After merge → delete source branch:
SKIP_PREFLIGHT=1 git push github --delete <branch> - Branch naming:
<type>/<issue-or-slug>(e.g.fix/1037-heal,feat/p4-usage-sink) - Max 1 open branch per agent on GitHub. No parallel feature branches.
- Before push:
git ls-remote --heads github | wc -l— if >3, clean up first. - No branches without PRs on GitHub. Either open a PR or keep it local.
Compression Safety
lean-ctx shadow-mode compresses file reads. Edit tools (StrReplace, Write) can write compression omission markers back to disk as literal text. The pre-commit hook blocks such commits.
If a commit is blocked or a file looks corrupted:
LEAN_CTX_DISABLED=1 git restore --source=HEAD -- <file> # restore raw content
LEAN_CTX_DISABLED=1 sed -i '' 's/old/new/g' <file> # edit without hooksNever use git show commit:file > file without LEAN_CTX_DISABLED=1.
LEAN_CTX_DISABLED=1 bypasses all lean-ctx compression for a single command.
Quality Bar
- Zero clippy warnings, all tests pass
- Security: PathJail, Shell Allowlist, bounded_lock, no hardcoded secrets
- No mock data, no placeholders, no stubs
Test Policy (single source of truth)
~12 900 tests already exist; every new one costs CI minutes on three OSes
forever. A test earns its place only if it catches a plausible future bug
that nothing else catches (type system, clippy, existing tests, generators
with --check). Skills and rules reference this section instead of
prescribing their own test menus.
- Bugfix: exactly one regression test, at the lowest layer that reproduces the bug. It must fail without the fix.
- Feature / contract change: test the public behaviour and the contract (inputs → outputs, error paths, security boundaries), not internals.
- Extend before adding: put new cases into the nearest existing test
module or table-driven test; do not create a new file or a new
rust/tests/*.rsbinary (each one links the full lib) unless it must mutate process-global state. - Do not write: serde round-trips of derived types, default-value checks, trivial getters/constructors, tests that restate the implementation, hardcoded counts (tool counts, list lengths) that only change-detect.
- Source-text tests (
include_str!("….rs")+ string matching): no new ones unless no behavioural test is feasible (e.g. a security invariant across files). Existing ones are migrated to behaviour tests when their code is touched. - No test is also a valid answer for pure refactors covered by existing tests, docs, config or wording changes. Say so in the PR instead of adding a token test.
- Never weaken, skip or delete a failing test to make a change pass. Deleting a test is fine when it is redundant or only change-detects — state why in the commit.
- Reviewers judge test value, not only coverage: "remove this test" is a legitimate review result.
Quality Gate
Before every commit, all checks must pass (run from rust/):
cargo test --lib > /tmp/lib-tests.log 2>&1; echo "exit=$?" # judge by exit code, grep the log for FAILED
cargo clippy --all-features -- -D warnings
cargo clippy --tests -- -D warnings -A clippy::too_many_lines -A clippy::unwrap_used # --lib never compiles tests/*.rs
cargo fmt --checkNever judge a run by | tail: a single red test scrolls past unnoticed.
Before pushing, PREFLIGHT_BASE=github/main bash scripts/preflight.sh runs the
change-aware fast gate (the pre-push hook runs it too).
Output Determinism (#498)
Tool outputs MUST be deterministic functions of (file content, mode, CRP mode, task). Provider-side prompt caching (Anthropic 90%, OpenAI 50% discount) rewards byte-stable text; any timestamp, counter or random element in tool output bodies defeats it.
- No timestamps/counters in output bodies. Artifact paths are content-addressed
(see
save_tee:{cmd_slug}_{blake3(cmd)[..8]}.log). - Dynamic additions (hints, checkpoints) only as state-triggered suffixes with stable headers.
- Regression guard: determinism tests in
ctx_read/tests.rs,ctx_search.rs,shell/redact.rs.
<!-- lean-ctx -->lean-ctx
lean-ctx is active — the MCP tools replace native equivalents. Full rules: LEAN-CTX.md (open on demand — do not auto-load).
<!-- /lean-ctx --><!-- lean-ctx-compression -->OUTPUT STYLE: concise
- Bullet points over paragraphs
- Skip filler words and hedging ("I think", "probably", "it seems")
- 1-sentence explanations max, then code/action
- No repeating what the user said
<!-- /lean-ctx-compression -->Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

