Документация

Environment Variables

Complete reference for all LEAN_CTX_* environment variables - grouped by area with types, defaults, and examples.

lean-ctx behavior can be configured via ~/.lean-ctx/config.toml or environment variables. Env vars always take precedence over the config file, making them ideal for per-session overrides, CI/CD, and containerized environments.

All variables use the LEAN_CTX_ prefix (with a few LCTX_ exceptions for safety caps). Boolean variables accept true/false, 1/0, or simply being set/unset.


Core

Fundamental settings that control data storage, caching, output protocols, and checkpointing.

Variable Type Default Description Since
LEAN_CTX_DATA_DIR path ~/.lean-ctx Base directory for all persistent data (stats, knowledge, agents, cache, sessions). All modules resolve paths through this single variable. v2.0
LEAN_CTX_CACHE_TTL number 300 Cache time-to-live in seconds. Cached file reads older than this value are automatically invalidated and re-read from disk. v2.0
LEAN_CTX_CRP_MODE string tdd Compact Response Protocol mode. Controls the format of lean-ctx's own output. tdd = test-driven-development optimized, compact = general compression, off = full verbose output. v3.0
LEAN_CTX_MINIMAL flag unset Enable minimal overhead mode. Disables auto-checkpoints, meta-strings (savings notes, stale notes, shell hints), and session/knowledge blocks in MCP instructions. Equivalent to minimal_overhead = true in config. See Minimal Overhead. v3.4.0
LEAN_CTX_NO_CHECKPOINT flag unset Disable auto-checkpoint injection without affecting other features. More targeted than LEAN_CTX_MINIMAL. v3.4.1
LEAN_CTX_CHECKPOINT_INTERVAL number 15 Number of tool calls between automatic session checkpoints. Lower values increase resilience at the cost of slightly more overhead. v2.5
LEAN_CTX_OUTPUT_DENSITY string normal Controls tool response compression (input tokens). normal = full output, terse = moderate compression (20-40% savings), ultra = maximum compression (50-70% savings). v3.1

Examples

# Use a custom data directory (e.g. for containers)
export LEAN_CTX_DATA_DIR=/data/lean-ctx

# Increase cache TTL to 10 minutes
export LEAN_CTX_CACHE_TTL=600

# Switch to compact output mode
export LEAN_CTX_CRP_MODE=compact

# Checkpoint every 10 calls for maximum resilience
export LEAN_CTX_CHECKPOINT_INTERVAL=10

# Enable maximum compression on tool responses
export LEAN_CTX_OUTPUT_DENSITY=ultra

Shell

Control the shell hook behavior, timeouts, and shell binary selection.

Variable Type Default Description Since
LEAN_CTX_DISABLED flag unset When set (any value), disables the shell hook entirely. Commands run without any lean-ctx interception or compression. v1.0
LEAN_CTX_ENABLED flag unset Explicit enable toggle. Set to 0 to disable the shell hook. Useful in scripts where you want to temporarily turn off lean-ctx. v1.0
LEAN_CTX_RAW flag unset When set, bypasses all compression for the current command. The shell output is returned verbatim. Also available as ctx_shell(raw=true). v2.0
LEAN_CTX_ACTIVE flag unset Set internally when the MCP server is running. When already set, prevents a second auto-start. Can be set manually to prevent auto-start entirely. v2.0
LEAN_CTX_SHELL_TIMEOUT_MS number 120000 Maximum time (in milliseconds) a shell command may run before being killed. Commands exceeding this timeout exit with code 124 (matching the timeout convention). Set to 0 to disable the timeout. v3.3
LEAN_CTX_SHELL path auto-detect Override which shell binary lean-ctx uses for ctx_shell and lean-ctx -c. Useful on Windows when PowerShell detection fails. v2.5

Examples

# Temporarily disable lean-ctx for a session
export LEAN_CTX_DISABLED=1

# Get raw output for a single command
LEAN_CTX_RAW=1 lean-ctx -c "cat package.json"

