Operations

Configuration

Every LeanCTX configuration surface: config.toml reference, environment variables, per-tool profiles, security hardening and editor setup — with defaults that work out of the box.

LeanCTX works out of the box with zero configuration. All settings below are optional - defaults are tuned for typical AI-assisted development workflows.


Config File

LeanCTX supports an optional TOML configuration file at ~/.lean-ctx/config.toml.

Create the default config

lean-ctx config init

View current configuration

lean-ctx config

Set individual values

lean-ctx config set ultra_compact true
lean-ctx config set checkpoint_interval 15
lean-ctx config set tee_mode always
lean-ctx config set passthrough_urls localhost:3000,api.internal

Validate Your Config

# Check for typos, unknown keys, and wrong field names
lean-ctx config validate

# View the full config schema (all keys, types, defaults)
lean-ctx config schema

Configuration Priority

When the same setting is defined in multiple places, LeanCTX uses a clear priority order. Higher-priority sources override lower ones:

PrioritySourceExample
1 (highest)Environment variableLEAN_CTX_COMPRESSION=max
2Project-local config.lean-ctx.toml
3 (lowest)Global config~/.lean-ctx/config.toml

Within a single config file, TOML is a key-value format; there is no line-order priority. If you define the same key twice, the TOML parser will use the last occurrence, but this is considered a syntax error. Use lean-ctx config validate to catch such issues.


Common Confusion: "max" Parameters

LeanCTX has several parameters with "max" in their name that control completely different things. This table clarifies which parameter controls what:

ParameterWhat it controlsDefaultSection
graph_index_max_files Graph file scan limit, how many files the JSON graph index scans for dependency analysis. This is what lean-ctx gain shows as "Graph: N files".0 (unlimited) root
memory.knowledge.max_facts Knowledge facts, how many learned facts (from conversations) are stored per project. Has nothing to do with the graph.200 [memory.knowledge]
memory.embeddings.max_facts Embedding index, how many facts are indexed in the vector store for semantic search. Separate from knowledge facts.2000 [memory.embeddings]
archive.max_disk_mb Archive storage, maximum disk space for zero-loss compression archives. Unrelated to memory or graph.500 [archive]
archive.max_age_hours Archive retention, how long archived tool results are kept before cleanup.48 [archive]
memory.lifecycle.stale_days Knowledge staleness, facts not accessed for this many days become eligible for pruning during consolidation. Does not delete instantly, facts are pruned only when auto_consolidate runs.30 [memory.lifecycle]

Config Options

KeyTypeDefaultDescription
ultra_compact bool false Enable ultra-compact output mode
compression_level string "lite" Unified compression level controlling the 4-layer terse engine. "off" = no compression, "lite" = abbreviations only, "standard" = balanced compression, "max" = maximum token savings. Replaces the legacy output_density and terse_agent settings. See Compression Level.
minimal_overhead bool true Reduce per-call token overhead to the absolute minimum. Disables auto-checkpoints, meta-strings (savings notes, stale notes, shell hints), and session/knowledge blocks in MCP instructions. Recommended for Codex, CI pipelines, and cost-sensitive environments. Also available via LEAN_CTX_MINIMAL=1. See Minimal Overhead.
output_density string "normal" Legacy, superseded by compression_level. Values: "normal" / "terse" / "ultra". Also available via LEAN_CTX_OUTPUT_DENSITY. See Output Density.
tee_mode string "failures" When to save full output to ~/.lean-ctx/tee/. Values: always, failures, never. Backward-compatible: tee_on_error: true maps to failures.
passthrough_urls list [] URL fragments for curl passthrough. Curl commands targeting these URLs skip JSON compression and return full responses.
checkpoint_interval u32 15 Auto-checkpoint every N tool calls (0 = disabled). Overridden by LEAN_CTX_CHECKPOINT_INTERVAL env var.
excluded_commands list [] Commands to skip compression for
custom_aliases list [] Define custom shell command aliases for ctx_shell. Each entry maps a short name to a full command. See Custom Aliases for examples.
path_jail bool? null PathJail is active by default (null) — every tool path is confined to the project root. Set path_jail = false to disable it entirely (e.g. inside containers or trusted monorepos). The former LEAN_CTX_NO_JAIL=1 env override was removed in v3.7.3.
redirect_exclude list [] Glob patterns for files that should bypass the hook redirect and go straight to the native Read tool. Useful for config files or files you don't want compressed. Example: [".wolf/**", ".claude/**", "*.json", "CLAUDE.md"]. Also configurable via LEAN_CTX_HOOK_EXCLUDE.
content_defined_chunking bool false Enable Rabin-Karp content-defined chunking for ctx_read. Creates stable chunk boundaries based on content hashes, improving LLM prompt cache hit rates across edits. Opt-in: enable when working with large files that change frequently.
disabled_tools list [] Exclude tools from the MCP tool list to reduce token overhead. Example: ["ctx_benchmark", "ctx_metrics", "ctx_gain"]. Also available via LEAN_CTX_DISABLED_TOOLS env var (comma-separated).
terse_agent string "off" Legacy, superseded by compression_level. Still accepted for backward compatibility ("off"/"lite"/"full"/"ultra" and true/false). If both are set, compression_level takes precedence.
rules_scope string "both" Controls where LeanCTX injects its cursor rules. "global" = only ~/.cursor/rules/, "project" = only .cursor/rules/ in the project, "both" = both locations. See Rules Scope.
slow_command_threshold_ms u64 5000 Commands running longer than this threshold (in milliseconds) are flagged in ctx_shell output with a timing warning. Set to 0 to disable slow command detection entirely.
buddy_enabled bool true Enable buddy mode for collaborative multi-agent workflows. See Buddy Mode.
extra_ignore_patterns list [] Additional glob patterns to exclude from ctx_tree, ctx_search, and file discovery. These are merged with the built-in ignore list (node_modules, .git, etc.). Example: ["*.generated.ts", "vendor/**", "dist/**"]
profile string "" Active profile name. Overridden by LEAN_CTX_PROFILE env var. Resolution order: env var → config.toml → "coder". Built-in profiles: "coder" (balanced compression), "passthrough" (full content, zero compression). Set via lean-ctx config set profile <name>.
theme string "default" Visual theme for CLI and dashboard output.
memory_profile string "performance" Controls memory subsystem behavior. "low" reduces memory usage at the cost of recall. "balanced" optimizes for typical workflows. "performance" (default) retains more context for maximum recall. Also available via LEAN_CTX_MEMORY_PROFILE.
bm25_max_cache_mb u64 128 Maximum size in MB for the BM25 search index cache. Higher values improve search performance for large codebases.
allow_paths list [] Additional paths outside the project root that are allowed through the PathJail sandbox. Use for monorepo shared directories or external dependency sources. Entries support ~, $VAR and ${VAR} expansion (since 3.8.1); lean-ctx doctor flags entries that can never match.
shadow_mode bool false Transparently intercept native Read/Grep/Shell calls via hooks and route through lean-ctx. Logs to ~/.lean-ctx/shadow.log
shell_hook_disabled bool false Disable the shell hook entirely. When true, LeanCTX will not intercept shell commands for compression.
update_check_disabled bool false Disable automatic version update checks. When true, LeanCTX will not check for new releases on startup.
graph_index_max_files u64 0 (unlimited) Maximum files scanned by the JSON graph index fallback. Increase for large monorepos. When the cap is reached, lean-ctx gain shows "(capped)" and a warning is emitted.
sandbox_level u8 0 Sandbox level for code execution. 0 = subprocess isolation only, 1 = OS-level sandboxing (Seatbelt on macOS, Landlock on Linux). Also available via LEAN_CTX_SANDBOX_LEVEL.
shell_allowlist list [] When non-empty, only listed commands are permitted by ctx_shell. All other commands are rejected. Also available via LEAN_CTX_SHELL_ALLOWLIST (comma-separated).
no_degrade bool false When true, disables all automatic read mode degradation. Explicit mode=full is never downgraded by pressure or context gate. Also available via LCTX_NO_DEGRADE=1. v3.6.15
allow_auto_reroot bool false Allow automatic project root re-rooting. When false, absolute paths outside the PathJail are rejected. Also available via LEAN_CTX_ALLOW_REROOT.
agent_token_budget usize 0 Default per-agent token budget. 0 = unlimited. Override per-agent via ctx_session.
reference_results bool false When true, large tool outputs (>4000 chars) are stored as references and a URI is returned instead of the full content. Also available via LEAN_CTX_REFERENCE_RESULTS.
[archive] table - Configure zero-loss compression. Full tool results are saved to disk; the agent retrieves them on demand via ctx_expand. See Tool Result Archive.
[cloud] table - Cloud integration settings. See Cloud.
[proxy] table - Upstream API proxy overrides. See Proxy.
[memory] table - Memory subsystem configuration with sub-tables for knowledge, episodic, procedural, lifecycle, gotcha, and embeddings. See Memory.
[secret_detection] table - Regex-based secret detection in tool outputs. See Secret Detection.
[boundary_policy] table - Cross-project access control and audit policy. See Boundary Policy.
bypass_hints string "on" Strength of the nudge when an agent uses native Read/Grep instead of the ctx_* tools: on (default, periodic reminder), off (silent), or aggressive (reminds on the first native call).
[loop_detection] table - Configure loop detection thresholds. See Loop Detection section below.
memory_cleanup string "aggressive" Controls how aggressively LeanCTX frees memory when idle. "aggressive" (default) clears caches after 5 minutes of idle time, ideal for single-IDE use. "shared" retains caches for 30 minutes, ideal when multiple IDEs or models share the same LeanCTX instance. Also available via LEAN_CTX_MEMORY_CLEANUP env var.
shell_activation string "always" Controls when LeanCTX shell aliases auto-activate. "always" (default): active in every interactive shell. "agents-only": only active when AI agent env vars are detected (LEAN_CTX_AGENT, CLAUDECODE, CODEX_CLI_SESSION, GEMINI_SESSION). "off": never auto-activate, user must call lean-ctx-on manually. Also available via LEAN_CTX_SHELL_ACTIVATION env var. See Shell Activation.
max_ram_percent u8 5 Maximum percentage of system RAM that LeanCTX may use before the RAM Guardian triggers adaptive cache eviction. Range: 1–50. Also available via LEAN_CTX_MAX_RAM_PERCENT env var.
savings_footer string "auto" Controls visibility of token savings footers (e.g. [42 tok saved (30%)]). "auto" (default): shown in CLI, suppressed in MCP/agent context. "always": always shown. "never": never shown. Also available via LEAN_CTX_SAVINGS_FOOTER env var.
rules_injection v3.7.4 string "shared" How lean-ctx delivers its tool-mapping rules to shared-instruction-file agents (Claude Code, Codex, OpenCode, Gemini CLI). "shared" writes a marker-delimited block into CLAUDE.md / AGENTS.md / GEMINI.md. "dedicated" never edits those files — it uses each agent's own config-driven, fully-removable auto-load path plus a lean-ctx-owned rules file. Switching back, and lean-ctx uninstall, reverse every registration cleanly.
permission_inheritance v3.7.4 string "off" When "on", lean-ctx mirrors the host IDE's permission rules onto its own tools so ctx_shell/ctx_execute honor your bash rules, ctx_read honors read, etc. (v1: OpenCode opencode.json, global + project merged). deny blocks, ask holds the call back with an actionable message, allow proceeds. Read-only and runtime-only — lean-ctx never writes your permission block; default "off" adds zero hot-path cost.
cache_policy string "aggressive" Cache policy for ctx_read: aggressive (warm re-reads collapse to ~13-token stubs), safe (return a structural map on a cache hit), or off (always read from disk). Env: LEAN_CTX_CACHE_POLICY.
structure_first bool false Opt-in: bias auto toward structure-first reads (map) for medium code files on a cold read. Off by default — intended for phase-isolated harnesses with no warm-session cache payback. Env: LEAN_CTX_STRUCTURE_FIRST.
symbol_map_auto bool false Opt-in: α-code identifier substitution inside aggressive reads on large (>50-file) projects. Off by default because abbreviated symbols hinder editing/refactoring. Env: LEAN_CTX_SYMBOL_MAP.
response_verbosity string "normal" How verbose tool responses are: normal, compact, or minimal. Env: LEAN_CTX_RESPONSE_VERBOSITY.
persona string "coding" Active context persona — reshapes the tool surface, default read modes, compressors and the secret-sensitivity floor. Env: LEAN_CTX_PERSONA.
tool_profile string "" Tool-visibility profile: minimal, standard, or power (empty = the built-in default surface of ~13 lean-core tools, full catalog on demand). Env: LEAN_CTX_TOOL_PROFILE.
tools_enabled list [] Explicit list of enabled tool names; overrides tool_profile when non-empty.
default_tool_categories list [] Tool categories active by default (core, arch, debug, memory, metrics, session). Empty = the built-in default set.
enable_wakeup_ctx bool true Append the wakeup briefing (facts + session summary) to ctx_overview. Set false to trim context when calling ctx_overview frequently.
auto_capture bool true Automatically capture knowledge facts from tool findings during a session.
journal_enabled bool true Write a human-readable activity journal under the lean-ctx state directory.
preserve_compact_formats list ["toon"] Already-compact output formats preserved verbatim instead of being recompressed. Set to [] to disable.
shell_strict_mode bool false Block command substitution ($(), backticks, <()) in shell arguments. Default false warns only.
shell_allowlist_extra list [] Commands merged on top of shell_allowlist without replacing the defaults. Managed via lean-ctx allow <cmd>.
project_root string? null Explicit project root directory; prevents accidental home-directory scans. Env: LEAN_CTX_PROJECT_ROOT.
proxy_enabled bool? null Force the API proxy layer on/off. null = auto-detect, true = force on, false = force off.
proxy_port u16? null Custom proxy listen port (default: 4444). Env: LEAN_CTX_PROXY_PORT.
proxy_timeout_ms u64? null Proxy reachability timeout in milliseconds (default: 200). Env: LEAN_CTX_PROXY_TIMEOUT_MS.
team_url string? null Team-server base URL for the opt-in savings roll-up (push/pull).
team_token string? null Bearer token for the team server (push needs a member token; pull/auto-push needs the configured team token).
team_auto_push bool false Opt-in: the daemon periodically pushes your signed savings batch to team_url (requires team_url + team_token).

