Memory palace for AI coding agents — index sessions, recall code context in <0.2s
Project description
Codeatrium
A memory palace for AI coding agents.
English · 日本語
Codeatrium distills past conversations into palace objects and stores them in a searchable index, giving agents long-term memory. Past decisions, implementations, and code locations can be recalled in under 0.2 seconds.
The CLI command loci (from Method of Loci) is designed to be called by the agent itself — running loci search "..." --json from within a prompt.
The architecture extends the conversational memory model from arXiv:2603.13017 for coding agents.
Note: Currently Claude Code only. Session log format (
.jsonl) and distillation (claude --print) depend on Claude Code.
Simple Interface
Agents use two core commands:
- Semantic search —
loci search "query"retrieves past conversations by semantic similarity - Reverse lookup from code —
loci context --symbol "name"recalls past conversations about a specific code symbol- tree-sitter symbol resolution (Python / TypeScript / Go) lets agents understand implementation intent before editing
How It Works
- Index — Splits agent session logs into exchanges (user utterance + agent response pairs) and indexes them with FTS5 for keyword search
- Distill — An LLM (
claude --print, defaultclaude-haiku-4-5) summarizes each exchange into a palace object:exchange_core(what was done),specific_context(concrete details),room_assignments(topic tags). tree-sitter resolves touched files to symbol level (function/class/method + file + line + signature) - Search — Cross-layer search fusing BM25 on verbatim text with HNSW on distilled embeddings via RRF
Raw conversations are not embedded — only the condensed distilled text is embedded with multilingual-e5-small (384-dim), balancing semantic search quality with embedding cost. The embedding model runs as a Unix socket server, keeping search latency under 0.2 seconds after the first load.
Installation
pipx install codeatrium
Requires Python 3.11+.
Quick Start
# Initialize in project root (also registers Claude Code hooks)
loci init
loci init now handles everything in one step — database setup, existing session detection, and Claude Code hook registration. Pass --no-hooks to skip hook registration. If init fails partway through, .codeatrium/ is cleaned up automatically so re-running is safe.
When running loci init, if past session logs are detected, you'll be prompted with:
[!IMPORTANT] When adopting this tool mid-project, a large number of exchanges may already exist. Distilling all of them will consume significant
claude --print(Haiku) tokens. We recommend starting withSkip allorDistill last 50.
- Min chars threshold — Minimum character filter for exchanges (default: 50). This controls how many exchanges become distillation candidates. Higher values exclude short conversations and reduce token usage; lower values include nearly everything.
- Handling existing exchanges — Choose how much past history to distill:
- Skip all (no past session distillation)
- Distill last 50 (recent history only)
- Distill all (everything — high token cost)
- Custom (specify a number)
- Run distillation now? — Accepts
1/2/y/n/yes/no. Choose No to defer to the next session start.
Invalid input on any prompt re-prompts instead of silently falling back to a default.
Agent Instructions
Agent instructions are injected automatically — no manual setup required:
loci init— Inserts a marker section (<!-- BEGIN CODEATRIUM -->...<!-- END CODEATRIUM -->) intoCLAUDE.mdloci prime— Dynamically injects command usage into the context window at every session start via SessionStart Hook
CLI Commands
| Command | Description |
|---|---|
loci init |
Initialize .codeatrium/ and register Claude Code hooks (--no-hooks to skip) |
loci index |
Index new session logs |
loci distill [--limit N] |
Distill undistilled exchanges via LLM |
loci search "query" --json |
Semantic search (agent-facing) |
loci context --symbol "name" --json |
Code symbol → past conversations |
loci show "<ref>" --json |
Retrieve verbatim conversation |
loci status |
Show index state |
loci server start/stop/status |
Embedding server management |
loci hook install |
Re-register hooks (normally already done by loci init) |
Automation (Claude Code Hooks)
After loci init (or loci hook install), everything runs automatically:
| Hook | Trigger | Command |
|---|---|---|
| Stop (async) | After every turn | loci index |
| SessionStart | startup / /clear / /resume / compact |
loci prime |
| SessionStart | startup / /clear / /resume / compact |
loci server start |
| SessionStart | startup / /clear / /resume / compact |
loci distill |
loci index— Runs asynchronously after every turn. Indexes only new exchanges, so it's fast even mid-sessionloci distill— Distills undistilled exchanges at session start viaclaude --print. Calls Haiku through the user's Claude Code (default:claude-haiku-4-5)loci server start— Keeps the embedding model (~500MB) resident in memory for sub-0.2s search latency
Search Output
[
{
"exchange_core": "Added connection pool with pool_size=5",
"specific_context": "pool_size=5, max_overflow=10",
"rooms": [
{ "room_type": "concept", "room_key": "db-pool", "room_label": "DB connection pooling" }
],
"symbols": [
{ "name": "create_pool", "file": "src/db.py", "line": 42, "signature": "def create_pool(...)" }
],
"verbatim_ref": "~/.claude/projects/.../session.jsonl:ply=42"
}
]
Configuration
.codeatrium/config.toml (generated by loci init):
[distill]
model = "claude-haiku-4-5-20251001" # Model for distillation (default)
batch_limit = 20 # Max distillations per hook run
[index]
min_chars = 50 # Skip exchanges shorter than this
Acknowledgments
The palace object model, room-based topic grouping, and BM25+HNSW fusion search are based on:
Structured Distillation for Personalized Agent Memory (arXiv:2603.13017)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codeatrium-0.2.0.tar.gz.
File metadata
- Download URL: codeatrium-0.2.0.tar.gz
- Upload date:
- Size: 301.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3de674e3ac27b216a8b157517e4dfc4a881d51c47a87a5fded7b20a0b9282846
|
|
| MD5 |
133719de7d5bfa096a4a0a3402ac63e3
|
|
| BLAKE2b-256 |
a2a12896da7beaff42d662656c38f76ff154fb9768e8ea01d02ee8debe07e256
|
Provenance
The following attestation bundles were made for codeatrium-0.2.0.tar.gz:
Publisher:
publish.yml on senna-lang/Codeatrium
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codeatrium-0.2.0.tar.gz -
Subject digest:
3de674e3ac27b216a8b157517e4dfc4a881d51c47a87a5fded7b20a0b9282846 - Sigstore transparency entry: 1349074505
- Sigstore integration time:
-
Permalink:
senna-lang/Codeatrium@66be3fac6cf275c8fd336a1732262eb727b741b0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/senna-lang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@66be3fac6cf275c8fd336a1732262eb727b741b0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file codeatrium-0.2.0-py3-none-any.whl.
File metadata
- Download URL: codeatrium-0.2.0-py3-none-any.whl
- Upload date:
- Size: 46.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3ca802c98aaa3a4de42e6e5b83897bb58041e67293e80cef50f20a1443dd52b
|
|
| MD5 |
bc48332bf0f305c7f99d211b5565bc3e
|
|
| BLAKE2b-256 |
9bb09d9d749db6059da27d27e8c56c938332c8f00e3f14d4d2e05cce1ffe04c6
|
Provenance
The following attestation bundles were made for codeatrium-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on senna-lang/Codeatrium
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codeatrium-0.2.0-py3-none-any.whl -
Subject digest:
f3ca802c98aaa3a4de42e6e5b83897bb58041e67293e80cef50f20a1443dd52b - Sigstore transparency entry: 1349074607
- Sigstore integration time:
-
Permalink:
senna-lang/Codeatrium@66be3fac6cf275c8fd336a1732262eb727b741b0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/senna-lang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@66be3fac6cf275c8fd336a1732262eb727b741b0 -
Trigger Event:
push
-
Statement type: