Operations

Performance Tuning

Bound LeanCTX disk/RAM on huge monorepos and constrained CI runners: memory_profile, bm25_max_cache_mb, graph_index_max_files, LEAN_CTX_MAX_* and the slow-command log — with exact knobs and defaults.

You are: running LeanCTX on a huge monorepo, a constrained CI runner, or a low-RAM laptop, and you want to bound how much disk/RAM it uses — or find what's slow. LeanCTX is fast by default; these are the exact knobs and their defaults when you need them.

See your effective limits first

Before tuning, look at what's actually in effect. lean-ctx config show resolves config + env + defaults into one view and tags the source of each value (← config = yours, ← default = built-in). 0 means "unbounded / use the derived default".

╭─── Derived effective limits ────────────────────────────────╮
│ archive_max_disk_mb    =    500 MB                          │
│ bm25_max_cache_mb      =    512 MB                          │
│ archive_max_age_hours  =     48 h                           │
│ graph_index_max_files  =      0                             │
╰────────────────────────────────────────────────────────────╯

The memory profile — one dial for the footprint

memory_profile sets the overall disk/RAM posture; the derived limits (archive size, BM25 cache, staleness) follow from it unless you override them individually.

memory_profile = "balanced"     # balanced | performance | conservative
# or per-process, no config edit:
LEAN_CTX_MEMORY_PROFILE=conservative lean-ctx serve --daemon

Reach for conservative on small CI runners or low-RAM machines; performance trades disk for speed on a workstation.

Bounding the search index (BM25)

The BM25 full-text index is the biggest disk consumer on large repos.

bm25_max_cache_mb = 512          # cap the BM25 cache (derived from profile if unset)
extra_ignore_patterns = ["vendor/**", "*.min.js"]   # never index these
LEAN_CTX_BM25_MAX_CACHE_MB=256 lean-ctx index build

When the cap is hit, LeanCTX tells you exactly how to react (raise the cap or add ignore patterns). If an index is oversized or corrupt, reclaim it with lean-ctx cache prune — the next read rebuilds a clean one.

Bounding the code graph

graph_index_max_files = 0        # 0 = unlimited; set a cap on giant monorepos

On a very large tree, capping graph_index_max_files keeps graph builds fast and bounded; when the limit is reached, LeanCTX prints a clear truncation notice so it's never silent. To skip indexing entirely (e.g. an ephemeral CI job that only needs reads):

LEAN_CTX_NO_INDEX=1 lean-ctx <cmd>          # or LEAN_CTX_DISABLE_SEARCH_INDEX=1

Disk / RAM / staleness budgets

These cross-cutting budgets apply across caches and indexes; 0 means "use the profile-derived default":

KnobEnv overrideMeaning
max_disk_mbLEAN_CTX_MAX_DISK_MBtotal on-disk budget across caches/indexes
max_ram_percentLEAN_CTX_MAX_RAM_PERCENTRAM ceiling as % of system memory (default 5)
max_staleness_daysLEAN_CTX_MAX_STALENESS_DAYSauto-prune entries older than N days

config show warns if max_disk_mb is set lower than archive.max_disk_mb + bm25_max_cache_mb, so your sub-budgets can't quietly exceed the global cap.

Finding what's slow — slow-log

LeanCTX records commands that exceed slow_command_threshold_ms (default 5000) so you can see where wall-clock time goes:

slow_command_threshold_ms = 5000
lean-ctx slow-log list      # show recorded slow commands
lean-ctx slow-log clear     # reset the log

Pair this with lean-ctx gain --deep (cost + heatmap) and lean-ctx ghost (uncompressed-command waste) to turn "it feels slow" into a concrete list.

Keeping caches lean

lean-ctx cache stats              # size + hit rate
lean-ctx cache prune              # drop oversized/quarantined/orphaned indexes
lean-ctx cache reset --project    # wipe just this project's cache

A healthy cache has a high hit rate (each hit is a ~13-token re-read). cache prune is the safe periodic maintenance command; it never touches valid, in-budget entries.

Tuning checklist

ConstraintKnob
Low-RAM / small CI runnermemory_profile = "conservative"
Index eats too much diskbm25_max_cache_mb + extra_ignore_patterns
Giant monorepo, slow graphgraph_index_max_files = <N>
No index needed at allLEAN_CTX_NO_INDEX=1
Hard disk/RAM ceilingLEAN_CTX_MAX_DISK_MB / LEAN_CTX_MAX_RAM_PERCENT
"What's slow?"slow-log list + gain --deep
Reclaim space nowcache prune

Next step: set enforceable ceilings in Budgets & SLOs →