# Set a 5-minute shell timeout
export LEAN_CTX_SHELL_TIMEOUT_MS=300000

# Force a specific shell binary (Windows)
export LEAN_CTX_SHELL="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"

Tools & Agent

Configure tool availability, agent behavior, rules injection, and model selection.

Variable Type Default Description Since
LEAN_CTX_RULES_SCOPE string both Where lean-ctx injects its cursor rules. global = ~/.cursor/rules/ only, project = .cursor/rules/ only, both = both locations. v3.3
LEAN_CTX_DISABLED_TOOLS comma-separated none Exclude specific tools from the MCP tool list to reduce token overhead. Overrides disabled_tools in config.toml. v3.0
LEAN_CTX_AGENT_ROLE string none Role identifier for automatic agent registration in multi-agent workflows. Used by ctx_agent to identify the agent in the registry. v3.1
LEAN_CTX_TERSE_AGENT string off Bidirectional token optimization for agent output. off = disabled, lite = abbreviations + function refs, full = CEP v1 protocol with 150-token budget, ultra = maximum compression. Also accepts true/false for backward compatibility. v3.3
LEAN_CTX_QUIET flag unset Suppresses all output during lean-ctx doctor --fix and similar auto-repair operations. Useful for non-interactive environments. v3.0
LEAN_CTX_HEADLESS flag unset Start MCP server in headless mode - skips all auto-setup (rules injection, hook installation, CLAUDE.md modification, agent registry). Ideal for custom launchers and CI/CD. v3.3
LEAN_CTX_MODEL string auto Model identifier used for token/gain calculations. Affects how ctx_gain estimates savings. Alias: LCTX_MODEL. v3.1
LCTX_MODEL string auto Alias for LEAN_CTX_MODEL. If both are set, LEAN_CTX_MODEL takes precedence. v3.1
LEAN_CTX_HOOK_EXCLUDE comma-separated none Glob patterns for files that bypass the hook redirect and go straight to the native Read tool. Overrides redirect_exclude in config.toml. v2.21
LEAN_CTX_MODELS_DIR path built-in Override directory for model tokenizer definitions. Useful for custom or fine-tuned models not included in the default set. v3.0

Examples

# Inject rules only in the project directory
export LEAN_CTX_RULES_SCOPE=project

# Disable expensive tools to save tokens
export LEAN_CTX_DISABLED_TOOLS=ctx_benchmark,ctx_metrics,ctx_wrapped

# Enable full terse agent mode
export LEAN_CTX_TERSE_AGENT=full

# Start MCP in headless mode (no auto-setup)
export LEAN_CTX_HEADLESS=1

# Set model for accurate gain calculation
export LEAN_CTX_MODEL=claude-sonnet-4

Autonomy

Fine-grained control over lean-ctx's autonomous behaviors - preloading, deduplication, related file suggestions, and knowledge consolidation. All autonomy env vars override the corresponding [autonomy] section in config.toml.

Variable Type Default Description Since
LEAN_CTX_AUTONOMY bool true Master toggle for all autonomy features. When false, all auto-preload, auto-dedup, auto-related, and auto-consolidate are disabled regardless of individual settings. v3.0
LEAN_CTX_AUTO_PRELOAD bool true After ctx_read, automatically pre-cache files referenced via imports/includes. v3.0
LEAN_CTX_AUTO_DEDUP bool true Automatically deduplicate the file cache when it exceeds the dedup threshold. v3.0
LEAN_CTX_AUTO_RELATED bool true Suggest related files based on the import graph when reading a file. v3.0
LEAN_CTX_AUTO_CONSOLIDATE bool true Periodically consolidate knowledge base entries to merge duplicates and prune stale entries. v3.0
LEAN_CTX_SILENT_PRELOAD bool true Pre-cache files silently without output in tool responses. Set to false to see which files were preloaded. v3.0
LEAN_CTX_DEDUP_THRESHOLD number 8 Number of cached files that triggers automatic deduplication. v3.0
LEAN_CTX_CONSOLIDATE_EVERY_CALLS number 25 Run knowledge consolidation every N tool calls. Higher values reduce overhead but delay cleanup. v3.0
LEAN_CTX_CONSOLIDATE_COOLDOWN_SECS number 300 Minimum seconds between two consecutive consolidation runs. v3.0

Examples

# Disable all autonomy features
export LEAN_CTX_AUTONOMY=false

# Keep autonomy on but disable preloading
export LEAN_CTX_AUTO_PRELOAD=false

# Increase dedup threshold for large projects
export LEAN_CTX_DEDUP_THRESHOLD=15

# Consolidate less frequently
export LEAN_CTX_CONSOLIDATE_EVERY_CALLS=50
export LEAN_CTX_CONSOLIDATE_COOLDOWN_SECS=600

Tool Mode

Control how lean-ctx exposes its tools to the AI agent - lazy discovery, single-tool mode, or full tool listing.

Variable Type Default Description Since
LEAN_CTX_LAZY_TOOLS flag unset Enable lazy tool discovery. Tools are only registered when first invoked, reducing initial tool list overhead. v3.1
LEAN_CTX_UNIFIED flag unset Single-tool mode. All 58 tools are accessed through a single ctx entry point. Reduces token overhead from tool descriptions by up to 90%. v3.2
LEAN_CTX_FULL_TOOLS flag unset Show all tools in the MCP tool list, including those normally hidden or lazily loaded. Useful for debugging or exploration. v3.1

Examples

# Enable lazy tool discovery
export LEAN_CTX_LAZY_TOOLS=1

# Use single-tool mode for minimal token overhead
export LEAN_CTX_UNIFIED=1

# Show all tools (debugging)
export LEAN_CTX_FULL_TOOLS=1

Dashboard (Observatory)

Configure the real-time Observatory dashboard binding and project selection.

Variable Type Default Description Since
LEAN_CTX_PORT number 3117 Port for the Observatory web dashboard. v3.0
LEAN_CTX_HOST string 127.0.0.1 Bind address for the Observatory. Set to 0.0.0.0 to expose on all interfaces (e.g. Docker). v3.0
LEAN_CTX_DASHBOARD_PROJECT path auto-detect Override the project directory shown in the Observatory. Useful when running the dashboard separately from the project. v3.1

Examples

# Run Observatory on a custom port
export LEAN_CTX_PORT=8080

# Expose dashboard in Docker
export LEAN_CTX_HOST=0.0.0.0

# Override project for dashboard
export LEAN_CTX_DASHBOARD_PROJECT=/home/user/my-project

Archive Premium

The Tool Result Archive enables zero-loss compression: full tool outputs are saved to disk, and the agent retrieves them on demand via ctx_expand. These env vars override the [archive] section in config.toml.

Variable Type Default Description Since
LEAN_CTX_ARCHIVE bool false Master toggle for the Tool Result Archive. Set to 0 or false to disable completely. When enabled, tool outputs exceeding the threshold are archived to disk. v3.3
LEAN_CTX_ARCHIVE_THRESHOLD number 4096 Minimum size in characters before a tool result is archived. Outputs below this threshold are returned inline without archiving. v3.3
LEAN_CTX_ARCHIVE_TTL number 48 Time-to-live for archived entries in hours. Entries not accessed within this window are automatically cleaned up. v3.3

Examples

# Enable the archive system
export LEAN_CTX_ARCHIVE=true

# Only archive large outputs (8k+ chars)
export LEAN_CTX_ARCHIVE_THRESHOLD=8192

# Keep archives for 72 hours
export LEAN_CTX_ARCHIVE_TTL=72

# Disable archive for a session
export LEAN_CTX_ARCHIVE=0

Compaction Resilience Premium

Control how lean-ctx recovers when the IDE compacts (truncates) conversation history. These env vars override the [compaction] section in config.toml.

