Expand description
Opt-in, content-addressed cache of pure parse derivations, shared across worktrees and data homes (GitHub #2247).
An index build parses every file: BM25 chunks, the deep analysis behind the graph’s import and type edges and the call graph, and the graph scan’s signatures. A fresh worktree of the same repository parses almost the same files again. This store keeps those parse results by what they are a function of, so a second worktree reuses the unchanged ones and parses only its edited files.
What it keeps and what it does not:
- An entry is keyed by BLAKE3 over the build identity (version, commit and the running binary), the derivation kind, its selector (language, and for chunks the repository-relative path they name) and the exact content the derivation read. Content that went through admission is hashed after admission, so a policy that changes the text changes the key.
- It never keeps a project index, a root, an absolute path, a retrieval result or a permission decision. Each root reads, admits and indexes its own files; only the pure parse of identical text is shared.
- A result produced while a language is blocklisted after a parser panic is neither stored nor served, so a regex fallback is never persisted as the parser’s output.
The store is off by default. [cache] derivations_enabled = true or
LEAN_CTX_DERIVATION_CACHE=1 turns it on; LEAN_CTX_DERIVATION_CACHE=0
turns it off. derivations_dir / LEAN_CTX_DERIVATION_CACHE_DIR name a
directory shared by several data homes (default <cache dir>/derivations).
The setting is read once per process: a running daemon picks up a change
when it restarts.
Safety: the directory must be a real directory owned by the current user and not writable by group or others, or the store stays off. It is checked when the store opens and then used by path, so a configured directory belongs under a parent only this user can write to (the default is). Entries are opened without following links and must be regular files; FIFOs, links and oversized files are refused. Writes go to a private temp file and are renamed into place. A header carries the full key and a hash of the payload; any mismatch, truncation or decode error is a miss and the entry is removed. The total size is bounded and the least recently used entries are evicted.