loomem
CLAUDE.md4 starsChanged 4 days agoApache-2.0View on GitHub
Hard rules every AI assistant (Claude Code, Cowork, Copilot, Cursor, …) must follow when touching this repo. Some are enforced by CI; the rest are enforced in review. Deep rationale, complexity carve-outs and edge cases live in docs/agent-conventions.md — this file stays short on purpose, because it loads into context every session. What Loomem is. An open-core, single-user memory engine (Apache-2.0, vvooki-sys/loomem), forked from Engram. The repo is public — assume external readers and their agents. Public positioning: "the open-source…
In this repository3 other files it gives its agents.
- AGENTS.mdAGENTS.md
- docs/llms-full.txtllms.txt
- docs/llms.txtllms.txt
The file
We split this CLAUDE.md into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 46
Binary location: if a maintainer's global ~/.cargo/config.toml redirects target-dir, release binaries are not under ./target/release.
- Very specific: line 72
Dependencies: no new crate without justification (why it can't be ~50 lines in-tree) + cargo audit clean + recent maintenance.
- Distinctive: line 141
Never recreate a lost cost register or evidence file: If a frozen artifact or register is missing, report it.
- Distinctive: line 143
Thresholds are frozen per campaign: Never lower a decision threshold, a selector threshold or a denominator to make a result pass.
≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md — rules for AI code generators in the Loomem repo
Hard rules every AI assistant (Claude Code, Cowork, Copilot, Cursor, …) must follow when touching this repo. Some are enforced by CI; the rest are enforced in review. Deep rationale, complexity carve-outs and edge cases live in docs/agent-conventions.md — this file stays short on purpose, because it loads into context every session.
What Loomem is. An open-core, single-user memory engine (Apache-2.0, vvooki-sys/loomem), forked from Engram. The repo is public — assume external readers and their agents. Public positioning: "the open-source context layer for LLM agents." It is memory-only (the memory_* MCP tool set, no file layer) and single-user (no accounts, RBAC, SSO, multi-tenancy). Those two product boundaries are frozen (see § Product boundaries).
Router — read the subset that applies
- Changing Rust code → § Five hard rules + § Build & run + § Repo map + § Rust rules.
- Docs / landing / content / GEO → § Docs & site + hard rule 5 (surgical). A docs task never touches Rust.
- Dashboard (
loomem-dashboard/, React SPA) → § Build & run (dashboard bullet) + hard rule 5. A dashboard task touches no Rust beyondloomem-server/src/spa.rs. - Cutting a release → § Releases.
- Any multi-step task, or a session that writes code → § Agent workflow (worktrees, delegation, cleanup).
- Benchmarks / evaluation → § Benchmarks & evaluation.
- Always → § Five hard rules, especially live-state (rule 4), product boundaries (rule 3), secrets (rule 1).
Five hard rules (never break these)
- Secrets & personal data never get committed. No API keys, tokens, passwords, production endpoints — and no real names or private data in
entities.toml/synonyms.toml(gitignored; only*.examplevariants are tracked). Any user content that gets persisted anywhere, including derived/audit fields likeoriginal_content, must pass throughsanitizer+ the PII filter — not just the visiblecontent..gitleaks.tomlcatches some leaks; you are the first gate. See something sensitive in a diff → stop and tell the user. - The local gate must be green. For every change CI sends to the Rust jobs,
cargo fmt --check && cargo clippy --workspace -- -D warningsis byte-identical to CI and to the pre-commit hook. If it isn't green, the work isn't done. Never use--no-verify. - Product boundaries are frozen. Loomem is memory-only (the file layer was removed in loomem/005 — do not re-add file tools, parsers, or
/v1/files) and single-user (no accounts, RBAC, SSO, magic-link, transactional email, or multi-tenant "workspaces"; streams organize one person's memory, they are not tenancy). A brief asking for any of these = STOP and ask the owner (team features live in Engram). - Trust live state, not memory. Cross-conversation memory (Engram/Loomem MCP, Cowork
MEMORY.md) describes "what was true when written," not "what is now." Before relying on any file, function, flag, or default a memory names, verify it still exists in the repo. When memory andgit log/gh pr listdisagree, trust live. Likewise, docs adapt to code — never copy a value from one doc page to another; verify it againstconfig.toml/source. - Surgical and compatible changes only. Touch only what the task needs; no drive-by refactors, no "while I'm here" cleanups (report unrelated dead code, don't delete it). Match the file's existing style. And: any new field on a struct persisted to RocksDB (
Chunk,ExtractionMeta,FactType, …) must be#[serde(default)], or you break deserialization of existing databases.
Build & run
Crates: loomem-core (domain + storage), loomem-server (HTTP/MCP), loomem-cli (stdio↔HTTP MCP bridge + ops), loomem-migrate (probes/migrations). Not a crate: loomem-dashboard/ (React/Vite SPA, embedded into loomem-server by rust-embed from loomem-dashboard/dist/, see loomem-server/src/spa.rs).
loomem-coreandloomem-servercompile RocksDB (C++) and needlibclang. Light/sandboxed environments often can't build them — don't assume a cleancargo buildeverywhere. CI installslibclang-dev.- Dashboard build order: front end first, then cargo.
cd loomem-dashboard && npm ci && npm run buildwritesdist/;cargo build -p loomem-serverthen embeds it. With an emptydist/the server still compiles and/answers 404.dist/is gitignored — never commit it. The Rust gate does not cover the SPA: CI has a separate job (npm run lint,npm test,npm run build), so run those locally before pushing dashboard changes. - Fail-closed startup. With the default config the server refuses to start without the local embedding model (
embedding_provider = "local", no cloud fallback) and without an LLM key while LLM-backed subsystems are enabled.LOOMEM_ALLOW_KEYLESS=1opts into degraded keyless mode (memory_ingeststores nothing, extraction off, dreaming fails;memory_storeand search work). Expect this when running the server locally or in tests — don't "fix" it by weakening the check. - Windows:
loomem-serverbuilds and runs on Windows (LLVM forlibclang,LIBCLANG_PATH; seeINSTALL_WINDOWS.md). Release archives still cover Linux and macOS only. loomem-clipulls no RocksDB/Tantivy (just tokio/reqwest/clap) — it compiles in seconds. Use it for fast bridge/CLI iteration.- Fast feedback loop:
cargo check -p <crate>andcargo test -p loomem-core --librun in seconds. A fullcargo build --workspace(release especially) is slow — don't run it in a loop. - macOS aarch64 release gotcha: the release build SIGSEGVs rustc (LLVM SLP vectorizer, ThinLTO) without
-C no-vectorize-slp. That flag is already pinned for the Mac target in.cargo/config.toml— don't remove it. Linux/Docker/Railway are unaffected. - Binary location: if a maintainer's global
~/.cargo/config.tomlredirectstarget-dir, release binaries are not under./target/release. Check the effective target dir before hunting for a binary.
Repo map (where things live)
- Storage / domain:
loomem-core/src/storage.rs(RocksDB,Chunk),tantivy_index.rs,hybrid_search.rs,graph/,crypto/(+encrypt_backfill/) for at-rest encryption. - LLM prompts & extraction:
loomem-core/src/llm.rs,memory_extractor.rs(extraction prompt),dream.rs,consolidation.rs,advisor.rs. - LLM provider routing:
loomem-core/src/llm_provider.rs. Every chat call goes through the activellm.provider(LlmConfig::active_provider()→ResolvedProvider::chat_request/send_chat). Never hardcode a provider URL or a model name in new code — read both from config. OpenAI is not assumed: the default chat model isgpt-6-lunathrough the built-inopenaiprovider, withmax_completion_tokens/reasoning_effortcoming from the[llm.providers.openai]entry inconfig.toml(the previous defaultgpt-4.1-miniis retired by OpenAI on 2027-01-14); checkconfig.tomlfor what is live. Use a pay-per-token API for the engine and evaluation, not a personal coding subscription endpoint: those terms forbid automation. Embeddings are separate (embedding_provider, defaultlocal). - MCP surface:
loomem-server/src/mcp/—dispatcher.rs(tool dispatch, source of truth for the tool set),router.rs,handler.rs,tools.rs. Canonical handshake text:loomem-server/mcp_instructions.md. - HTTP handlers:
loomem-server/src/handlers/(search.rs,ingest.rs,admin.rs,purge.rs, …). - Config:
config.rscomposes per-module sub-configs (manifest/config.rs,access_audit/config.rs, …). Runtime config:config.toml.
Rust rules
Full tables, carve-outs, and the "aspirational vs actually enforced" breakdown are in docs/agent-conventions.md. The short version:
- Complexity (review-enforced, not CI): per function CC ≤ 10, COG ≤ 15, SLOC ≤ 100, args ≤ 6; per file SLOC ≤ 700, MI ≥ 40. Already-over files must not get worse. Before adding an
ifto a CC ≥ 10 function, stop and extract. (There is nocheck-complexity.shyet — a critic pass verifies withlizard.) - Error handling: no
.unwrap()/.expect()/panic!/todo!/unimplemented!in production paths (test/bench/example code and a finalmain()are exempt). Propagate with?and.context("…"). Domain errors →thiserror(inloomem-core); handler errors →anyhow. - Numeric conversions: no
asfor numeric casts — useu32::try_from(x).context(…)?.asonly for documented// truncation intentional: …, FFI, or same-type. - Embedding dim-guard:
embedding_dimmust match the provider (local/multilingual-e5-small = 384,openai/text-embedding-3-small = 1536). Read it from config; a mismatch with the existing index corrupts search. - Layers (non-negotiable):
[HTTP/MCP handler] → [loomem-core domain] → [storage/adapter]. Handlers don't call storage directly; storage doesn't import HTTP types;loomem-coredoesn't import axum (inject I/O traits instead). - Config: one
*Configstruct per module, declared next to its code; the rootConfigonly composes sub-configs.config.tomlis "all settings required, no hardcoded defaults" — new param goes in bothconfig.tomland the loader. - Tests: new public fn → unit test; new handler/MCP tool → integration test with a JSON fixture. No storage mocks in integration tests (use tempdir/in-memory trait impls). Deterministic only (no
sleep> 1ms, no system clock without aClocktrait). CI runscargo test --workspace --lib --bins(no integration tests); locally, run what the change's test level requires (§ Agent workflow). - Dependencies: no new crate without justification (why it can't be ~50 lines in-tree) +
cargo auditclean + recent maintenance. Pin versions centrally in[workspace.dependencies].
Docs & site
A docs/landing/content task never touches Rust (and never search.rs / fusion / retrieval). Where things live:
docs/*.md— source of truth for guide content.docs/guide/*.html— hand-maintained HTML mirrors ofdocs/*.md. There is no generator — when you change a.md, sync the matching.htmlby hand.docs/index.html— hand-written landing page.- Web-root / GEO files live under
docs/(the site root), not the repo root:docs/robots.txt,docs/sitemap.xml,docs/llms.txt,docs/llms-full.txt,docs/og-image.png, JSON-LD insidedocs/index.html,docs/assets/(banner, logo). There is noCNAMEfile in the repo. loomem-server/mcp_instructions.md— canonical MCP handshake text.
Anti-drift (this bit earns its keep): before writing any value into docs — a default, a config key name, a behavior — verify it against config.toml or the source. Never copy a value from another docs page; page-to-page copying is the root cause of drift (we have hit: backup retention, "RRF" vs weighted fusion, provider vs embedding_provider, OpenAI vs local embedding default). A user-facing claim (clients, install steps, feature list) must be synced across all surfaces at once: README.md + docs/index.html + docs/guide/*.html + docs/*.md.
Security page is dated — keep it current. The security page (docs/SECURITY.md + its mirror docs/guide/security.html, served at loomem.ai/guide/security) carries a Last updated: YYYY-MM-DD line under the H1. Any change to its security content must bump that date — in both files, to the same value (the date of the change, not a copied old one). A pure typo/markup fix that changes no security claim may leave it; when in doubt, bump. The date lives only on the security page — don't spread it to other guide pages unless asked.
Naming canon: brand is Loomem. The category label is "context layer"; "memory" is allowed as a benefit/bridge word in marketing copy — the canonical hero is H1 "One memory. Every AI tool." with the mantra "Swap the model, switch the tool — your context follows." as sub-headline. "memory engine" stays reserved for the one-line technical/GEO definition. Team tier is "Loomem T". "Engram" never appears in public-facing copy.
Tool-set caveat: Loomem exposes the memory_* set only — the dispatcher (loomem-server/src/mcp/dispatcher.rs) is the source of truth for which tools exist; don't hardcode a count in prose that can drift. There is no file layer in Loomem. loomem.ai and try.loomem.ai are marketing/trial pages, not an engine endpoint. Never "discover" a tool set against any live server and document it as Loomem features — a hosted instance may be Engram (which does expose file_*); the dispatcher is the only truth.
Commits, releases, workflow
Commits — Conventional Commits + DCO sign-off (see CONTRIBUTING.md):
feat: add temporal filter to memory_search
fix: handle empty stream id in purge handlertype: subject, imperative, ≤ 72 chars; blank line; body explains why. Sign off withgit commit -s(DCO; unsigned PRs get rebased).Fixes #123/Refs #123to close issues.- Do not add
Co-Authored-By: Claudeunless explicitly asked. - A no-op delivery is valid but must be documented (one line: "NO-OP, pre-count confirms no work, because …"). Deviating from a brief needs a one-line rationale in the body.
Releases (SemVer): in one commit, bump [workspace.package] version in Cargo.toml, add a CHANGELOG.md entry, and tag vX.Y.Z. Pushing the tag triggers release.yml, which builds the dashboard SPA and then 4 targets (x86_64/aarch64 Linux, aarch64/x86_64 macOS; no Windows archive). main should never be ahead of the latest tag — tag the release commit itself.
Workflow reality: solo repo, but every change goes through a PR on a branch — docs, chore, ci and release commits included. The protect-main ruleset blocks deletion and force-push and requires the CI gate status check, so a direct push to main is rejected (checked 2026-11-22). For a release, merge the release PR and tag the resulting commit on main. The pre-commit hook (fmt + clippy) is the real local gate for Rust — install it once with scripts/install-hooks.sh (from the main checkout or any worktree; hooks are shared, so once per clone is enough). It skips commits whose staged paths CI would not send to the Rust jobs; CI runs the jobs scripts/ci-scope.cjs selects for the diff, and CI gate fails if a selected job did not succeed. Greptile reviews every PR. Before merging, address every Greptile comment: fix it, or reply on the thread with why it does not apply. Wait for the Greptile review to finish and do not enable auto-merge, which merges on green checks without waiting for review comments. Every engine PR gets an independent critic pass before merge (see § Agent workflow); for risky engine work use the numbered-cycle discipline (multi-agent-workflow-lite). Cycle artifacts are not committed. PR + critic is mandatory for external contributions.
Memory dogfooding: Claude Code/Cowork now have a loomem MCP connector pointed at the product. Don't pollute product memory with dev-chatter — use a dedicated dev stream or skip storing ephemeral build/session notes.
Agent workflow
How AI sessions work in this repo (Claude Code first; other tools follow the same intent).
- Start from
origin/main, in your own worktree.git fetchfirst, then cut a fresh worktree and branch fromorigin/main(Claude Code: under.claude/worktrees/). Runscripts/install-hooks.shif the pre-commit hook is not installed yet. Never work in, switch branches in, or "update" a checkout you did not create — another session may be using it, and a localmaincan be far behindorigin/main. Before trusting any audit or memory about the code, confirm which commit it was made on (rule 4). - Orchestrate and delegate. For anything beyond a handful of edits, the top-level session plans, splits and verifies; specialised subagents do the work: read-only exploration (fan out over independent areas), planning per item, one implementer per PR in its own worktree, an independent critic that reviews the diff without the implementer's reasoning, and CI as the verifier (§ Spend builds and CI deliberately). Independent PRs run in parallel; two implementers never touch the same files. Delegation can be hierarchical (a coordinator per work item may delegate further). Every subagent gets a self-contained brief: goal, files, constraints, definition of done.
- Verify, don't relay. A subagent's report is a claim. Check the diff, CI and test output yourself before calling anything done.
- Greptile is part of review. A PR is ready to merge only when CI is green, the critic is positive and every Greptile comment is resolved (fixed, or answered on the thread). After pushing fixes, wait for Greptile's re-review.
- New behaviour lands behind a config flag, off by default and byte-identical to the current path, unless a measured A/B justifies a new default (no category may regress by 2 pp or more; see the benchmark rules below).
- Test in proportion to the change. The paths in the diff set the level; mixed diffs take the union, unclassified paths count as ci/infra.
scripts/ci-scope.cjsholds the path rules for CI and the hook; details and exceptions are indocs/agent-conventions.md.- presentation (
docs/, top-level*.md): no local build. - dashboard (
loomem-dashboard/):npm run lint && npm test && npm run build. - bench (
bench/longmemeval/): tests of the changed modules and their direct importers; the full harness once before the last push only when the shared money or runner path changes. - rust:
cargo check -p <crate>andcargo test -p <crate>(unit, bin and integration tests) for the changed crate and the crates that depend on it; CI runs no integration tests. Rust paths outside a crate (config.toml,.cargo/, toolchain files) need a fullcargo test --workspace. High-risk Rust (publicloomem-coreAPI, storage and RocksDB-persisted structs, search and fusion,crypto/andencrypt_backfill/, god files, hot-path refactors, dependencies, theevaluationfeature) also needs a fullcargo test --workspaceonce before opening the PR. - ci/infra (
.github/,scripts/,Dockerfile,install.sh) and unclassified paths: full CI.
- presentation (
- Spend builds and CI deliberately. Run your level once per push, not in a loop, and build release binaries only when the task needs them. A critic does not rerun the full suite: it reads the diff, runs the new and changed tests, and checks that they fail on the old code. CI is the verifier. Reproduce a CI failure locally before pushing a fix, batch fixes into one push (each push is a new CI run and Greptile review), and do not rerun CI without new evidence. Delete your own build outputs and temporary data directories as soon as you no longer need them; on a shared
target-dir(see § Build & run), never runcargo clean, which wipes every project's cache. - Clean up after yourself. After a PR merges, delete its remote and local branch and remove its worktree (
git worktree remove, thengit worktree prune). At the end of a task,git worktree listandgit branch -ashow nothing of yours. Stale branches that are already merged intoorigin/mainmay be deleted; never delete someone else's unmerged branch or worktree — list it for the owner instead (last commit date + PR state). - Owner overrides. The maintainer may keep a local, gitignored
CLAUDE.local.mdnext to this file with owner-specific permissions (e.g. merge/release autonomy, cost limits). Where present it refines this section; it never relaxes the five hard rules.
Benchmarks & evaluation
- No paid model calls without an approved budget. Dry-runs, smoke tests and failure tests run offline: a loopback stub provider, outbound traffic blocked, temporary data dirs, random ports (never the product port 3035). A paid run starts only after the owner approves a cost sheet, and only through a runner that reserves cost in a durable journal before each HTTP request and stops at the limit.
- Never recreate a lost cost register or evidence file. If a frozen artifact or register is missing, report it; a new campaign gets a new register with an explicit limit.
- Disclose the reader and judge.
gpt-4.1is no longer available, so earlier gpt-4.1 numbers are not directly comparable with new runs. Publish per-type results, prompts, config, tokens-to-reader and the exact reader/judge models; ≥ 90 % claims need two seeds. Model aliases without a dated snapshot must be recorded from each response and a run stops if the model changes. - Thresholds are frozen per campaign. Never lower a decision threshold, a selector threshold or a denominator to make a result pass; a change needs a new, versioned policy approved before the next measurement.
When in doubt — stop and ask
- Breaking up a function > 500 SLOC (architectural, not operational).
- Touching a god file (large inherited files; hottest are
handlers/search.rs,core/storage.rs,handlers/admin.rs,mcp/dispatcher.rs,server/main.rs,core/graph/mod.rs— runwc -lfor current sizes). Each modification needs aCritical file rationale:line in the commit (why it's minimal-risk: doesn't change control flow/behavior + what was verified). - Touching crypto / at-rest encryption (
loomem-core/src/crypto/,encrypt_backfill/) — a mistake here loses or leaks data. - Adding a dependency, or being unsure which layer (handler / core / storage) code belongs in.
- An existing test starts failing and you don't understand why.
- Code you don't understand that you're tempted to leave alone — don't leave it, ask.
This file is load-bearing: it shapes every agent session. Treat changes to it (and to docs/agent-conventions.md) as deliberate, not drive-by — especially for external contributors.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