Simplified Configuration v3.6.18

Instead of tuning dozens of individual limits, you can set a few high-level parameters that automatically derive downstream values. When simplified settings are used and individual limits are still at their defaults, the derived values take effect.

SettingEffectScale
max_disk_mb Distributes to archive.max_disk_mb (25%), bm25_max_cache_mb (10%), and proportionally scales memory limits (facts, patterns, episodes, procedures)Factor = max_disk_mb / 500, clamped to 0.5x–10x
max_staleness_days Flows into archive.max_age_hours (days × 24)Direct conversion
compression_level Sets terse agent, output density, and CRP mode in one knobOff / Lite / Standard / Max
max_ram_percent RAM Guardian eviction threshold1–50% of system RAM
memory_profile Preset for BM25 cache and runtime memory usagelow (64MB) / balanced (128MB) / performance (512MB)

Use lean-ctx config show to see all effective values with their source (env / config / default / derived).

# Example: 2GB disk budget → facts=800, patterns=200, episodes=2000, procedures=400
max_disk_mb = 2000
compression_level = "Standard"
max_staleness_days = 30

Environment Variables

VariableValuesDescription
LEAN_CTX_PERSONA coding (default), research, support, data-analysis, lead-gen Active context persona. Reshapes the tool surface, default read modes, compressors and the sensitivity floor for the session. Custom personas are loaded by id from the personas directory.
LEAN_CTX_PERSONAS_DIR path (default: <config-dir>/lean-ctx/personas) Directory of custom persona TOML files. Each <id>.toml defines the tool profile, read modes, compressors and sensitivity floor for that persona.
LEAN_CTX_PLUGINS_DIR path (default: <config-dir>/lean-ctx/plugins) Directory of plugins. Each plugin ships a plugin.toml manifest plus lifecycle hooks, discovered at startup.
LEAN_CTX_WASM_DIR path Directory of WebAssembly extensions (custom compressors / chunkers) loaded into the extension registry — extend LeanCTX without forking it.
LEAN_CTX_CRP_MODE tdd (default), compact, off Controls Token Dense Dialect compression level
LEAN_CTX_OUTPUT_DENSITY normal (default), terse, ultra Override the compression level without editing config. Maps to CompressionLevel (Off/Lite/Standard/Max). Applies to all MCP tool outputs (and most tool footers).
LEAN_CTX_MINIMAL 1 / unset Enable minimal overhead mode. Disables auto-checkpoints, meta-strings, and session blocks in instructions. Equivalent to minimal_overhead = true in config.
LEAN_CTX_NO_CHECKPOINT 1 / unset Disable auto-checkpoint injection without affecting other meta-strings. More targeted than LEAN_CTX_MINIMAL which disables everything.
LEAN_CTX_CHECKPOINT_INTERVAL number (default: 15) Auto-checkpoint every N tool calls (0 = disabled)
LEAN_CTX_CACHE_TTL number (default: 300) Seconds of inactivity before session cache auto-clears (0 = disabled)
LEAN_CTX_MEMORY_CLEANUP aggressive (default) / shared Controls idle memory cleanup aggressiveness. aggressive: clear caches after 5 min idle (single-IDE). shared: retain caches 30 min (multi-IDE/multi-model). Overrides memory_cleanup in config.toml. If LEAN_CTX_CACHE_TTL is also set, it takes precedence for the cache TTL value.
LEAN_CTX_SHELL_ACTIVATION always (default) / agents-only / off Override shell_activation config setting. Controls when LeanCTX shell aliases auto-activate. always: active in every interactive shell. agents-only: only when AI agent env vars detected. off: manual activation via lean-ctx-on. See Shell Activation.
LEAN_CTX_MAX_RAM_PERCENT number (default: 5) Maximum percentage of system RAM LeanCTX may use before the RAM Guardian triggers adaptive cache eviction. Range: 1–50. Overrides max_ram_percent in config.toml.
LEAN_CTX_SAVINGS_FOOTER auto (default) / always / never Controls visibility of token savings footers. auto: shown in CLI, suppressed in MCP/agent context. always: always shown. never: never shown. Overrides savings_footer in config.toml.
LEAN_CTX_SANDBOX_LEVEL 0 (default) / 1 Override sandbox_level config. 0 = subprocess only, 1 = OS-level sandboxing (Seatbelt on macOS, Landlock on Linux).
LEAN_CTX_SHELL_ALLOWLIST comma-separated commands Override shell_allowlist config. When set, only listed commands are permitted by ctx_shell. Merges with config defaults. Example: git,cargo,npm,ls
LEAN_CTX_SHELL_ALLOWLIST_OVERRIDE comma-separated commands Completely replaces the shell allowlist (no merging with config). Use for deterministic testing environments. Empty value ("") creates an empty allowlist (blocklist-only mode).
LCTX_NO_DEGRADE 1 Disable all automatic read mode degradation. Explicit mode=full is never downgraded by pressure.
LEAN_CTX_ALLOW_REROOT true / false Override allow_auto_reroot config. When false (default), absolute paths outside the PathJail are rejected.
LEAN_CTX_REFERENCE_RESULTS true / false Override reference_results config. When true, large tool outputs (>4000 chars) are stored as references with a URI returned instead.
LEAN_CTX_ACTIVE set / unset Recursion guard. When set, LeanCTX passes commands through without compression. Set automatically by the shell hook.
LEAN_CTX_PROFILE profile name Override active profile. Takes precedence over profile in config.toml. Built-in profiles: coder (default, balanced compression), passthrough (full content, zero compression). v3.6.19
LEAN_CTX_FULL_TOOLS 1 / true / 0 / false Register all MCP tools (including advanced/intelligence tools). Set to 0 or false to disable. Fixed in v3.6.19: =0 was previously treated as enabled
LEAN_CTX_DISABLED set / unset Master kill-switch. Bypasses ALL compression in both shell hook and MCP server. Everything passes through unmodified.
LEAN_CTX_RAW set / unset Skip compression for the current command. Same effect as --raw flag or raw=true MCP parameter.
LEAN_CTX_AUTONOMY true / false Enable/disable autonomous intelligence features (auto-preload, auto-dedup, related hints). Default: true.
LEAN_CTX_DISABLED_TOOLS comma-separated tool names Exclude specific tools from the MCP tool list. Overrides disabled_tools in config.toml when set. Example: ctx_benchmark,ctx_metrics,ctx_gain
LEAN_CTX_BYPASS_HINTS gentle (default) / firm / off Controls bypass detection hints. When agents use native Read/Grep instead of LeanCTX tools, a reminder is appended to the next response. gentle: reminder with cooldown (every 5 calls). firm: immediate reminder on every detection. off: disabled. Overrides bypass_hints in config.toml.
LEAN_CTX_HARDEN 1 / unset Activate strict enforcement mode. When set, hook redirects strongly encourage LeanCTX tools by returning ALLOW JSON with embedded guidance (since v3.6.22, hooks never return DENY to avoid agent retry loops). Set automatically by lean-ctx harden.
LEAN_CTX_SHELL path to shell binary Override which shell LeanCTX uses for ctx_shell / lean-ctx -c. Useful on Windows when PowerShell detection fails. Example: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
LEAN_CTX_COMPRESSION off / lite / standard / max Override compression_level config setting. Controls the 4-layer terse engine for unified input/output compression. See Compression Level.
LEAN_CTX_TERSE_AGENT true / false Legacy. Override terse_agent config. Mapped to compression_level internally. See Compression Level.
LEAN_CTX_ARCHIVE true / false Override archive.enabled config. Enable zero-loss compression via the Tool Result Archive.
LEAN_CTX_ARCHIVE_THRESHOLD number (default: 4096) Minimum character count before a tool result is archived. Override for archive.threshold_chars.
LEAN_CTX_HEADLESS set / unset Start MCP server in headless mode - skip all auto-setup (rules injection, hook installation, CLAUDE.md modification, agent registry). See Headless MCP Mode.
LEAN_CTX_MODELS_DIR path Override where embedding models are stored/downloaded (default: ~/.lean-ctx/models). Useful for containers and CI.
LEAN_CTX_DATA_DIR path (fresh install: $XDG_DATA_HOME/lean-ctx; legacy: ~/.lean-ctx) Override the base directory for all LeanCTX persistent data (stats, knowledge, agents, cache, sessions). All modules resolve paths through this single env var. Useful for custom data locations or containerized environments.
LEAN_CTX_CONFIG_DIR v3.8.5 path (XDG: $XDG_CONFIG_HOME/lean-ctx) Per-category override for config artifacts (config.toml, shell hooks, env.sh). Part of the XDG Base Directory split (#408) so the config dir can be mounted read-only. Falls back to $XDG_CONFIG_HOME/lean-ctx, then ~/.config/lean-ctx.
LEAN_CTX_STATE_DIR v3.8.5 path (XDG: $XDG_STATE_HOME/lean-ctx) Per-category override for state (events, journals, logs, ledgers, agent_runtime_env.json). Falls back to $XDG_STATE_HOME/lean-ctx, then ~/.local/state/lean-ctx.
LEAN_CTX_CACHE_DIR v3.8.5 path (XDG: $XDG_CACHE_HOME/lean-ctx) Per-category override for cache (semantic cache, downloaded models, learned patterns). Falls back to $XDG_CACHE_HOME/lean-ctx, then ~/.cache/lean-ctx. A single explicit LEAN_CTX_DATA_DIR forces one directory and is never auto-split.
LCTX_MAX_READ_BYTES number (default: 4194304) Maximum file size in bytes that ctx_read / ctx_edit will process. Files exceeding this limit are rejected with a clear error. Prevents accidental ingestion of very large files. Default: 5 MB.
LCTX_MAX_SHELL_BYTES number (default: 2097152) Maximum shell output capture size in bytes for ctx_shell. Output exceeding this limit is truncated with a [truncated] marker. Default: 1 MB.
LEAN_CTX_RULES_INJECTION v3.7.4 shared (default) / dedicated Overrides the rules_injection config. dedicated never edits your shared instruction files (CLAUDE.md / AGENTS.md / GEMINI.md).
LEAN_CTX_PERMISSION_INHERITANCE v3.7.4 on / off (default) Overrides the permission_inheritance config. When on, lean-ctx tools honor the host IDE's permission rules (read-only mirroring).
LEAN_CTX_GRID_CO2_G_PER_KWH v3.7.4 number (default: 475) Grid carbon intensity (g CO₂e/kWh) used by ctx_gain to estimate carbon avoided. Defaults to the global-average grid; set your region's value for an honest figure on cleaner grids.
LEAN_CTX_STRUCTURE_FIRST 1 / 0 Overrides structure_first. Bias auto toward structure-first (map) reads for medium code files on a cold read.
LEAN_CTX_SYMBOL_MAP 1 / 0 Overrides symbol_map_auto. Forces α-code symbol substitution inside aggressive reads on/off.
LEAN_CTX_CACHE_POLICY aggressive / safe / off Overrides the cache_policy config for ctx_read caching.
LEAN_CTX_TOOL_PROFILE minimal / standard / power Overrides the tool_profile config (tool-visibility tier).
LEAN_CTX_PERSONA persona name (default: coding) Overrides the persona config — reshapes the tool surface, default read modes and compressors.
LEAN_CTX_RESPONSE_VERBOSITY normal / compact / minimal Overrides the response_verbosity config.
LEAN_CTX_MEMORY_PROFILE low / balanced / performance Overrides the memory_profile config (RAM vs. feature trade-off).
LEAN_CTX_EPHEMERAL true / false Overrides archive.ephemeral. Replace large results with a summary + reference (retrieve via ctx_expand).
LEAN_CTX_EPHEMERAL_MIN_TOKENS number (default: 2000) Overrides archive.ephemeral_min_tokens — output tokens before the ephemeral firewall fires.
LEAN_CTX_EMBEDDING_MODEL model id (default: minilm) Overrides embedding.model for ctx_semantic_search (e.g. jina-code-v2, nomic, hf:org/repo).
LEAN_CTX_EMBEDDINGS_AUTO_DOWNLOAD true / false Overrides embedding.auto_download. Set false on air-gapped machines to block background model downloads.
LEAN_CTX_PROJECT_ROOT path Overrides the project_root config; pins the project root and prevents accidental home-directory scans.
LEAN_CTX_EXTRA_ROOTS colon-separated paths Additional directories treated as in-jail roots (e.g. linked workspaces or shared toolchains).
LEAN_CTX_ALLOW_IDE_DIRS 1 / unset Opt-in: allow tool access to IDE/agent config dirs (.cursor, .claude, .codebuddy, …) that PathJail blocks by default. Same effect as allow_ide_config_dirs = true.
LEAN_CTX_HTTP_TOKEN #377 token string Pins the Bearer token required by the dashboard / HTTP server. Overridden by dashboard --auth-token.
LEAN_CTX_PROXY_TOKEN token string Bearer token required by the API proxy. If unset, a secure token is generated and persisted in the state directory.
LEAN_CTX_PROXY_PORT number (default: 4444) Overrides the proxy_port config (proxy listen port).
LEAN_CTX_PROXY_TIMEOUT_MS number (default: 200) Overrides the proxy_timeout_ms config (proxy reachability timeout).
LEAN_CTX_PROXY_HISTORY_MODE cache-aware / rolling / off Overrides proxy.history_mode. cache-aware keeps provider prompt caches valid; rolling maximizes raw savings; off never prunes.
LEAN_CTX_ALLOW_INSECURE_HTTP_UPSTREAM 1 / unset Allow a trusted non-loopback plaintext http:// upstream (overrides proxy.allow_insecure_http_upstream). Use only on a trusted local network, e.g. http://host.docker.internal:2455 with Codex in front of the proxy.
LEAN_CTX_PROXY_MAX_BODY_MB number Maximum proxy request/response body size in MB before passthrough.
LEAN_CTX_PI_ROUTE_SHELL 1 / 0 Pi extension: route the Pi agent's shell commands through lean-ctx for compression.

Hook Redirect Exclusion

The lean-ctx hook redirect command intercepts native Read/Grep/ListFiles tool calls and redirects them to LeanCTX MCP tools. To exclude specific paths from this redirect (e.g. for Edit workflows or framework protocol files), use the redirect_exclude config option or the LEAN_CTX_HOOK_EXCLUDE environment variable.

# ~/.lean-ctx/config.toml
redirect_exclude = [".wolf/**", ".claude/**", "*.json", "CLAUDE.md"]

Agent Integration Modes

lean-ctx init --agent <tool> supports two --agent values: hybrid (MCP reads + shell hooks, recommended) and mcp (explicit ctx_* tools only). auto selects the best default per tool (Hybrid for agents with shell access, MCP for others). A third integration mode, CLI-Redirect, removes MCP entirely and drives LeanCTX through editor rules.

# Auto (recommended — selects Hybrid for most agents)
lean-ctx init --agent cursor

# Force MCP tools only
lean-ctx init --agent cursor --mode mcp

# Force Hybrid (MCP reads + shell compression)
lean-ctx init --agent cursor --mode hybrid

Binary File Passthrough (v2.21.0)

The hook redirect automatically detects binary files (images, PDFs, archives, fonts, videos, compiled files) by extension and passes them through to the native Read tool. This ensures AI agents can still view screenshots, images, and other non-text files without interference.


Shadow Mode v3.7.0

Shadow Mode transparently intercepts native Read, Grep, and Shell tool calls via IDE hooks and routes them through lean-ctx's compression and caching layer. This provides full token savings without requiring the agent to explicitly call ctx_read/ctx_search/ctx_shell.

How it works

  1. When enabled, lean-ctx strengthens MCP instructions to MUST-level routing directives
  2. Bypass hints trigger on the first native tool use (not after 5 calls) with stronger "intercepted" wording
  3. All intercepted calls are logged to ~/.lean-ctx/shadow.log for audit transparency
  4. Redirected output includes a header explaining the interception

Configuration

# Enable shadow mode
lean-ctx config set shadow_mode true

# Or via environment variable
export LEAN_CTX_SHADOW_MODE=true

Visibility

Shadow mode status is visible in:

  • lean-ctx status — shows "shadow_mode: active" when enabled
  • lean-ctx doctor — validates hook wiring for interception
  • ~/.lean-ctx/shadow.log — full audit trail of intercepted calls

When to use

  • Agents that ignore MCP tool instructions and keep using native Read/Grep
  • Automated pipelines where you cannot control the agent's tool choice
  • Teams wanting guaranteed token savings without agent cooperation

Cursor Rule

For maximum token savings, add a .cursor/rules/lean-ctx.mdc to your project. This instructs the LLM to prefer LeanCTX tools and use compact output patterns. An example is included in examples/lean-ctx.mdc in the repository.

The Cursor rule includes CRP v2 (Compact Response Protocol) which can reduce both output tokens (50–80%) and thinking tokens (30–60%) through structured task parsing and one-hypothesis reasoning. These ranges are per-response estimates and depend on the model and task complexity.


Autonomy Configuration

The autonomous intelligence layer runs optimization pipelines automatically. Configure in ~/.lean-ctx/config.toml:

[autonomy]
enabled = true                    # Master switch for all autonomy features
auto_preload = true               # Pre-cache imported files after ctx_read
auto_dedup = true                 # Auto-deduplicate at 8+ cached files
auto_related = true               # Suggest related files via import graph
auto_consolidate = true           # Auto-consolidate knowledge periodically
silent_preload = true             # Cache files without output
dedup_threshold = 8               # Files before auto-dedup triggers
consolidate_every_calls = 25      # Run consolidation every N tool calls
consolidate_cooldown_secs = 120   # Minimum seconds between consolidations
cognition_loop_enabled = true     # Background cognition loop (periodic knowledge consolidation)
cognition_loop_interval_secs = 3600  # Seconds between cognition-loop iterations
cognition_loop_max_steps = 8      # Maximum steps per cognition-loop iteration

Override with environment: LEAN_CTX_AUTONOMY=false disables all.

All Autonomy Fields

KeyTypeDefaultDescription
autonomy.enabledbooltrueMaster switch. When false, all autonomy features are disabled regardless of individual settings.
autonomy.auto_preloadbooltrueAfter ctx_read, automatically pre-cache files referenced via imports/includes.
autonomy.auto_dedupbooltrueAutomatically deduplicate the file cache when it exceeds dedup_threshold.
autonomy.auto_relatedbooltrueSuggest related files based on the import graph when reading a file.
autonomy.auto_consolidatebooltruePeriodically consolidate knowledge base entries to merge duplicates and prune stale entries.
autonomy.silent_preloadbooltruePre-cache files silently without adding output to tool responses. Disable to see which files were preloaded.
autonomy.dedup_thresholdu328Number of cached files that triggers automatic deduplication.
autonomy.consolidate_every_callsu3225Run knowledge consolidation every N tool calls. Higher values reduce overhead but delay cleanup.
autonomy.consolidate_cooldown_secsu32120Minimum seconds between two consecutive consolidation runs, preventing rapid repeated consolidation.
autonomy.cognition_loop_enabledbooltrueEnable the background cognition loop that periodically consolidates knowledge between sessions.
autonomy.cognition_loop_interval_secsu643600Seconds between cognition-loop iterations.
autonomy.cognition_loop_max_stepsu88Maximum reasoning steps per cognition-loop iteration.

Multi-Root Workspaces v3.7.0

LeanCTX supports working across multiple repositories from a single parent directory. There are two approaches:

Auto-detection (no config needed)

If your working directory has 2 or more child directories with project markers (.git, Cargo.toml, package.json, etc.), LeanCTX auto-detects it as a multi-repo workspace and indexes everything under the parent.

# Just cd into the parent — LeanCTX handles the rest
cd ~/code
lean-ctx status
# → project_root: /Users/you/code (multi-repo workspace)

extra_roots (explicit configuration)

For repos in different locations, or fine-grained control over which repos are indexed:

# ~/.lean-ctx/config.toml
extra_roots = [
    "/Users/you/work/api",
    "/Users/you/work/frontend",
    "/Users/you/oss/cool-lib",
]

# Or per-project in .lean-ctx.toml:
extra_roots = ["../shared-infra", "../common-types"]
KeyTypeDefaultDescription
extra_rootsstring[][]Additional directories to index and include in search. Each gets its own graph + BM25 index (up to 8). Automatically added to PathJail allow-list.

How indexing works

  • Primary root: Indexed first (synchronous for first tool call)
  • Extra roots: Indexed in background threads after primary completes
  • Deduplication: Extra roots inside the primary root are skipped (already covered)
  • Storage: Each root gets its own ~/.lean-ctx/graphs/<hash>/ directory

For a detailed walkthrough with troubleshooting, see the Multi-Repo Workspace journey.


User TOML Filters

Define custom compression rules in ~/.lean-ctx/filters/*.toml. User filters are applied before builtin patterns.

# ~/.lean-ctx/filters/my-api.toml
name = "My API filter"
commands = ["curl"]

[[rules]]
pattern = "X-Request-Id: [a-f0-9-]+"
replacement = ""

[[rules]]
pattern = "^\\s+$"
replacement = ""

Manage via CLI: lean-ctx filter list, lean-ctx filter validate, lean-ctx filter init (creates example).


Security Layer v3.1.3

Security

LeanCTX enforces these security boundaries automatically. No configuration needed - they are always active:

FeatureBehavior
PathJailAll file operations are sandboxed to the project root. Symlink traversal, ../ path escapes, and absolute paths outside the project are blocked. Fixes CVE-class symlink leak vulnerabilities.
Shell Output CapShell command output is capped at 200KB with clear truncation markers ([truncated]). Prevents memory exhaustion from runaway commands.
File Size CapFile reads are capped at 10MB. Prevents accidental ingestion of binary files or generated assets.

PathJail (Project-Root Sandbox)

Every file operation is validated through a single resolve_path choke point. Paths must resolve inside the project root - symlink attacks, ../ traversal, and absolute paths outside the project are rejected. The sandbox is enforced for ctx_read, ctx_edit, ctx_search, ctx_tree, and all other file-touching tools.

Size Caps

Env VariableDefaultProtects
LCTX_MAX_READ_BYTES4 MBFile reads (ctx_read, ctx_edit)
LCTX_MAX_SHELL_BYTES2 MBShell output capture (ctx_shell)

Prompt Injection Hardening

All metadata in tool responses is sanitized via neutralize_metadata - stripping control characters, encoded sequences, and injection patterns. Sensitive output blocks (knowledge, memory, gotchas) are wrapped in CSPRNG-fenced boundaries to prevent prompt injection through LLM-generated content stored in memory.

TOCTOU Mitigation

ctx_edit uses the same file handle for read-verify-write, preventing time-of-check-to-time-of-use race conditions where a file could be swapped between the validation and write phases.


Secret Detection v3.6.0

The [secret_detection] section configures regex-based secret detection in tool outputs. When enabled, LeanCTX scans all tool responses for patterns matching API keys, tokens, passwords, and other sensitive values.

Configuration

# ~/.lean-ctx/config.toml
[secret_detection]
enabled = true                # Enable regex-based secret detection (default: true)
redact = true                 # Automatically redact detected secrets (default: true)
custom_patterns = []          # Additional regex patterns for detection (default: [])
KeyTypeDefaultDescription
secret_detection.enabledbooltrueEnable regex-based secret detection. When enabled, tool outputs are scanned for patterns matching known secret formats (API keys, tokens, passwords, private keys).
secret_detection.redactbooltrueAutomatically redact detected secrets from tool output before it reaches the agent.
secret_detection.custom_patternslist[]Additional regex patterns for secret detection, merged with the built-in patterns. Each entry is a regex string. Example: ["MYAPP_[A-Z0-9]{32}", "custom-secret-[a-f0-9]+"]

Boundary Policy v3.6.0

The [boundary_policy] section controls cross-project access behavior. In monorepo or multi-project setups, this determines whether agents can search or import files across project boundaries, and whether such access is logged for audit.

Configuration

# ~/.lean-ctx/config.toml
[boundary_policy]
cross_project_search = false      # Allow searching across project boundaries (default: false)
cross_project_import = false      # Allow importing knowledge from other projects (default: false)
audit_cross_access = true         # Log an audit event on cross-project access (default: true)
universal_gotchas_enabled = true  # Load universal (cross-project) gotchas (default: true)
KeyTypeDefaultDescription
boundary_policy.cross_project_searchboolfalseAllow searching across project boundaries.
boundary_policy.cross_project_importboolfalseAllow importing knowledge facts from other projects.
boundary_policy.audit_cross_accessbooltrueLog an audit event whenever cross-project access occurs.
boundary_policy.universal_gotchas_enabledbooltrueLoad universal (cross-project) gotchas alongside project-scoped ones.

Data Directory v3.1.3

All persistent data (stats, knowledge, agent state, sessions, cache) is stored under a single base directory, resolved in this order:

  1. LEAN_CTX_DATA_DIR environment variable (if set)
  2. ~/.lean-ctx (default)
# Override for custom locations or containers
export LEAN_CTX_DATA_DIR=/data/lean-ctx

# Verify current data directory
ls "$(lean-ctx config | grep data_dir)"

CLI File Cache v2.21.1

Since v2.21.1, lean-ctx read <file> in CLI mode caches file content to $LEAN_CTX_DATA_DIR/cli-cache/cache.json (default: ~/.lean-ctx/cli-cache/cache.json). Subsequent reads of unchanged files return a compact ~13-token cache-hit response instead of the full file content. This enables caching for CLI-mode integrations (e.g. pi-lean-ctx) that don't use the MCP server.

ParameterValue
TTL5 minutes (300s)
Max entries200
Change detectionBLAKE3 hash
Cache location~/.lean-ctx/cli-cache/cache.json

Management Commands

lean-ctx cache              # Overview with hit rate
lean-ctx cache stats        # Detailed statistics
lean-ctx cache clear        # Remove all entries
lean-ctx cache invalidate <path>  # Remove specific file

lean-ctx read file.rs --fresh     # Bypass cache for one read

Cache Eviction Policy

The session cache uses a multi-signal eviction system: Reciprocal Rank Fusion (RRF) fuses recency, frequency, and size into a base score. On top, Hebbian co-access patterns track which files are used together, and a Boltzmann temperature mechanism adjusts eviction aggressiveness based on memory pressure. Entries with the lowest combined energy are evicted first. No manual tuning required.


Progressive Throttling / Loop Detection

LeanCTX automatically detects when an AI agent loops - calling the same or similar tools repeatedly without progress. This prevents token waste in large and monorepo projects.

Per-Fingerprint Throttling

Tool calls are tracked using a fingerprint-based sliding window (default 5 minutes). When repeated identical calls are detected, throttling escalates:

LevelTriggerBehavior
Normal≤ 2 identical callsNo intervention
Reduced3+ identical calls (configurable via reduced_threshold)Warning appended to tool response
BlockedDisabled by default (blocked_threshold = 0). Set to a positive value to enable.Tool call blocked with actionable guidance

Cross-Tool Search Tracking v3.1.2

Agents often alternate between ctx_search, ctx_shell (grep/rg/find), and ctx_semantic_search to search for the same thing. LeanCTX now tracks ALL search-related calls as a group. If more than 10 total search calls happen within the window (regardless of which tool), the agent is blocked with guidance to use ctx_tree and narrow searches with the path parameter.

Pattern Similarity Detection v3.1.2

Searching for "compress", then "compression", then "compress_output" is now detected as the same semantic loop. LeanCTX extracts the alpha-root of each search pattern and groups similar queries together.

Configuration

All thresholds are configurable via ~/.lean-ctx/config.toml:

[loop_detection]
normal_threshold = 2      # warn after this many identical calls
reduced_threshold = 4     # reduce output after this many
blocked_threshold = 0     # block after this many (0 = disabled)
window_secs = 300         # sliding window in seconds
search_group_limit = 10   # total search calls before block

# Per-tool total call ceilings within one session (0 = unlimited)
[loop_detection.tool_total_limits]
ctx_read = 100
ctx_search = 80
ctx_semantic_search = 60
ctx_shell = 50

Pipe Guard v2.21.6

Since v2.21.6, the shell hook automatically detects when stdout is piped (not a terminal) and bypasses all compression. This prevents corruption when piping command output - for example, curl -fsSL https://example.com/install.sh | sh now works correctly even with the LeanCTX shell hook active.

ShellDetection Method
Bash / Zsh[ ! -t 1 ]
Fishnot isatty stdout
PowerShell[Console]::IsOutputRedirected

Tool Result Archive v3.3.3

When compression removes details you might need later, the Tool Result Archive saves the full uncompressed output to disk and returns a reference ID. The agent can retrieve the full content at any time using ctx_expand.

This is the core of zero-loss compression: the context window stays small, but no information is permanently lost.

How It Works

  1. A tool response exceeds the configured token threshold
  2. LeanCTX stores the full output to ~/.lean-ctx/archive/ (content-addressed by SHA-256)
  3. The compressed response includes an [ARCHIVE: <id>] reference
  4. The agent calls ctx_expand <id> to retrieve the full content on demand

Configuration

# ~/.lean-ctx/config.toml
[archive]
enabled = true                # Enable tool result archiving (default: true)
ephemeral = true              # Replace large results with summary + ref, retrievable via ctx_expand (default: true)
ephemeral_min_tokens = 2000   # Minimum output tokens before the ephemeral firewall fires (default: 2000)
threshold_chars = 800         # Minimum characters before archiving (default: 800)
max_age_hours = 48            # Auto-cleanup after N hours (default: 48)
max_disk_mb = 500             # Maximum total disk usage for archive (default: 500)
KeyTypeDefaultDescription
archive.enabledbooltrueEnable the archive system. When disabled, compression is permanent (no retrieval).
archive.ephemeralbooltrueReplace large results with a summary + reference; retrieve the full body on demand with ctx_expand. Env: LEAN_CTX_EPHEMERAL.
archive.ephemeral_min_tokensusize2000Minimum output tokens before the ephemeral firewall replaces the inline body with summary + ref. Env: LEAN_CTX_EPHEMERAL_MIN_TOKENS.
archive.threshold_charsusize800Minimum output size in characters before a tool result is archived to disk.
archive.max_age_hoursu6448Global maximum age for archived entries. Entries older than this are purged regardless of access patterns.
archive.max_disk_mbu64500Maximum total disk space (in MB) the archive directory may consume. Oldest entries are evicted when the limit is reached.

Environment Variables

VariableValuesDescription
LEAN_CTX_ARCHIVEtrue / falseOverride archive.enabled at runtime.
LEAN_CTX_ARCHIVE_THRESHOLDnumberOverride archive.threshold_chars.

Storage

Archived results are content-addressed (SHA-256 hash of the full output). Duplicate content is automatically deduplicated. Race conditions from parallel tool calls are handled via PID-unique temporary files with atomic rename.



Compression Level v4.0.0

compression_level is the unified control for the 4-layer terse engine, replacing the legacy output_density and terse_agent settings. It governs both input compression (tool responses) and output optimization (agent responses) through a single knob.

Levels

LevelValueBehavior
Off"off"No compression. Full tool output, no output optimization.
Lite"lite"Abbreviations and function references. Moderate input compression (~20-40% savings).
Standard"standard"Balanced compression with CEP v1 protocol, delta-only output, and structured notation. Recommended when you want denser agent output.
Max"max"Maximum compression. Single-line output, aggressive truncation, symbols only. Best for CI/automated pipelines.

Configuration

# ~/.lean-ctx/config.toml
compression_level = "lite"    # lite (default) | off | standard | max

# Legacy settings still accepted for backward compatibility:
# terse_agent = "full"            # maps to compression_level = "standard"
# output_density = "terse"        # maps to compression_level = "lite"

Environment Variables

VariableValuesDescription
LEAN_CTX_COMPRESSIONoff / lite / standard / maxOverride compression_level at runtime.
LEAN_CTX_TERSE_AGENToff / lite / full / ultra / true / falseLegacy. Still accepted. Mapped to compression_level internally.

Interaction with CRP Mode

compression_level and LEAN_CTX_CRP_MODE are complementary but independent. CRP mode controls the format of LeanCTX's own output (tdd/compact/off), while compression_level controls both input compression and the instructions given to the agent about how it should respond. Both can be active simultaneously for maximum token savings.

What Changes (Standard / Max)

When compression is active at "standard" or above, the 4-layer terse engine applies:

  • Layer 1: Dictionary — Common token substitutions and abbreviations
  • Layer 2: Residual — Whitespace normalization, boilerplate removal
  • Layer 3: Scoring — Information-theoretic ranking of content blocks
  • Layer 4: Pipeline — CEP v1 protocol with delta-only output, structured notation (+/-/~), and token budgets

This can reduce total token usage by 30-50% per conversation turn. Formally verified by 82 Lean4 theorems including TerseQuality and TerseEngine proofs.

Legacy: Terse Agent Mode

The terse_agent setting is still accepted for backward compatibility. Values are mapped automatically: "off" → Off, "lite" → Lite, "full" → Standard, "ultra" → Max. Boolean true maps to Standard.


Legacy: Output Density v3.1.0 — superseded by compression_level

output_density is superseded by compression_level, which unifies both input and output compression into a single setting. The legacy output_density values are still accepted and mapped automatically: "normal" → Off, "terse" → Lite, "ultra" → Max.

Legacy Configuration

# ~/.lean-ctx/config.toml
# Legacy (still works):
output_density = "terse"

# Recommended replacement:
compression_level = "lite"

Minimal Overhead v3.4.1

minimal_overhead reduces LeanCTX's per-call token footprint to the absolute minimum. It's designed for environments where every token counts - Codex, CI pipelines, or any cost-sensitive workflow.

What it disables

FeatureNormal ModeMinimal Mode
Auto-checkpoint injectionInjected every N calls with session cacheSkipped entirely
Savings notes[saved 142 tokens vs native Grep]Suppressed
Stale notes[cache stale, full→signatures]Suppressed
Shell efficiency hints[hint: ctx_search is more token-efficient]Suppressed
Archive hints[result archived as A1, use ctx_expand]Suppressed
Session block in instructionsActive session stats blockRemoved

Configuration

# ~/.lean-ctx/config.toml
minimal_overhead = true

# Or via environment variable
# export LEAN_CTX_MINIMAL=1

# To only disable checkpoints (keep other meta-strings):
# export LEAN_CTX_NO_CHECKPOINT=1

When to use

  • Codex / Claude Code CLI - these environments benefit most from reduced overhead since every token in the conversation counts against the context window
  • CI/CD pipelines - automated tasks where meta-strings add noise without value
  • High-frequency tool calls - sessions with many short tool calls where per-call overhead accumulates
  • Cost optimization - when you want to minimize API costs without changing compression settings

Measured impact

Combined with lazy tools (default), minimal overhead reduces per-session token overhead from ~6,600 tokens (full tools + verbose) to ~2,400 tokens (lazy + minimal) - a 64% reduction.


Rules Scope v3.3.3

Controls where LeanCTX injects its cursor rules file (lean-ctx.mdc). By default, rules are injected in both the global and project locations to ensure coverage across all Cursor workspaces.

Values

ValueInjection LocationUse Case
"global"~/.cursor/rules/lean-ctx.mdcShare LeanCTX rules across all projects. Project directories stay clean.
"project".cursor/rules/lean-ctx.mdcPer-project rules only. Useful when global rules conflict with other tools.
"both"Both locationsMaximum coverage - ensures LeanCTX is active regardless of how Cursor resolves rules.

Configuration

# ~/.lean-ctx/config.toml
rules_scope = "global"    # global | project | both

# Set via CLI
lean-ctx config set rules_scope project

Buddy Mode

Buddy mode enables collaborative multi-agent workflows. When enabled, LeanCTX coordinates context sharing between multiple agent sessions working on the same project.

Configuration

# ~/.lean-ctx/config.toml
buddy_enabled = true
KeyTypeDefaultDescription
buddy_enabledbooltrueEnable buddy mode for multi-agent collaboration. Agents can share cached files, knowledge entries, and session context via ctx_agent.

Custom Aliases

Define custom shell command aliases that expand inside ctx_shell. Useful for project-specific shortcuts that agents can use without knowing the full command.

Configuration

# ~/.lean-ctx/config.toml
[[custom_aliases]]
alias = "test"
command = "cargo test --workspace --quiet"

[[custom_aliases]]
alias = "lint"
command = "npm run lint -- --fix"

[[custom_aliases]]
alias = "deploy-staging"
command = "kubectl apply -f k8s/staging/ --dry-run=client"
FieldTypeDescription
aliasstringThe alias name. Used as ctx_shell("@test") or similar shorthand.
commandstringThe full command that the alias expands to.

Headless MCP Mode v3.3.3

By default, when LeanCTX starts as an MCP server it automatically configures the environment: injecting rules, installing hooks, updating CLAUDE.md, and registering itself. If you want full control over your configuration - for example when using a custom launcher - you can disable all auto-setup behavior.

Usage

# Set before launching the MCP server
export LEAN_CTX_HEADLESS=1

# lean-ctx will start as a pure MCP server:
# - No rules injection
# - No hook installation
# - No CLAUDE.md modification
# - No agent registry updates
# - No background version check

When to Use

  • Custom launchers - You inject LeanCTX instructions via --append-system-prompt
  • Toggle setups - You want to switch LeanCTX on/off per session
  • CI/CD pipelines - No interactive environment, no need for hooks
  • Sandboxed environments - You don't want LeanCTX modifying files outside the project

Project Identity File (.lean-ctx-id) v3.5.16

LeanCTX identifies projects by hashing their root path. In Docker or CI environments where multiple projects share the same mount path (e.g. /workspace), this can cause data collisions, graph index, semantic cache, bandit state, and embedding index from one project bleeding into another.

To prevent this, create a .lean-ctx-id file in your project root with a unique project name. This file takes highest priority for project identification, above git remote URL, package.json name, and directory name.

# Create the identity file
echo "my-unique-project-name" > .lean-ctx-id

Priority Order

PrioritySourceExample
1 (highest).lean-ctx-idmy-api-service
2Git remote URLgithub.com/org/repo
3package.json / Cargo.toml namemy-api
4 (lowest)Directory path/workspace

Identity-Aware Caches

The following data stores use a composite project hash (path + identity) to ensure isolation:

  • Graph index, project dependency graph (SQLite Property Graph)
  • Semantic cache, embedding-based similarity lookups
  • Bandit state, multi-armed bandit model for read mode selection
  • Embedding index, vector store for semantic search

When a .lean-ctx-id file is added or changed, existing data is automatically migrated from old hash directories. No manual action required.

Docker Usage

# Include in your Dockerfile or mount as volume
COPY .lean-ctx-id /workspace/.lean-ctx-id

# Or create during build
RUN echo "my-project" > /workspace/.lean-ctx-id

Shell Activation v3.5.16

shell_activation controls when LeanCTX shell aliases (like _lc) auto-activate in interactive shells. By default, LeanCTX activates in every shell. In team environments or CI, you may want to limit activation to AI agent sessions only.

Modes

ModeValueBehavior
Always"always"Active in every interactive shell. Default behavior, same as previous versions.
Agents Only"agents-only"Only activates when AI agent environment variables are detected: LEAN_CTX_AGENT, CLAUDECODE, CODEX_CLI_SESSION, GEMINI_SESSION. Since v3.5.19, these same variables also enable tracking in non-interactive shells (e.g. Docker bash -c, Codex CLI), bypassing the TTY guard that normally disables the hook when stdout is not a terminal.
Off"off"Never auto-activate. User must call lean-ctx-on manually to enable shell aliases.

Configuration

# ~/.lean-ctx/config.toml
shell_activation = "agents-only"    # always | agents-only | off

# Or via environment variable
# export LEAN_CTX_SHELL_ACTIVATION=agents-only

When to Use

  • always — Solo developer, want compression in every terminal
  • agents-only — Team environments where non-AI shells should remain unmodified. Also enables non-interactive (non-TTY) tracking for Docker/Codex containers (v3.5.19+)
  • off — Full manual control, only enable when explicitly needed

Cloud

The [cloud] section controls cloud integration features for LeanCTX.

Configuration

# ~/.lean-ctx/config.toml
[cloud]
contribute_enabled = false    # Opt-in to anonymous usage telemetry (default: false)
KeyTypeDefaultDescription
cloud.contribute_enabledboolfalseOpt-in to anonymous usage telemetry. When enabled, LeanCTX sends aggregated compression statistics to help improve the product. No code, file paths, or personal data is transmitted.

Providers

The [providers] section controls external data sources. Provider data flows through the full consolidation pipeline — BM25, graph edges, knowledge facts, and session cache.

# ~/.lean-ctx/config.toml
[providers]
enabled = true            # Enable/disable all providers
auto_index = true         # Index into BM25/Graph/Knowledge (not just cache)
cache_ttl_secs = 120      # In-memory TTL for provider results

# MCP bridge — HTTP transport
[providers.mcp_bridges.knowledge-base]
url = "http://localhost:8080"

# MCP bridge — stdio transport
[providers.mcp_bridges.github-mcp]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]
auth_env = "GITHUB_TOKEN"
KeyTypeDefaultDescription
providers.enabledbooltrueMaster switch for all data source providers.
providers.auto_indexbooltrueIndex provider data into BM25, Graph, and Knowledge. Set false for cache-only.
providers.cache_ttl_secsu64120TTL for in-memory provider result cache.
providers.github.enabledbooltrueEnable/disable the GitHub provider.
providers.github.api_urlstring?nullGitHub API base URL (for GitHub Enterprise).
providers.gitlab.enabledbooltrueEnable/disable the GitLab provider.
providers.gitlab.api_urlstring?nullGitLab API base URL (for self-hosted instances).
providers.mcp_bridges.<name>.urlstring?HTTP endpoint for MCP server.
providers.mcp_bridges.<name>.commandstring?Executable for stdio-based MCP server.
providers.mcp_bridges.<name>.argsstring[][]Arguments for the stdio command.
providers.mcp_bridges.<name>.auth_envstring?Environment variable for auth token injection.

Jira Cloud OAuth 2.0 (3LO) v3.6.25

The built-in Jira provider supports OAuth 2.0 (3-legged) as an alternative to Basic auth (JIRA_EMAIL + JIRA_API_TOKEN). LeanCTX ships no embedded client secret, so you register your own free Atlassian OAuth app at developer.atlassian.com/console/myapps (callback URL http://localhost), then export its credentials:

export JIRA_OAUTH_CLIENT_ID=...        # from your Atlassian 3LO app
export JIRA_OAUTH_CLIENT_SECRET=...    # from your Atlassian 3LO app
export JIRA_AUTH=oauth                 # optional: force OAuth over Basic auth

lean-ctx provider auth jira            # one-time interactive consent
Env VarRequiredDescription
JIRA_OAUTH_CLIENT_IDyesClient id of your Atlassian OAuth 2.0 (3LO) app.
JIRA_OAUTH_CLIENT_SECRETyesClient secret of the same app.
JIRA_OAUTH_SCOPESnoSpace-separated scopes. Default: read:jira-work read:jira-user offline_access (offline_access enables refresh tokens).
JIRA_AUTHnoSet to oauth to force OAuth. Otherwise OAuth is used automatically when a stored credential exists; Basic auth is the fallback.

Tokens are stored in ~/.lean-ctx/credentials/jira-oauth.json (0600) and refreshed automatically with refresh-token rotation. Manage credentials via the lean-ctx provider command.


Proxy

The [proxy] section lets you override upstream API endpoints for LLM providers. Useful for corporate proxies, self-hosted inference, or regional routing.

Configuration

# ~/.lean-ctx/config.toml
[proxy]
anthropic_upstream = null     # Custom Anthropic API endpoint (default: null)
openai_upstream = null        # Custom OpenAI API endpoint (default: null)
gemini_upstream = null        # Custom Gemini API endpoint (default: null)
history_mode = "cache-aware"  # History pruning: cache-aware (default) | rolling | off
allow_insecure_http_upstream = false  # Allow a trusted plaintext http:// upstream (default: false)
KeyTypeDefaultDescription
proxy.anthropic_upstreamstring?nullCustom upstream URL for Anthropic API requests. Set to your corporate proxy or self-hosted endpoint.
proxy.openai_upstreamstring?nullCustom upstream URL for OpenAI API requests.
proxy.gemini_upstreamstring?nullCustom upstream URL for Gemini API requests.
proxy.history_modeenum"cache-aware"History pruning strategy. cache-aware: frozen boundaries that keep provider prompt caches valid (default). rolling: legacy moving window (max raw savings, breaks prompt caching). off: never prune. Env: LEAN_CTX_PROXY_HISTORY_MODE.
proxy.allow_insecure_http_upstreamboolfalseAllow a trusted non-loopback http:// upstream (e.g. http://host.docker.internal:2455 when a client like Codex sits in front of the proxy). Off by default — plaintext upstreams are rejected with an HTTPS error. The startup banner and doctor flag the plaintext hop so it stays a conscious choice. Env: LEAN_CTX_ALLOW_INSECURE_HTTP_UPSTREAM.

Embedding Engine

Local ONNX embedding model used by ctx_semantic_search. Switching models re-indexes once on the next search; nothing leaves your machine.

Configuration

# ~/.lean-ctx/config.toml
[embedding]
model = "minilm"          # minilm (384d, default) | jina-code-v2 (768d) | nomic (768d) | hf:org/repo
auto_download = true      # Download the model in the background on first semantic need (default: allowed)
KeyTypeDefaultDescription
embedding.modelstring"minilm"Local ONNX model: minilm (all-MiniLM-L6-v2, 384d), jina-code-v2 (768d, code-optimized), nomic (768d), or any HuggingFace ONNX export via hf:org/repo[@revision]. Env: LEAN_CTX_EMBEDDING_MODEL.
embedding.auto_downloadbool?nullDownload the embedding model in the background on first semantic need (default: allowed). Set false for air-gapped machines. Env: LEAN_CTX_EMBEDDINGS_AUTO_DOWNLOAD.
embedding.dimensionsinteger?nullDeclared embedding width for hf: custom models (fallback only — the real width is probed from the ONNX graph). Built-in models ignore this key.

Memory

The [memory] section configures LeanCTX's persistent memory subsystem. Memory is organized into specialized stores, each with its own retention policy, capacity limits, and retrieval rules. Use memory_profile for a preset, or fine-tune individual sub-tables.

How Memory Lifecycle Works

Memory entries (facts, patterns, gotchas) have a confidence score that changes over time:

  1. New facts start with high confidence (based on source quality)
  2. Daily decay (decay_rate) gradually reduces confidence of unused facts
  3. Access resets, when a fact is recalled by the agent, its confidence is restored
  4. Low-confidence facts (below low_confidence_threshold) are flagged for review
  5. Stale facts (not accessed for stale_days) become eligible for pruning
  6. Pruning happens during auto_consolidate runs, not instantly

[memory.knowledge]

Fact store for project-level knowledge extracted from conversations and code analysis.

[memory.knowledge]
max_facts = 200               # Maximum stored facts per project (default: 200)
max_patterns = 50             # Maximum code patterns (default: 50)
max_history = 100             # Maximum history entries (default: 100)
contradiction_threshold = 0.5 # Confidence threshold for contradiction detection (default: 0.5)
recall_facts_limit = 10       # Facts recalled per retrieval (default: 10)
rooms_limit = 25              # Maximum rooms returned (default: 25)
timeline_limit = 25           # Maximum timeline entries (default: 25)
relations_limit = 40          # Maximum relations returned (default: 40)
KeyTypeDefaultDescription
memory.knowledge.max_factsusize200Maximum number of facts stored in the knowledge base per project. Oldest entries are evicted when the limit is reached.
memory.knowledge.max_patternsusize50Maximum number of code patterns retained.
memory.knowledge.max_historyusize100Maximum history entries retained in the knowledge timeline.
memory.knowledge.contradiction_thresholdf320.5Confidence threshold for automatic contradiction detection between facts.
memory.knowledge.recall_facts_limitusize10Number of facts retrieved per knowledge recall query.
memory.knowledge.rooms_limitusize25Maximum number of rooms returned per query.
memory.knowledge.timeline_limitusize25Maximum number of timeline entries returned per query.
memory.knowledge.relations_limitusize40Maximum number of entity relations returned per query.

[memory.episodic]

Session-level memory capturing what happened during agent interactions.

[memory.episodic]
max_episodes = 500            # Maximum stored episodes (default: 500)
max_actions_per_episode = 50  # Actions per episode (default: 50)
summary_max_chars = 200       # Episode summary length (default: 200)
KeyTypeDefaultDescription
memory.episodic.max_episodesusize500Maximum number of episodes retained across sessions.
memory.episodic.max_actions_per_episodeusize50Maximum actions recorded per individual episode.
memory.episodic.summary_max_charsusize200Maximum character length for automatically generated episode summaries.

[memory.procedural]

Learned procedures extracted from repeated agent workflows.

[memory.procedural]
max_procedures = 100          # Maximum stored procedures (default: 100)
min_repetitions = 3           # Repetitions before a pattern becomes a procedure (default: 3)
min_sequence_len = 2          # Minimum sequence length for detection (default: 2)
max_window_size = 10          # Maximum window size for pattern analysis (default: 10)
KeyTypeDefaultDescription
memory.procedural.max_proceduresusize100Maximum number of learned procedures stored.
memory.procedural.min_repetitionsusize3Minimum times a workflow pattern must repeat before it is promoted to a procedure.
memory.procedural.min_sequence_lenusize2Minimum length of a tool-call sequence to be considered for procedure extraction.
memory.procedural.max_window_sizeusize10Maximum sliding window size when scanning for repeated patterns.

[memory.lifecycle]

Controls how memory entries age, decay, and are pruned over time.

[memory.lifecycle]
decay_rate = 0.01             # Daily decay factor for memory scores (default: 0.01)
low_confidence_threshold = 0.3 # Below this, facts are low-confidence (default: 0.3)
stale_days = 30               # Days before an entry is considered stale (default: 30)
similarity_threshold = 0.85   # Cosine similarity for deduplication (default: 0.85)
KeyTypeDefaultDescription
memory.lifecycle.decay_ratef320.01Daily decay factor applied to memory entry scores. Higher values age entries faster.
memory.lifecycle.low_confidence_thresholdf320.3Facts with confidence below this threshold are flagged as low-confidence and may be pruned earlier.
memory.lifecycle.stale_daysi6430Number of days after which an unaccessed entry is considered stale and eligible for pruning.
memory.lifecycle.similarity_thresholdf320.85Cosine similarity threshold for deduplication. Entries above this threshold are merged.

[memory.gotcha]

Stores project-specific gotchas, pitfalls, caveats, and non-obvious behaviors discovered during sessions.

[memory.gotcha]
max_gotchas_per_project = 100       # Maximum gotchas per project (default: 100)
retrieval_budget_per_room = 10      # Gotchas surfaced per session (default: 10)
default_decay_rate = 0.03           # Default decay rate for gotcha importance (default: 0.03)
KeyTypeDefaultDescription
memory.gotcha.max_gotchas_per_projectusize100Maximum number of gotchas stored per project.
memory.gotcha.retrieval_budget_per_roomusize10Maximum number of gotchas surfaced in a single session context.
memory.gotcha.default_decay_ratef320.03Default daily decay rate applied to gotcha importance scores. Category-specific overrides can be set via category_decay_overrides.

[memory.embeddings]

Configuration for the vector embedding index used by semantic memory operations.

[memory.embeddings]
max_facts = 2000              # Maximum facts in the embedding index (default: 2000)
KeyTypeDefaultDescription
memory.embeddings.max_factsusize2000Maximum number of facts indexed in the vector embedding store.

Exit Codes

In shell hook mode (-c), LeanCTX forwards the exit code of the wrapped command. This ensures scripts and CI pipelines work correctly. If the command fails (non-zero exit), the full original output is saved to ~/.lean-ctx/tee/ for debugging (when tee_mode is set to failures or always).


Token Counting

LeanCTX uses tiktoken-rs with the o200k_base encoding (same as GPT-4o, Claude, and other modern models) for exact token counting. No estimation, no heuristics - every savings number you see in lean-ctx gain or the dashboard reflects real token counts.


Complete key reference

Every section and key the binary accepts, generated from lean-ctx config schema — the same schema config validate checks against. The guides above explain the keys you will actually tune; this table guarantees nothing is undocumented.

top-level keys Top-level configuration keys
KeyTypeDefaultDescription
agent_token_budget usize 0 Default per-agent token budget. 0 = unlimited
allow_auto_reroot bool false Allow automatic project-root re-rooting when absolute paths outside the jail are seen
allow_paths string[] [] Additional paths allowed by PathJail (absolute)
auto_capture bool true Automatic knowledge capture from tool findings
bm25_max_cache_mb u64 128 Maximum BM25 cache file size in MB
buddy_enabled bool true Enable the buddy system for multi-agent coordination
cache_policy enum(aggressive|safe|off) aggressive Cache policy for ctx_read: aggressive (13-tok stubs), safe (map on hit), off (always disk)
checkpoint_interval u32 15 Session checkpoint interval in minutes
compression_level enum lite Unified output-style level for the model's prose (not tool-output compression). lite=plain concise (default), standard/max=denser symbolic 'power modes'
content_defined_chunking bool false Enable Rabin-Karp chunking for cache-optimal output ordering
custom_aliases array [] Custom command aliases (array of {command, alias} entries)
default_tool_categories string[] [] Tool categories active by default (core, arch, debug, memory, metrics, session). Override via LCTX_DEFAULT_CATEGORIES
disabled_tools string[] [] Tools to exclude from the MCP tool list
enable_wakeup_ctx bool true Append wakeup briefing (facts, session summary) to ctx_overview output. Set false to reduce context bloat when calling ctx_overview frequently.
excluded_commands string[] [] Commands to exclude from shell hook interception
extra_ignore_patterns string[] [] Extra glob patterns to ignore in graph/overview/preload
extra_roots string[] [] Extra project roots for multi-root workspaces (auto-added to PathJail allow-list)
graph_index_max_files u64 0 Maximum files in graph index. 0 = unlimited (default). Set >0 to cap for constrained systems
journal_enabled bool true Write human-readable activity journal to ~/.lean-ctx/journal.md
max_disk_mb u64 0 Simplified disk budget in MB (0 = disabled). Distributes: archive ~25%, BM25 ~10%
max_ram_percent u8 5 Maximum percentage of system RAM that lean-ctx may use (1-50, default 5)
max_staleness_days u32 0 Auto-purge data older than N days (0 = disabled). Flows into archive.max_age_hours
memory_cleanup enum aggressive Controls how aggressively memory is freed when idle
memory_profile enum performance Controls RAM vs feature trade-off (performance = max quality)
minimal_overhead bool true Skip session/knowledge/gotcha blocks in MCP instructions
no_degrade boolean false Disable all automatic read-mode degradation. Override via LCTX_NO_DEGRADE=1
output_density enum normal Controls how dense/compact MCP tool output is formatted
passthrough_urls string[] [] URLs to pass through without proxy interception
permission_inheritance enum off Mirror the host IDE's permission rules onto lean-ctx tools (v1: OpenCode). When on, ctx_shell honors your bash/rm * rules instead of bypassing them. Override via LEAN_CTX_PERMISSION_INHERITANCE
preserve_compact_formats string[] ["toon"] Already-compact output formats preserved verbatim instead of recompressed (e.g. ["toon"]). Set to [] to disable
profile string Persistent profile name. Checked after LEAN_CTX_PROFILE env var. Set via: lean-ctx config set profile passthrough
project_root string? Explicit project root directory. Prevents accidental home-directory scans
proxy_enabled bool? Enable/disable the proxy layer. null = auto-detect, true = force on, false = force off
proxy_port u16? Custom proxy port (default: 4444). Useful for multi-user systems. Env: LEAN_CTX_PROXY_PORT
proxy_timeout_ms u64? Proxy reachability timeout in ms (default: 200). Override via LEAN_CTX_PROXY_TIMEOUT_MS
redirect_exclude string[] [] URL patterns to exclude from proxy redirection
reference_results bool false Store large tool outputs as references instead of inline content
response_verbosity enum normal Controls how verbose tool responses are
rules_injection enum shared How rules load for CLAUDE.md/AGENTS.md/GEMINI.md agents: shared block, dedicated (no shared-file edits; SessionStart hook / instructions[] / context.fileName), or off (write no rules file — for hosts that supply their own steering or phase-isolated/non-caching harnesses). Override via LEAN_CTX_RULES_INJECTION
rules_scope enum both Where agent rule files are installed. Override via LEAN_CTX_RULES_SCOPE
sandbox_level u8 0 Sandbox strictness level (0=default, 1=strict, 2=paranoid)
savings_footer enum always Controls visibility of token savings footers: always (default, show on every response), never, auto (context-dependent). Also: LEAN_CTX_SHOW_SAVINGS=1|0
shadow_mode bool false Opt-in (default off): transparently route native Read/Grep/Edit/Shell through lean-ctx — via hooks for hook-based agents, via the interception plugin for OpenCode
shell_activation enum always Controls when the shell hook auto-activates aliases
shell_allowlist array [] Optional shell command allowlist. When non-empty, only listed binaries are permitted
shell_allowlist_extra array [] Commands merged on top of shell_allowlist without replacing the defaults. Managed via `lean-ctx allow <cmd>`
shell_hook_disabled bool false Disable shell hook injection
shell_strict_mode bool false Block $(), backticks, <() in shell arguments. Default false = warn only.
slow_command_threshold_ms u64 5000 Commands taking longer than this (ms) are recorded in the slow log. Set to 0 to disable
structure_first bool false Opt-in: bias `auto` toward structure-first reads (map) for medium code files on a cold read. Off by default — for phase-isolated harnesses with no warm-session cache payback. Override via LEAN_CTX_STRUCTURE_FIRST
symbol_map_auto bool false Opt-in: α-code identifier substitution in aggressive reads (>50-file projects). Off by default — abbreviated symbols hinder editing/refactoring
team_auto_push bool false Opt-in: daemon periodically pushes your signed savings batch to team_url (off by default; requires team_url + team_token)
team_token string? Bearer token for the team server (push needs a member token; pull/auto-push needs the configured team token)
team_url string? Team server base URL for the opt-in savings roll-up (push/pull)
tee_mode enum failures Controls when shell output is tee'd to disk for later retrieval
terse_agent enum off Controls agent output verbosity via instructions injection
theme string default Dashboard color theme
tool_profile enum Tool visibility profile: minimal (6 tools), standard (22), power (all). Override via LEAN_CTX_TOOL_PROFILE
tools_enabled string[] [] Explicit list of enabled tool names (overrides tool_profile when non-empty)
ultra_compact bool false Legacy flag for maximum compression (use compression_level instead)
update_check_disabled bool false Disable the daily version check
[archive] Settings for the zero-loss compression archive (large tool outputs saved to disk)
KeyTypeDefaultDescription
enabled bool true Enable zero-loss compression archive
ephemeral bool true Replace large results with summary+ref (ctx_expand to retrieve). Env: LEAN_CTX_EPHEMERAL
ephemeral_min_tokens usize 2000 Minimum output tokens before the ephemeral firewall replaces inline body with summary+ref. Env: LEAN_CTX_EPHEMERAL_MIN_TOKENS
max_age_hours u64 48 Maximum age of archived entries before cleanup
max_disk_mb u64 500 Maximum total disk usage for the archive
threshold_chars usize 800 Minimum output size (chars) to trigger archiving
[autonomy] Controls autonomous background behaviors (preload, dedup, consolidation)
KeyTypeDefaultDescription
auto_consolidate bool true Auto-consolidate knowledge periodically
auto_dedup bool true Auto-deduplicate repeated reads
auto_preload bool true Auto-preload related files on first read
auto_related bool true Auto-load graph-related files
cognition_loop_enabled bool true Enable the background cognition loop (periodic knowledge consolidation)
cognition_loop_interval_secs u64 3600 Seconds between cognition loop iterations
cognition_loop_max_steps u8 8 Maximum steps per cognition loop iteration
consolidate_cooldown_secs u64 120 Minimum seconds between consolidation runs
consolidate_every_calls u32 25 Consolidate knowledge every N tool calls
dedup_threshold usize 8 Number of repeated reads before dedup triggers
enabled bool true Enable autonomous background behaviors
silent_preload bool true Suppress preload notifications in output
[boundary_policy] Cross-project boundary and access control policies
KeyTypeDefaultDescription
audit_cross_access bool true Log audit events when cross-project access occurs
cross_project_import bool false Allow importing knowledge from other projects
cross_project_search bool false Allow searching across project boundaries
universal_gotchas_enabled bool true Load universal (cross-project) gotchas
[cloud] Cloud feature settings
KeyTypeDefaultDescription
auto_sync bool false Push the Personal Cloud (knowledge, commands, CEP, gotchas, buddy, feedback) silently once per day at session end (Pro; toggle: `lean-ctx cloud autosync on|off`)
contribute_enabled bool false Enable contributing anonymized stats to lean-ctx cloud
[custom_aliases] Custom command aliases (array of {command, alias} entries). Note: field names are 'command' and 'alias' (not 'name')
KeyTypeDefaultDescription
alias string The alias definition to execute
command string The command pattern to match (e.g. 'deploy')
[embedding] Semantic-embedding engine settings (model selection for ctx_semantic_search)
KeyTypeDefaultDescription
dimensions integer Declared embedding width for hf: custom models (fallback only — the real width is probed from the ONNX graph at load time). Built-in models ignore this key.
model string minilm Local ONNX embedding model for ctx_semantic_search. One of: minilm (all-MiniLM-L6-v2, 384d, default), jina-code-v2 (768d, code-optimized), nomic (768d) — or any HuggingFace repo with an ONNX export via hf:org/repo[@revision]. Switching models re-indexes once on the next search.
[gain] Token-savings recap publishing (gain --publish / auto-publish)
KeyTypeDefaultDescription
auto_publish bool false Automatically (re)publish your Wrapped recap when you run `lean-ctx gain` (opt-in, off by default; throttled and sends only an aggregate payload)
auto_publish_interval_hours u64 24 Minimum hours between automatic publishes (throttle; default 24)
display_name string? Optional display name shown on your published card / leaderboard entry
leaderboard bool true When auto-publishing, also list the card on the public opt-in leaderboard
[gateway] MCP Tool-Catalog Gateway: aggregate + query-route downstream MCP servers (#210). Global-only.
KeyTypeDefaultDescription
cache_ttl_secs integer 300 Aggregated-catalog cache lifetime in seconds
call_timeout_secs integer 30 Per-operation timeout for downstream connect/list/call (seconds)
enabled bool false Enable the MCP Tool-Catalog Gateway (no-op when false)
top_n integer 5 How many tools `ctx_tools find` returns per query (clamped 1..=50)
[gateway.servers] Downstream MCP servers (array of tables: `[[gateway.servers]]`)
KeyTypeDefaultDescription
args array [] Arguments for the spawned command (stdio transport)
command string Executable to spawn (stdio transport)
enabled bool true Per-server switch (default true)
env table {} Extra environment variables for the child process (stdio transport)
headers table {} Extra request headers, e.g. Authorization (http transport)
name string Stable server id; becomes the catalog namespace (`name::tool`)
transport string stdio Transport: stdio (spawn command) or http (connect to url)
url string Streamable-HTTP endpoint (http transport)
[graph] Code-graph settings, including traversal (co-access) edges learned from sessions
KeyTypeDefaultDescription
traversal_edges bool true Learn co-access edges from real sessions (files surfaced together), surface them as decaying `co_access` graph edges, and boost recall by them. Set false for a purely static AST-only graph.
[ide_paths] Per-IDE allowed paths. Keys are agent names (cursor, codex, opencode, antigravity, etc.), values are arrays of paths to index for that agent
KeyTypeDefaultDescription
[llm] Optional LLM enhancement settings (query expansion, contradiction explanation). Deterministic fallback when disabled or unreachable.
KeyTypeDefaultDescription
api_key string API key for OpenRouter or Anthropic backends
backend enum ollama LLM backend provider
enabled bool false Enable optional LLM enhancements (query expansion, contradiction explanation)
model string llama3.2 Model name for the selected backend
timeout_secs u64 10 HTTP timeout for LLM requests
[loop_detection] Loop detection settings for preventing repeated identical tool calls
KeyTypeDefaultDescription
blocked_threshold u32 0 Repetitions before blocking. 0 = disabled
normal_threshold u32 2 Repetitions before reducing output
reduced_threshold u32 4 Repetitions before further reducing output
search_group_limit u32 10 Maximum unique searches within a loop window
tool_total_limits table {"ctx_read":100,"ctx_search":80,"ctx_semantic_search":60,"ctx_shell":50} Per-tool total call limits within a session. Keys are tool names, values are max calls
window_secs u64 300 Time window in seconds for loop detection
[lsp] LSP server binary overrides. Map language name to custom binary path
KeyTypeDefaultDescription
go string? Custom path to gopls binary
python string? Custom path to pylsp binary
rust string? Custom path to rust-analyzer binary
typescript string? Custom path to typescript-language-server binary
[memory.embeddings] Embeddings memory settings for semantic search
KeyTypeDefaultDescription
max_facts usize 2000 Maximum number of embedding facts stored
[memory.episodic] Episodic memory budgets (session episodes)
KeyTypeDefaultDescription
max_actions_per_episode usize 50 Maximum actions tracked per episode
max_episodes usize 500 Maximum number of episodes retained
summary_max_chars usize 200 Maximum characters in episode summary
[memory.gotcha] Gotcha memory settings (project-specific warnings and pitfalls)
KeyTypeDefaultDescription
default_decay_rate f32 0.03 Default decay rate for gotcha importance
max_gotchas_per_project usize 100 Maximum gotchas stored per project
retrieval_budget_per_room usize 10 Maximum gotchas retrieved per room per query
[memory.knowledge] Knowledge memory budgets (facts, patterns, gotchas)
KeyTypeDefaultDescription
contradiction_threshold f32 0.5 Confidence threshold for contradiction detection
max_facts usize 200 Maximum number of knowledge facts stored per project
max_history usize 100 Maximum history entries retained
max_patterns usize 50 Maximum number of patterns stored
recall_facts_limit usize 10 Maximum facts returned per recall query
relations_limit usize 40 Maximum number of relations returned
rooms_limit usize 25 Maximum number of rooms returned
timeline_limit usize 25 Maximum number of timeline entries returned
[memory.lifecycle] Knowledge lifecycle policy (decay, staleness, dedup)
KeyTypeDefaultDescription
decay_rate f32 0.01 Rate at which knowledge confidence decays over time
low_confidence_threshold f32 0.3 Threshold below which facts are considered low-confidence
similarity_threshold f32 0.85 Similarity threshold for deduplication
stale_days i64 30 Days after which unused facts are considered stale
[memory.procedural] Procedural memory budgets (learned patterns)
KeyTypeDefaultDescription
max_procedures usize 100 Maximum number of learned procedures stored
max_window_size usize 10 Maximum window size for pattern analysis
min_repetitions usize 3 Minimum repetitions before a pattern is stored
min_sequence_len usize 2 Minimum sequence length for procedure detection
[providers] External context providers (GitHub, GitLab, Jira, MCP bridges, etc.). Set tokens via env vars (GITHUB_TOKEN, GITLAB_TOKEN). MCP bridges connect external MCP servers as context sources.
KeyTypeDefaultDescription
auto_index bool true Auto-ingest provider results into BM25/embedding indexes
cache_ttl_secs u64 120 Default cache TTL for provider results (seconds)
enabled bool true Master switch for the provider subsystem (GitHub, GitLab, etc.)
github.api_url string GitHub API base URL (for GitHub Enterprise)
github.enabled bool true Enable/disable GitHub provider
gitlab.api_url string GitLab API base URL (for self-hosted instances)
gitlab.enabled bool true Enable/disable GitLab provider
mcp_bridges.<name>.args array [] Arguments for the MCP server command
mcp_bridges.<name>.auth_env string Environment variable name containing auth token for MCP server
mcp_bridges.<name>.command string Command to spawn a local MCP server (stdio transport)
mcp_bridges.<name>.url string HTTP/SSE URL for a remote MCP server
[proxy] Proxy upstream configuration for API routing
KeyTypeDefaultDescription
allow_insecure_http_upstream bool false Allow a non-loopback plaintext http:// upstream (trusted local network only, e.g. http://host.docker.internal:2455 when a client like Codex sits in front of the proxy). Opt-in; default false
anthropic_upstream string? Custom upstream URL for Anthropic API proxy
gemini_upstream string? Custom upstream URL for Gemini API proxy
history_mode enum cache-aware History pruning strategy. cache-aware: frozen boundaries that keep provider prompt caches valid (default). rolling: legacy moving window (max raw savings, breaks prompt caching). off: never prune
openai_upstream string? Custom upstream URL for OpenAI API proxy
[search] Hybrid search weights for ctx_semantic_search (BM25 + dense vector + SPLADE + graph proximity)
KeyTypeDefaultDescription
bm25_candidates usize 75 Number of BM25 candidates to retrieve before fusion
bm25_weight f64 1 BM25 lexical search weight in RRF fusion
dense_candidates usize 75 Number of dense candidates to retrieve before fusion
dense_weight f64 1 Dense vector search weight in RRF fusion
splade_weight f64 0.5 SPLADE expansion weight (0.0 to disable)
[secret_detection] Secret/credential detection and redaction settings
KeyTypeDefaultDescription
custom_patterns array [] Additional regex patterns to detect as secrets
enabled bool true Enable secret/credential detection in tool outputs
redact bool true Redact detected secrets from output
[sensitivity] Per-item sensitivity model with a uniform policy floor (#212)
KeyTypeDefaultDescription
action string redact How to enforce the floor: redact (mask spans) or drop (withhold item)
enabled bool false Enable the per-item sensitivity policy floor (no-op when false)
policy_floor string secret Block items at/above this level: public|internal|confidential|secret
[setup] Controls what lean-ctx injects during setup and updates. Fresh installs default to non-invasive (rules/skills off, MCP on).
KeyTypeDefaultDescription
auto_inject_rules bool? Inject agent rule files during setup/update. null=auto (inject if already present), true=always, false=never
auto_inject_skills bool? Install SKILL.md files during setup/update. null=auto (install if rules present), true=always, false=never
auto_update_mcp bool true Register lean-ctx MCP server in editor configs during setup/update
[skillify] Skillify miner: distill recurring session diary + knowledge patterns into rules
KeyTypeDefaultDescription
enabled bool true Master switch for the skillify miner (codify recurring session patterns into .cursor/rules). Only acts when explicitly invoked.
min_confidence f32 0.699999988079071 Minimum confidence for a single curated knowledge fact to be codified without repetition (0.0..=1.0).
min_recurrence u32 2 Minimum reinforcements (confirmations / repeated mentions) before a sub-threshold-confidence pattern is codified.
scope enum project Where generated rules are written: project (<repo>/.cursor/rules, git-committable) or global (~/.cursor/rules).
[summaries] AI session summaries: periodic, semantically-recallable session digests
KeyTypeDefaultDescription
enabled bool true Record periodic, semantically-recallable AI session summaries (what was done, files, decisions).
every_n_turns u32 25 Tool calls between automatic session summaries (gated by the auto-checkpoint cadence).
max_kept u32 100 Maximum session summaries kept per project (oldest pruned first).
[updates] Automatic update configuration
KeyTypeDefaultDescription
auto_update bool false Enable automatic updates (requires explicit opt-in)
check_interval_hours u64 6 How often to check for updates (hours)
notify_only bool false Only notify about updates, don't install automatically