Variable Type Default Description Since
LEAN_CTX_COMPACTION_RESUME bool true Enable automatic context recovery after IDE compaction. When the IDE truncates conversation history, lean-ctx injects a resume block into the next tool response. Set to 0 to disable. v3.3

Examples

# Disable compaction recovery
export LEAN_CTX_COMPACTION_RESUME=0

# Keep default behavior (auto-resume after compaction)
unset LEAN_CTX_COMPACTION_RESUME

Safety Caps

These variables use the shorter LCTX_ prefix and control hard limits that prevent accidental resource exhaustion.

Variable Type Default Description Since
LCTX_MAX_READ_BYTES number 5242880 Maximum file size in bytes that ctx_read / ctx_edit will process. Files exceeding this limit are rejected. Default: 5 MB. v3.1
LCTX_MAX_SHELL_BYTES number 1048576 Maximum shell output capture size in bytes for ctx_shell. Output exceeding this limit is truncated with a [truncated] marker. Default: 1 MB. v3.1

Examples

# Allow reading files up to 10 MB
export LCTX_MAX_READ_BYTES=10485760

# Increase shell output cap to 5 MB
export LCTX_MAX_SHELL_BYTES=5242880

Quick Reference

All environment variables at a glance, sorted alphabetically.

Variable Default Section
LEAN_CTX_ACTIVEunsetShell
LEAN_CTX_AGENT_ROLEnoneTools & Agent
LEAN_CTX_ARCHIVEfalseArchive
LEAN_CTX_ARCHIVE_THRESHOLD4096Archive
LEAN_CTX_ARCHIVE_TTL48Archive
LEAN_CTX_AUTO_CONSOLIDATEtrueAutonomy
LEAN_CTX_AUTO_DEDUPtrueAutonomy
LEAN_CTX_AUTO_PRELOADtrueAutonomy
LEAN_CTX_AUTO_RELATEDtrueAutonomy
LEAN_CTX_AUTONOMYtrueAutonomy
LEAN_CTX_CACHE_TTL300Core
LEAN_CTX_CHECKPOINT_INTERVAL15Core
LEAN_CTX_COMPACTION_RESUMEtrueCompaction
LEAN_CTX_CONSOLIDATE_COOLDOWN_SECS300Autonomy
LEAN_CTX_CONSOLIDATE_EVERY_CALLS25Autonomy
LEAN_CTX_CRP_MODEtddCore
LEAN_CTX_DASHBOARD_PROJECTautoDashboard
LEAN_CTX_DATA_DIR~/.lean-ctxCore
LEAN_CTX_DEDUP_THRESHOLD8Autonomy
LEAN_CTX_DISABLEDunsetShell
LEAN_CTX_DISABLED_TOOLSnoneTools & Agent
LEAN_CTX_ENABLEDunsetShell
LEAN_CTX_FULL_TOOLSunsetTool Mode
LEAN_CTX_HEADLESSunsetTools & Agent
LEAN_CTX_HOOK_EXCLUDEnoneTools & Agent
LEAN_CTX_HOST127.0.0.1Dashboard
LEAN_CTX_LAZY_TOOLSunsetTool Mode
LEAN_CTX_MODELautoTools & Agent
LEAN_CTX_MODELS_DIRbuilt-inTools & Agent
LEAN_CTX_OUTPUT_DENSITYnormalCore
LEAN_CTX_PORT3117Dashboard
LEAN_CTX_QUIETunsetTools & Agent
LEAN_CTX_RAWunsetShell
LEAN_CTX_RULES_SCOPEbothTools & Agent
LEAN_CTX_SHELLautoShell
LEAN_CTX_SHELL_TIMEOUT_MS120000Shell
LEAN_CTX_SILENT_PRELOADtrueAutonomy
LEAN_CTX_TERSE_AGENToffTools & Agent
LEAN_CTX_UNIFIEDunsetTool Mode
LCTX_MAX_READ_BYTES5242880Safety Caps
LCTX_MAX_SHELL_BYTES1048576Safety Caps
LCTX_MODELautoTools & Agent