Cache Mode (CAG)
Cache-Augmented Generation (CAG) embeds your full context directly in the system prompt and lets the provider’s prompt cache handle the rest. Subsequent queries over the same context pay a fraction of the input-token cost — up to 90% off on Google and Anthropic.Use cache mode when your context fits inside the provider’s window and you plan to ask multiple questions against it. For corpora that exceed the window, stay on default RLM mode (programmatic navigation).
CAG vs default RLM
Switch into cache mode with the
--cache flag on any query, or set cache.enabled: true in .rlmx/rlmx.yaml.
End-to-end example
Interrogate a documentation folder three times — the first query warms the cache, the next two ride it.1. Estimate the cost
Output
2. Warm the cache
Output (stderr)
3. Run cached queries
Approximate cost per query
--cache invocation hashes the context; matching content hashes hit the cached system prompt instead of re-sending it.
How it works
When--cache is enabled RLMX:
- Computes a SHA-256 content hash over sorted context items
- Builds a session ID:
{cache.session-prefix}-{hash}(or just the hash) - Writes the full context into the system prompt under a
## Context Filesblock - Sends the request with provider-specific cache headers (
cache_controlfor Anthropic, explicit cached content for Gemini, etc.) - Provider returns usage metrics including
cache_read_tokens— billed at the discount rate
storage.enabled is auto/always).
Provider support
Configuration
Cache behavior lives undercache: in .rlmx/rlmx.yaml:
See the full table in Configuration → cache.
The rlmx cache command
rlmx cache is the operator-facing entry point for CAG. It has two modes:
Full flag reference: CLI →
rlmx cache.
Practical patterns
Study session over a codebase
Warm once, then ask as many follow-ups as you want within the TTL:Cached batch interrogation
Batch mode always enables caching — it’s effectivelyrlmx cache plus a question loop. See Batch Mode for the questions-file format and cost math.
Budget-capped cached run
Set a hard spend ceiling so runaway iterations can’t overshoot cache savings:Automatic fallback to RLM
If the context inflates past the provider limit, RLMX logs a warning and silently downgrades to RLM navigation:When NOT to use cache mode
- Context is too large for the provider window (use default RLM with
storage.enabled: auto) - Questions span different contexts — each unique context pays its own warmup cost
- You only plan to ask one question — the first-query cost equals a non-cached query, so there’s no savings
See also
Batch Mode
Bulk interrogation that stacks caching with the Gemini Batch API for up to 95% savings.
CLI Reference
Every flag on
rlmx cache and --cache documented.Configuration
cache: section of rlmx.yaml in full.Provider limits
Max cacheable context size by provider.