Documentation Index
Fetch the complete documentation index at: https://docs.claude-mem.ai/llms.txt
Use this file to discover all available pages before exploring further.
LiteLLM Gateway
claude-mem can route its background memory agent through a LiteLLM proxy. This lets teams keep claude-mem’s Claude Agent SDK workflow while using LiteLLM for model routing, centralized credentials, usage tracking, budgets, audit logs, and provider failover. The important detail: claude-mem does not call LiteLLM with the OpenAI client directly. claude-mem still uses the Claude Agent SDK, and the SDK sends Anthropic-format requests to LiteLLM. LiteLLM then translates those requests to the upstream model provider you configured.When to Use This
Use LiteLLM gateway mode when you want:- A single organization-level LLM gateway for claude-mem traffic
- Provider routing without changing claude-mem source code
- Centralized API keys instead of storing provider keys in each developer’s claude-mem settings
- LiteLLM budgets, rate limits, logging, fallback routing, or virtual keys
- A non-Anthropic upstream model while preserving the Claude Agent SDK execution path used by claude-mem
Architecture
One Agent Path
The LiteLLM integration is intentionally small. There is no custom LiteLLM provider, no Python handler, and no OpenAI-compatible server embedded in claude-mem. At runtime:- The installer or user writes gateway settings to
~/.claude-mem/.env. ~/.claude-mem/settings.jsonkeepsCLAUDE_MEM_PROVIDERset toclaude.- The worker starts the Claude Agent SDK with an isolated environment.
- The SDK reads
ANTHROPIC_BASE_URLandANTHROPIC_AUTH_TOKEN. - LiteLLM receives the SDK’s Anthropic-format request.
- LiteLLM maps the request to the upstream provider and model configured in LiteLLM.
- The SDK response is parsed by the normal claude-mem observation pipeline.
| Layer | Responsibility |
|---|---|
src/npx-cli/commands/install.ts | Prompts for “LiteLLM or custom gateway”, stores the gateway URL/token, and allows custom gateway model names |
src/shared/EnvManager.ts | Stores credentials in ~/.claude-mem/.env, blocks shell-leaked auth vars, and injects only explicit claude-mem credentials |
src/services/worker/ClaudeProvider.ts | Starts the Claude Agent SDK for observation extraction with the isolated environment |
src/services/worker/knowledge/KnowledgeAgent.ts | Uses the same isolated SDK path for knowledge corpus Q&A |
Why CLAUDE_MEM_PROVIDER Stays claude
LiteLLM is a gateway for the Claude Agent SDK path, not a fourth claude-mem provider.
claude matters because the worker should continue to use ClaudeProvider, not the native Gemini or OpenRouter REST providers. The gateway URL changes where the SDK sends model traffic; it does not change how claude-mem manages memory sessions.
Configure LiteLLM
LiteLLM must expose an Anthropic-compatible endpoint for Claude Code / Claude Agent SDK traffic. Anthropic’s gateway guidance recommends the unified LiteLLM endpoint as the normal setup:~/.claude-mem/.env, not your shell, so the background worker uses it consistently across restarts.
Minimal LiteLLM Example
Create a LiteLLM config that defines the model name claude-mem will request:claude-haiku-4-5-20251001, LiteLLM accepts that model alias, and LiteLLM forwards the request to openai/gpt-4o-mini.
The alias in
model_name must match CLAUDE_MEM_MODEL, or CLAUDE_MEM_MODEL must be changed to match your LiteLLM alias. claude-mem does not translate model names.Configure claude-mem
Option 1: Installer
Run the installer:Claude Agent SDKAPI key or gatewayLiteLLM or custom gateway- Your LiteLLM URL, for example
http://127.0.0.1:4000 - Your LiteLLM key/token if the proxy requires one
- The model alias LiteLLM should receive
~/.claude-mem/settings.json and gateway credentials in ~/.claude-mem/.env.
Option 2: Manual Files
Edit~/.claude-mem/settings.json:
~/.claude-mem/.env:
ANTHROPIC_AUTH_TOKEN.
Restart the worker after manual edits:
Environment Isolation
claude-mem deliberately does not trust whatever Anthropic credentials happen to be exported in your shell or project.env file.
The worker blocks inherited ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, and stale CLAUDE_CODE_OAUTH_TOKEN values. It then re-injects only the credentials stored in ~/.claude-mem/.env.
This avoids two common failure modes:
- A project-level
ANTHROPIC_API_KEYsilently bypasses LiteLLM and bills the public Anthropic API. - An expired Claude Code OAuth token overrides a configured gateway token and causes confusing auth failures.
ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, or ANTHROPIC_API_KEY is present in ~/.claude-mem/.env, the worker treats that as explicit gateway/API configuration and skips Claude OAuth lookup. This prevents a configured gateway from falling back to api.anthropic.com.
Model Names
CLAUDE_MEM_MODEL is passed through to the Claude Agent SDK. In gateway mode, claude-mem allows any non-empty model string because the valid model list is owned by LiteLLM.
Recommended pattern:
Request Flow
When a Claude Code session produces transcript events, claude-mem’s worker queues them for observation extraction. In gateway mode the extraction flow is:- The worker loads pending messages for a memory session.
ClaudeProviderbuilds the observation prompt and selected model.buildIsolatedEnvWithFreshOAuth()loads~/.claude-mem/.env.- The SDK subprocess starts with
ANTHROPIC_BASE_URLpointing at LiteLLM. - LiteLLM receives the Anthropic-format request.
- LiteLLM routes to the configured upstream model.
- The SDK streams the assistant response back to the worker.
- claude-mem parses observations, stores them in SQLite, and syncs searchable embeddings.
What LiteLLM Does and Does Not Replace
LiteLLM replaces:- Upstream model selection
- Provider credentials
- Gateway-level budgets and rate limits
- Gateway-level logging and auditing
- Optional routing/fallback policies inside LiteLLM
- claude-mem’s worker process
- The Claude Agent SDK subprocess
- claude-mem’s observation XML format
- SQLite storage
- Chroma/vector sync
- Hook installation
- Session resume handling inside claude-mem
Verification
Check claude-mem’s worker logs:CLAUDE_MEM_PROVIDERisclaudeCLAUDE_MEM_CLAUDE_AUTH_METHODisgatewayANTHROPIC_BASE_URLis in~/.claude-mem/.env- The worker was restarted after manual edits
- The LiteLLM URL does not include an extra
/v1suffix for the unified Anthropic endpoint
Troubleshooting
LiteLLM returns “model not found”
The model name sent by claude-mem does not match a LiteLLMmodel_name. Make CLAUDE_MEM_MODEL and the LiteLLM alias match exactly.
claude-mem still uses Anthropic directly
Check~/.claude-mem/.env. Gateway settings must be stored there. Shell exports are not the reliable configuration source for the worker.
Also make sure ANTHROPIC_BASE_URL is present. A token alone authenticates a gateway, but the base URL is what redirects traffic away from the default Anthropic endpoint.
Authentication fails
If LiteLLM uses a master key or virtual key, store it asANTHROPIC_AUTH_TOKEN in ~/.claude-mem/.env. The Claude Agent SDK sends this value as gateway authorization.
If you previously configured a direct Anthropic API key, remove ANTHROPIC_API_KEY from ~/.claude-mem/.env for gateway mode unless your gateway explicitly expects that variable.

