cavemem
CLAUDE.md678 starsChanged 5 months agoMITView on GitHub
This file is the source of truth for AI coding assistants working on this repository. Follow it before generating code, tests, or documentation. If a request conflicts with this file, pause and ask. cavemem is a cross-agent persistent memory system for coding assistants. It captures observations from editor sessions, compresses prose using the project's deterministic caveman grammar, stores entries in a local SQLite + vector index, and exposes them to agents through a Model Context Protocol (MCP) server and a…
The file
We split this CLAUDE.md into the rules it gives an agent
9 rules. About 0 are common, 0 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 19
Local by default: Default embedding provider is local (Transformers.js).
- Very specific: line 26
All database I/O goes through @cavemem/storage.
- Very specific: line 28
All user-visible strings default to the caveman intensity from settings (default full).
- Very specific: line 60
Every PR touching a package under packages/* or apps/* needs a changeset entry (pnpm changeset).
- Very specific: line 73
New IDE integration: add a module in packages/installers/src/ that implements the Installer interface (detect, install, uninstall, status) …
- Very specific: line 75
New compression rule: update packages/compress/src/lexicon.json, add at least one round-trip fixture under …
- Very specific: line 76
New embedding provider: add a module in packages/embedding/src/providers/, wire it into the createEmbedder switch in …
- Very specific: line 77
New storage migration: add a numbered SQL file in packages/storage/src/migrations/.
- Very specific: line 78
New CLI setting: add the field to SettingsSchema with a .describe(…) string.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 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
cavemem — Agent Playbook
This file is the source of truth for AI coding assistants working on this repository. Follow it before generating code, tests, or documentation. If a request conflicts with this file, pause and ask.
Project identity
cavemem is a cross-agent persistent memory system for coding assistants. It captures observations from editor sessions, compresses prose using the project's deterministic caveman grammar, stores entries in a local SQLite + vector index, and exposes them to agents through a Model Context Protocol (MCP) server and a local web viewer.
The signature property of the project is that memory is stored compressed. Every write path runs text through @cavemem/compress. Every human-facing read path runs it back through @cavemem/compress#expand. Model-facing reads may keep content compressed when the caller requests it.
Non-negotiable rules
- All persisted prose must pass through
packages/compressbefore hitting storage. Writing raw prose to SQLite is a defect. If you add a new write path, it must useMemoryStore, which enforces this. - Never compress technical tokens. Code blocks, inline code, URLs, file paths, shell commands, version numbers, dates, numeric literals, and quoted identifiers are preserved byte-for-byte. The tokenizer in
packages/compress/src/tokenize.tsis the single authority. - Round-trip tests must pass. Any change to the compressor, the lexicon, or the tokenizer requires
pnpm --filter @cavemem/compress testgreen, including the technical-token preservation suite. - Progressive disclosure in MCP.
searchandtimelinereturn compact results (IDs + snippets). Full observation bodies are only returned byget_observations(ids[]). Do not bloat the compact shapes. - Hot-path hooks are fast. Hook handlers in
packages/hooksmust complete under 150 ms p95. Summarization, embedding, and indexing are handed off to the worker. No network calls in hooks. - Privacy is enforced at the write boundary. Content inside
<private>…</private>tags is stripped. Paths matchingsettings.excludePatternsare never read. Neither appears in logs. - Local by default. Default embedding provider is local (Transformers.js). Remote providers are opt-in via settings. Do not add default network calls.
- No silent failures. Hook and worker errors are logged as structured JSON; user-visible commands surface failures with a non-zero exit code and a short message.
- No daemon on the write path. Hooks write observations synchronously through
MemoryStore.addObservation— never across a network or HTTP boundary. Hooks may detach-spawn the worker to kick off background embedding, but they must never wait on it. If the worker is down, writes still succeed; only the semantic-search side is degraded (BM25 keeps working).
Architectural rules
- Monorepo with pnpm workspaces. Dependency direction is strictly downward:
apps/*may depend onpackages/*;packages/*may depend on each other only in the orderconfig → compress → storage → { core, embedding } → hooks → installers. (coreandembeddingare siblings — both consumeconfigandstorage, neither depends on the other.) No upward or sideways imports that break this order. - All database I/O goes through
@cavemem/storage. No other package opens the DB directly. - Settings access goes through
@cavemem/config. No direct reads from~/.cavemem/settings.jsonelsewhere. - All user-visible strings default to the caveman intensity from settings (default
full). - Public package exports are listed in each package's
package.json#exports. Internal files are not imported across package boundaries.
Layout
apps/cli user-facing binary
apps/worker local HTTP daemon: read-only viewer + embedding backfill loop
apps/mcp-server stdio MCP server
packages/config settings schema, loader, defaults, settingsDocs()
packages/compress compression engine + lexicon
packages/storage SQLite + FTS5 + vector adapter
packages/core domain models, MemoryStore facade, Embedder interface
packages/embedding provider factory (local / ollama / openai / none)
packages/hooks lifecycle hook handlers + worker auto-spawn
packages/installers per-IDE integration modules
viewer Vite + React read-only UI
hooks-scripts portable shell stubs that invoke node handlers
docs architecture + user docs
evals token-savings and round-trip harnessDevelopment workflow
pnpm installonce. Node ≥ 20.pnpm devruns the CLI and worker in watch mode against.cavemem-dev/in the repo root (isolated data dir).- The four required gates before merging:
pnpm typecheckpnpm lintpnpm testpnpm build
- New features require unit tests. Any change that affects MCP contracts requires an integration test via the MCP inspector.
- Every PR touching a package under
packages/*orapps/*needs a changeset entry (pnpm changeset).
End-to-end publish test
Unit tests cover handlers, storage, and protocol contracts in isolation. They cannot catch issues that only show up in a globally-installed binary: bin-shim symlink resolution, ESM chunk shebangs, prepublishOnly staging, native better-sqlite3 resolution, dynamic-import bundling. Those failure modes have bitten this repo before — they are now guarded by a dedicated script.
bash scripts/e2e-publish.sh— covers the changeset publish path (CI default). Builds, packs (mirroring whatchangeset publishships), installs into an isolated.e2e/prefix with an isolated$HOME, drives every Claude Code hook event with a realistic payload, exercises FTS search and the MCP server, then uninstalls. Self-cleans on success. Required to pass in CI beforechangeset publishruns.bash scripts/e2e-pack-release.sh— covers thepnpm publish:releasepath (legacy bespoke flow that usesapps/cli/scripts/pack-release.mjsto writeapps/cli/release/). Run this if you changepack-release.mjsor thedependenciesblock ofapps/cli/package.json.- The 15 numbered checks in
e2e-publish.shmust stay green. If you change anything inapps/cli/,packages/installers/, the hook handler stdout/stderr contract, or the publish surface, re-run it locally before opening a PR. - Touching the tsup config, the
prepublishOnlyscript, or the bin entrypoint guards (isMainEntry()) without re-running both scripts is a defect.
Extension points
- New IDE integration: add a module in
packages/installers/src/that implements theInstallerinterface (detect,install,uninstall,status) and register it in the installer index. Update the CLIinstallcommand choices. - New MCP tool: register in
apps/mcp-server/src/server.ts, document contract indocs/mcp.md, add an inspector test fixture. - New compression rule: update
packages/compress/src/lexicon.json, add at least one round-trip fixture underpackages/compress/test/fixtures/, and re-run the benchmark inevals/. - New embedding provider: add a module in
packages/embedding/src/providers/, wire it into thecreateEmbedderswitch inpackages/embedding/src/index.ts, and extend theEmbeddingProviderenum inpackages/config/src/schema.ts. Each provider must expose{ model, dim, embed(text) }—dimmust be correct before the firstembed()call completes (warm-up probe). - New storage migration: add a numbered SQL file in
packages/storage/src/migrations/. Migrations are forward-only. - New CLI setting: add the field to
SettingsSchemawith a.describe(…)string.cavemem config showandsettingsDocs()pick it up automatically — no parallel docs to maintain.
Performance budgets
- Hook handler p95 runtime: 150 ms.
searchMCP call p95: 50 ms for up to 50k observations.- Compression throughput: ≥ 5 MB/s on one core.
- Worker cold start: ≤ 500 ms on Node, ≤ 100 ms on Bun.
Release policy
- Versioning via changesets. Releases are normally cut by GitHub Actions (
.github/workflows/release.yml) on merge tomainwhen a release changeset exists. Local publishing from a laptop is permitted as a fallback when CI publishing is unavailable (e.g. missing/expiredNPM_TOKEN); usepnpm --filter cavemem publish:releasefrommainafternpm login. - Conventional Commits for commit messages. PRs require passing CI and one review.
Authorship voice
Code comments are minimal and explain why, not what. Keep naming explicit. Prefer pure functions. Avoid adding dependencies when the standard library or an existing package covers the need.
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.

