Are you the author? Sign in to claim
A memory layer for Claude Code
Persistent engineering memory for Claude Code.
Store decisions, constraints, failures, and compacted summaries in local SQLite, then bring the right context back into long sessions, complex refactors, and debugging loops.
Star on GitHub · Quick Start · Feature Highlights · Configuration · Tools · Development
CodeMemory is a local-first Claude Code plugin that turns per-session context into durable engineering memory. It stores conversations, summaries, decisions, constraints, failures, and fix attempts in SQLite, then injects the right context back into prompts and risky tool calls.
CodeMemory is intentionally narrow: it is not a general-purpose RAG layer. It is optimized for long Claude Code sessions, complex refactors, and multi-round debugging loops where remembering prior intent matters more than broad document search.
codememory-plugincodememory-for-claudeCodeMemory is built for three recurring pain points in coding sessions:
~/.claude/codememory.db; no external service is required.additionalContext.Edit, Write, or Bash, CodeMemory checks whether the target has failed before.task, constraint, decision, failure, fix_attempt, and summary nodes with tags, relations, and lifecycle status.
node:sqlite, which does not exist below 22.5, and the daemon will refuse to start with a version error.jq and curl available on PATHContributors: the
node:sqlitedependency is deliberate and must not be traded back for a native SQLite binding. Plugin hosts install with--ignore-scripts, which silently skips a native package's build step and leaves every daemon start dying on "Could not locate the bindings file". A built-in has no install step to skip.
Open Claude Code in any project, then run:
/plugin marketplace add harrylettering/CodeMemory
/plugin install codememory-plugin@harrylettering-codememory-marketplace
/reload-plugins
This repository now doubles as its own marketplace through .claude-plugin/marketplace.json, so you can distribute the plugin through Claude Code's standard marketplace flow without a separate catalog repository.
Because the runtime hooks execute compiled JavaScript from dist/, marketplace releases must include committed dist/*.js files in Git.
git clone https://github.com/harrylettering/CodeMemory.git
cd CodeMemory
npm install
npm run build
chmod +x hooks/scripts/*.sh
mkdir -p ~/.claude/plugins
ln -sf "$(pwd)" ~/.claude/plugins/codememory
The repository already contains .claude-plugin/plugin.json, .claude-plugin/marketplace.json, and hooks/hooks.json, so linking the repository root is enough for local development.
Restart Claude Code. On the next SessionStart, CodeMemory will initialize the SQLite database, start its per-session daemon, and begin watching the session transcript.
Once installed, CodeMemory runs mostly on its own:
SessionStart initializes the database and starts a per-session daemon.UserPromptSubmit can trigger memory-first retrieval and inject relevant context into the prompt.PreToolUse checks for prior failures related to the file, command, or symbol being touched.All configuration goes through CODEMEMORY_* environment variables resolved in src/db/config.ts. The most useful knobs:
Each model env var is configured independently. If you do not set it explicitly, each one defaults to claude-haiku-4-5-20251001.
| Variable | Default | Description |
|---|---|---|
CODEMEMORY_ENABLED | true | Global on/off switch. |
CODEMEMORY_DATABASE_PATH | ~/.claude/codememory.db | SQLite database location. |
CODEMEMORY_WORKSPACE_ROOT | daemon's cwd at start | Root used to qualify file tags across repositories. |
CODEMEMORY_DEBUG_TOOLS_ENABLED | false | Expose grep/describe/expand/lifecycle admin tools to the model. |
CODEMEMORY_COMPACTION_ENABLED | true | Enable async compaction. |
CODEMEMORY_COMPACTION_TOKEN_THRESHOLD | 30000 | Uncompacted M/L token budget that triggers compaction. |
CODEMEMORY_COMPACTION_FRESH_TAIL_COUNT | 20 | Most-recent messages protected from compaction. |
CODEMEMORY_COMPACTION_DISABLE_LLM | false | Skip claude --print and use truncation fallback. Required offline / in CI. |
CODEMEMORY_EXPANSION_MODEL | claude-haiku-4-5-20251001 | Model used by codememory_expand and codememory_expand_query. |
CODEMEMORY_QUERY_PLANNER_MODEL | claude-haiku-4-5-20251001 | Model used by the optional query planner. |
CODEMEMORY_COMPACTION_MODEL | claude-haiku-4-5-20251001 | Model used for compaction. |
CODEMEMORY_AUTO_SUPERSEDE_MODEL | claude-haiku-4-5-20251001 | Model used by the optional auto-supersede judge. |
CODEMEMORY_QUERY_PLANNER_ENABLED | false | Enable the optional LLM planner after weak fast-path retrieval. |
CODEMEMORY_AUTO_SUPERSEDE_VIA_LLM | false | Auto-detect implicit decision supersedes within a conversation. |
CODEMEMORY_EXPLORED_TARGET_WINDOW_MS | 1800000 (30 min) | Repeat exploration of the same Read/Grep/Glob target inside this window decays L → N. |
For the full environment-variable reference, see docs/CONFIGURATION.md.
| Tool | Purpose |
|---|---|
codememory_check_prior_failures | Ask whether a file, command, or symbol has failed before. |
codememory_mark_decision | Persist a meaningful technical decision as a decision node. |
codememory_mark_requirement | Persist a hard requirement or stable constraint. |
codememory_compact | Force compaction for the current conversation. |
Enable CODEMEMORY_DEBUG_TOOLS_ENABLED=true to expose:
codememory_grep, codememory_describe, codememory_expand, codememory_expand_query, codememory_memory_pending, codememory_memory_lifecycle
codememory-mark-decision, codememory-mark-task, codememory-mark-constraint, codememory-context-skill, codememory-summarization-skill
The mark skills post through hooks/scripts/codememory-mark.sh, and the daemon remains the single writer for memory_nodes.
/codememory-status, /codememory-grep, /codememory-describe, /codememory-expand, /codememory-expand-query, /codememory-watch
| Path | Purpose |
|---|---|
src/ | Core runtime: retrieval, compaction, stores, hooks runtime, and plugin activation. |
hooks/ | Claude Code hook definitions and shell entrypoints. |
commands/ | Slash-command descriptions such as /codememory-status and /codememory-watch. |
skills/ | Skills for marking decisions, tasks, and constraints from the model side. |
docs/ | User-facing configuration reference in English and Chinese. |
test/ | Automated tests for retrieval, lifecycle, failure lookup, compaction, and tools. |
benchmark/ | Latency benchmark for the lookup path. |
npm install if dependencies changed.npm run plugin:release-check.dist/*.js output together with your source changes..claude-plugin/plugin.json.npm install
npm run build
npm run build:watch
npm test
npm run test:watch
npm run benchmark
npm run benchmark:ci
Useful one-off commands:
npx vitest run test/failure-lookup.test.ts
npx vitest run -t "stitched chain"
Notes:
src/ to dist/.dist/*.js files.jq and curl.dist/.CODEMEMORY_COMPACTION_DISABLE_LLM=true..claude-plugin/plugin.json so installed users receive the new release.npm run build has been run, then restart Claude Code so hooks and dist/ are available.~/.claude/codememory-logs/session-start.log and ~/.claude/codememory-logs/daemon.log.CODEMEMORY_COMPACTION_DISABLE_LLM=true./codememory-status and review ~/.claude/codememory.db.MIT.
Run Claude Code as an MCP server so any agent can delegate coding tasks to it
Browser automation using accessibility snapshots instead of screenshots
Google's universal MCP server supporting PostgreSQL, MySQL, MongoDB, Redis, and 10+ databases
Official GitHub integration for repos, issues, PRs, and CI/CD workflows