codemem
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@codememshow memories from last session"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
codemem
Persistent memory for OpenCode and Claude Code. codemem captures what you work on across sessions, retrieves relevant context using hybrid search, and injects relevant context automatically in OpenCode.
Local-first — everything lives in SQLite on your machine
Hybrid retrieval — FTS5 BM25 lexical search + sqlite-vec semantic search, merged and re-ranked
Automatic injection — the OpenCode plugin injects context into every prompt, no manual steps
Claude Code plugin support — install from the codemem marketplace source
Built-in viewer — browse memories, sessions, and observer output in a local web UI
Peer-to-peer sync — replicate memories across machines without a central service
Quick start
Prerequisites: Node.js 24+ and npm (or pnpm)
OpenCode
Install the OpenCode plugin and MCP config:
npx -y codemem setup --opencode-onlyRestart OpenCode.
The OpenCode plugin manages backend execution automatically — no separate global install is required.
Verify:
# Works on fresh installs (no global codemem needed)
npx -y codemem stats
npx -y codemem db raw-events-statusThat's it. The plugin captures activity, builds memories, and injects context from here on.
If you want codemem available directly on your PATH for manual commands, install the CLI globally:
npm install -g codememOpenCode plugin and CLI are now split intentionally:
@codemem/opencode-plugin— OpenCode plugin packagecodemem— CLI and MCP commands
Claude Code (marketplace install)
Install codemem's Claude MCP config:
npx -y codemem setup --claude-onlyIn Claude Code, add the codemem marketplace source and install the plugin:
/plugin marketplace add kunickiaj/codemem
/plugin install codememThe Claude plugin starts MCP with the TS CLI (codemem mcp).
Claude hook ingestion is HTTP enqueue-first (POST /api/claude-hooks) and falls back to direct local DB enqueue via codemem claude-hook-ingest when the local server path is unavailable. Experimental Codex hook ingestion follows the same shared raw-event pipeline through POST /api/codex-hooks, codemem codex-hook-ingest, and a Codex-specific fallback spool.
Claude hook events share the same raw-event queue pipeline used by OpenCode. UserPromptSubmit runs
capture ingest in the background and injects memory context via Claude additionalContext using
local pack generation by default, with optional HTTP /api/pack fallback.
Codex (early beta)
Codex support is early beta — functional and dogfooded, but not yet promoted to a stable support tier. It installs through Codex's own plugin marketplace:
Add the codemem marketplace and install the plugin:
codex plugin marketplace add https://github.com/kunickiaj/codemem.git
codex plugin add codemem@codememRestart Codex.
The Codex plugin bundles its MCP config (codemem mcp) and hooks. Hooks call codemem from your PATH and fall back to npx -y codemem@<version>, so a global install is optional (installing codemem globally reduces hook latency). Validated targets are Codex CLI 0.135+ and current Desktop builds.
API-key Codex Desktop (marketplace unavailable): When plugin installation is greyed out (non-subscription / API-key Desktop), configure codemem without the plugin surface:
npx -y codemem setup --codex-onlyThis merges [mcp_servers.codemem] into ~/.codex/config.toml and writes ~/.codex/hooks.json (SessionStart, UserPromptSubmit, PostToolUse, Stop) — backing up existing files and preserving unrelated entries. Restart Codex and approve the one-time prompt to trust the codemem hooks. MCP recall works immediately. If codemem is on your PATH the hooks call it directly; otherwise they fall back to npx -y codemem. Honors CODEX_HOME; re-runnable (use --force to refresh).
Codex hook ingestion shares the same raw-event pipeline as Claude and OpenCode: HTTP enqueue-first (POST /api/codex-hooks), then codemem codex-hook-ingest direct enqueue, with a Codex-specific spool fallback. UserPromptSubmit runs capture ingest in the background and injects memory context via additionalContext; disable injection with CODEMEM_INJECT_CONTEXT=0. See docs/plugin-reference.md for details and troubleshooting.
Migrating from
opencode-mem? See docs/rename-migration.md.
Related MCP server: Cortex
How it works
Adapters hook into runtime event systems (OpenCode plugin and Claude hooks). They capture tool calls and conversation messages, flush them through an observer pipeline that produces typed memories, and surface retrieval context for future prompts.
sequenceDiagram
participant OC as OpenCode
participant PL as codemem plugin
participant VW as viewer HTTP
participant ST as MemoryStore
participant DB as SQLite
OC->>PL: tool.execute.after events
OC->>PL: experimental.chat.messages.transform
PL->>VW: POST /api/pack with shaped query
VW->>ST: build_memory_pack
ST->>DB: FTS5 BM25 lexical search
ST->>DB: sqlite vec semantic search
ST->>ST: merge rerank and section assembly
ST-->>VW: pack text
VW-->>PL: pack JSON
PL->>OC: inject codemem contextRetrieval combines two strategies: keyword search via SQLite FTS5 with BM25 scoring and semantic similarity via sqlite-vec embeddings. In the pack-building path, results from both are merged, exactly deduplicated, and re-ranked using recency and memory-kind boosts. Near-related memories stay fully rendered by default; use compact rendering or CODEMEM_PACK_COMPRESSION=ids only when you intentionally want ID-based expansion via memory_get_observations.
Injection happens automatically. The plugin builds a query from the current session context (first prompt, latest prompt, project, recently modified files), asks the long-lived local viewer to build the pack, and appends the result to the latest user message via experimental.chat.messages.transform. Before sending prompt-derived POST data, it performs a payload-free viewer/profile handshake and rejects redirects. Retryable viewer transport, version, database-target, effective identity/config-target, compression-setting, or embedding-setting mismatch failures fall back to the existing CLI path; only structured, validated request errors are terminal. Prior injected message blocks are replayed byte-for-byte on later turns so provider prompt caches can keep the stable prefix. Set CODEMEM_INJECT_SURFACE=system to use the legacy system-prompt surface. OpenCode raw-event capture streams through the viewer and falls back to direct CLI enqueue; explicit SQLite busy/locked results and command timeouts receive one idempotent retry with the same event ID, while terminal failures are reported and dropped instead of requeued. Each retrieval and current-request cache reuse is recorded through the viewer-backed local evidence ledger with bounded memory identities, machine-readable reason codes, delivery status, and safe repository-relative working-set paths; retryable ledger transport failures retain the CLI fallback. Repository-contained absolute tool paths are converted to repository-relative / paths before retrieval; outside-repository, traversing, blank, and overlong paths are omitted. Prompts, pack text, memory content, and absolute paths are not copied into the ledger, historical message reconstruction creates no new attempts, and recording failures never block injection. After a plugin restart, usable context also remains fail-open when fresh ledger-identity repair fails; fallback bytes are injected without attributing delivery to either the conflicted or failed attempt.
Memories are typed — bugfix, feature, refactor, change, discovery, decision, exploration — with structured fields like facts, concepts, files_read, and files_modified that improve retrieval relevance. Low-signal events are filtered at multiple layers before persistence.
For architecture details, see docs/architecture.md.
CLI
Group | Command | Description |
Core |
| Local operational roll-up ( |
| Database statistics | |
| Bounded local retrieval-attribution diagnostics ( | |
| Recent memories | |
| Search memories | |
| Build a context-aware memory pack | |
| Inspect retrieval and pack assembly for a manual query | |
| Mine recurring memories into reviewable context candidates | |
| Backfill semantic embeddings | |
Memory |
| Print a memory item as JSON |
| Deactivate a memory item | |
| Manually add a memory | |
| Raw pack text for prompt injection | |
| Export memories by project | |
| Import memories (idempotent) | |
Viewer |
| Launch / manage the web viewer |
Sync |
| Enable or disable peer-to-peer sync |
| Device info and peer health | |
| Advanced/legacy device pairing | |
| Run one immediate sync pass | |
| Diagnose sync configuration issues | |
| Bootstrap sync from a peer snapshot | |
Updates |
| Check the npm registry for a newer stable release ( |
Coordinator |
| Self-hosted coordinator admin (groups, devices, invites) |
Database |
| Deactivate low-signal memories ( |
| Deactivate low-signal observations | |
| Populate missing | |
| Show raw-event queue status | |
Config |
| View or update configuration |
| Interactive first-run setup | |
Plumbing |
| MCP stdio server; best-effort starts the local viewer unless |
| Local Streamable HTTP MCP server ( | |
| Claude hook event ingestion (stdin) | |
| Codex hook event ingestion (stdin, experimental) | |
| Codex prompt-time memory injection (stdin, experimental) |
Run codemem --help for the full list. show, forget, and remember still work as hidden top-level aliases. export-memories and import-memories remain visible but are deprecated — they warn on stderr and will be hidden from help and completion in a future release; use codemem memory export / codemem memory import.
Use codemem status to answer whether the local database, viewer, sync, maintenance,
semantic index, raw-event ingestion, and observer need attention. It is observational:
it does not create a missing database, repair state, inspect credentials, or contact
peers, coordinators, registries, or non-loopback hosts. Use codemem status --json
for the stable machine-readable report. codemem stats remains the inventory and
usage command; use sync status/sync doctor, maintenance status, and
db raw-events-status for subsystem detail.
codemem update check is read-only: it reports the latest validated stable release and
installation-specific guidance. Results are cached for six hours;
pass --refresh to force a registry request or --json for one stable status object.
The Viewer Health page reads the same status from /api/update-status. The OpenCode plugin
checks it after startup and shows at most one best-effort notification for each newly discovered
release. notify is the default. Explicit auto policy may run codemem update install only for
a fresh, validated npm release observed for at least 24 hours and an installation whose npm origin
can be proven. Pinned, prerelease, downgrade, repository-development, stale, Docker, and unknown
installs refuse execution. Set CODEMEM_BACKEND_UPDATE_POLICY=off to disable release checks.
Docker guidance is always rebuild-and-restart guidance, never an in-container update.
Pack rendering defaults to self-contained context. For token-constrained experiments, codemem pack <context> --compact renders an index plus top details. Near-related compression is controlled by --compression-mode off|compact|ids (or CODEMEM_PACK_COMPRESSION); MCP memory_pack exposes the same setting as compression_mode. Use ids only when the agent can follow up with memory_get_observations.
Distill recurring lessons
codemem distill finds repeated discoveries and decisions that may be worth promoting into project or user context.
codemem distill --explain # ranked candidates + evidence
codemem distill --all-projects --json # machine-readable
codemem distill --no-judge # skip the observer-model worthiness judgment
codemem distill --draft # draft an AGENTS.md rule for the top candidate and show a diff
codemem distill --draft --apply # write it after confirmationCandidate mining is deterministic, and by default an observer-model worthiness pass then drops clusters of recurring routine activity (release/CI status, review passes with no findings, context lookups) that recurrence scoring cannot distinguish from real lessons. Without a configured observer model the command falls back to unjudged output with a warning; --no-judge opts out entirely. --draft uses your configured observer model to turn the top candidate into a single AGENTS.md rule and renders a unified diff; nothing is written. --apply writes that rule into a codemem-managed ## Distilled lessons block (delimited by <!-- codemem:distilled:begin/end --> markers, so all distilled edits stay in one place) after prompting for confirmation.
MCP tools
To give the LLM direct access to memory tools (search, timeline, pack, distill candidates, remember, forget):
codemem setup --opencode-onlyThis updates your OpenCode config to install the plugin and register the MCP server. Restart OpenCode to activate.
The standalone codemem-mcp-ts binary runs the same stdio server used by codemem mcp. Viewer autostart is on by default for both invocation paths; set CODEMEM_VIEWER=0 or CODEMEM_VIEWER_AUTO=0 to disable. MCP autostart and the serve start/stop/restart lifecycle identify a running viewer through GET /api/health (service discriminator codemem-viewer), with one bounded GET /api/stats compatibility probe when an older viewer returns 404.
For local HTTP transport testing, run codemem mcp http. It listens on 127.0.0.1:38889 by default and exposes Streamable HTTP at POST /mcp; use --host, --port, and --db-path to override those values. OAuth discovery metadata and Dynamic Client Registration are available at /.well-known/oauth-authorization-server, /.well-known/oauth-protected-resource/mcp, and /register; set --public-url or CODEMEM_MCP_HTTP_PUBLIC_URL to the externally reachable /mcp URL so advertised endpoints use the public origin. /authorize redirects through a configured upstream OIDC provider before issuing public-client authorization codes, /token supports PKCE S256 exchange, and /oauth/revoke revokes access tokens. When a public URL or OIDC configuration is present, POST /mcp requires a valid bearer token; local-only HTTP mode remains unauthenticated for development and still applies loopback Host/Origin checks. Non-loopback binds are rejected unless you explicitly pass --unsafe-public or set CODEMEM_MCP_HTTP_UNSAFE_PUBLIC=1.
Configuration
Config resolution precedence for runtime commands is:
explicit
CODEMEM_CONFIGworkspace-scoped config derived from
CODEMEM_RUNTIME_ROOTorCODEMEM_WORKSPACE_IDlegacy global config at
~/.config/codemem/config.json{c}
Environment variables still override file values once a config file has been selected.
Common overrides:
Variable | Purpose |
| SQLite database path |
|
|
|
|
| Host/port the plugin-managed viewer should start, probe, and restart |
|
|
| Host/port for |
| Public |
| Upstream OIDC provider used before MCP OAuth code issuance |
| Single-user allowlist for upstream OIDC identity; at least one is required when OIDC is configured |
|
|
Viewer note:
The plugin manages one explicit viewer target per runtime. If you run multiple viewers, give each one its own DB/runtime folder instead of sharing
viewer.pidstate next to the same SQLite file.The OpenCode plugin monitors viewer liveness through
GET /api/health. When an older viewer returns404, it makes one compatibility probe to the legacy raw-event status endpoint; raw-event ingest preflight remains separate and is bounded by a 5-second timeout.
The viewer includes a grouped Settings modal (Connection, Processing, Device Sync) with shell-agnostic labels and an advanced-controls toggle for technical fields.
Settings show effective values (configured or default) and only persist changed fields on save.
The viewer HTTP service is intended for localhost-only use. It does not currently provide a general-purpose auth/session layer for safe public exposure.
Observer runtime/auth:
Runtime options:
api_httpandclaude_sidecar.api_httpdefaults togpt-5.1-codex-mini(OpenAI path) unless you setobserver_model.Anthropic direct API calls accept Anthropic model IDs/aliases. codemem maps the common Claude shorthand
claude-4.5-haikuto Anthropic's direct API aliasclaude-haiku-4-5; you can also set a pinned snapshot likeclaude-haiku-4-5-20251001explicitly.claude_sidecardefaults toclaude-4.5-haiku; if the selectedobserver_modelis unsupported by Claude CLI, codemem retries once with Claude's CLI default model.claude_sidecarcommand is configurable withclaude_command(CODEMEM_CLAUDE_COMMAND) as a JSON argv array.Config file example:
"claude_command": ["wrapper", "claude", "--"]Env var example:
CODEMEM_CLAUDE_COMMAND='["wrapper","claude","--"]'
Auth sources:
auto,env,file,command,none.observer_auth_commandmust be a JSON string array (argv), not a space-separated string.Config file example:
"observer_auth_command": ["iap-auth", "--audience", "example"]Env var example:
CODEMEM_OBSERVER_AUTH_COMMAND='["iap-auth","--audience","example"]'
Header templates support
${auth.token},${auth.type}, and${auth.source}(for exampleAuthorization: Bearer ${auth.token}).Queue cadence is configurable with
raw_events_sweeper_interval_s(seconds) in Settings/config.
Export and import
Share project knowledge with teammates or back up memories across machines.
# Export current project
codemem memory export project.json
# Import on another machine (idempotent, safe to re-run)
codemem memory import project.json --remap-project ~/workspace/myprojectSee codemem memory export --help and codemem memory import --help for full options. The legacy top-level export-memories / import-memories forms still work but emit a deprecation warning.
Sharing and devices
Share selected project memories with a teammate, or use the same Project-first model to understand your own devices. The viewer's normal workflow is Projects → Sharing → Devices → Health; open Sharing → Teams to manage ongoing Team membership and inherited Project access. Sync internals live under Advanced.
Share projects with a teammate
For ongoing collaboration:
Assign exact Projects to a Team.
Invite people to join it.
Team onboarding links Identities and devices. The invitation does not assign Projects to the Team, but a new member inherits every current and future Project assigned to it. Review the Team's Projects before sending or accepting the invitation. Use Share exact Projects to send a separate direct Project invitation to one Identity. Team sharing must already be configured, but accepting the direct invitation does not add the recipient to the Team.
For a direct share, choose Create an invitation → Share exact Projects:
Choose or enter the teammate's Identity display name.
Select the exact projects to share and review each existing-memory count.
Confirm that existing memories and future activity from those projects will share, then send the one expiring invite.
The recipient reviews and accepts the invitation, then confirms their Identity and device display names. Codemem establishes trust and Project access, then starts the first sync.
Only the reviewed canonical projects are shared—similarly named or sibling projects are not included. A memory marked Only me stays local even when its project is shared. Removing access stops future sharing; memories already copied to another device may remain there.
Add, disable, or restore devices
When an Identity adds another device, codemem shows the exact Projects it will inherit from direct shares and Team policies. Existing exclusions stay excluded. Review that list before sending the add-device invitation; acceptance links the new device to the same Identity without widening Project access.
Disabling a device's enrollment for one coordinator group revokes future delivery only for that group's Projects. The global identity device stays active in Devices and can retain access through other groups. In Advanced → Team administration, re-enable that group enrollment; the next owner reconciliation pass then restores only the Projects currently authorized through direct shares and Team policies for that group. An offline device simply waits: it keeps its access and catches up when it reconnects. A separate global identity-device revocation removes the device from the active Devices list. Neither action remotely erases copied memories.
Check devices and health
Devices is read-only. Each card shows the device's Owning Identity, whether it is available, and the Projects it receives:
Direct — the Project was shared with that Identity.
Team — the Identity receives the Project through a Team policy.
Waiting — acceptance, setup, or delivery is waiting; an offline device resumes on reconnect.
Needs attention — setup reached a terminal failure; use the displayed retry action.
Use Health for the current status. Globally revoked identity devices are omitted from the active Devices list. A device disabled only for one coordinator group remains listed; use Advanced → Team administration to review or re-enable that group enrollment. Removing access prevents future delivery, but cannot erase a copy already delivered to another device.
Advanced and compatibility
Manual pairing, actor assignment, Spaces, grants, project mappings, and coordinator administration remain available for same-person devices, existing integrations, and diagnostics. They are not required for normal teammate sharing. Existing #sync and #sync/diagnostics links remain supported as Advanced compatibility routes. See the user guide.
Advanced and legacy device pairing
Use manual pairing only for a same-person device, an existing integration, or a compatibility workflow:
codemem sync enable # generate device keys
codemem sync pair # generate pairing payload
codemem serve start # start it; use serve stop/restart for lifecycle management
codemem sync once # run one immediate sync passLegacy pairing and legacy coordinator invitations do not grant project access by themselves. For advanced access details, compatibility, and recovery, see the user guide.
For cross-network setups where peer addresses change frequently or mDNS does not cross VPN/network boundaries, codemem also supports optional coordinator-backed discovery with a self-hosted coordinator. The preferred deployment path is the built-in codemem coordinator service; see docs/coordinator-discovery.md.
Semantic recall
Embeddings are stored in sqlite-vec and written automatically when memories are created. Use codemem embed to backfill existing memories. If sqlite-vec cannot load, keyword search still works.
Alternative install methods
Local development
pnpm install
pnpm build
pnpm run codemem --helpVia npx (no install)
npx -y codemem statsPlugin for development
Start OpenCode inside the codemem repo directory — the plugin auto-loads from .opencode/plugin/.
Documentation
Architecture — data flow, retrieval, observer pipeline, design tradeoffs
Coordinator-backed discovery — self-hosted cross-network peer discovery
User guide — Projects, Sharing, Devices, Health, and Advanced operations
Coordinator deployment — advanced operator deployment and discovery
Coordinator E2E runbook — advanced coordinator validation
Plugin reference — plugin behavior, env vars, stream reliability
Migration guide — migrating from
opencode-memContributing — development setup, tests, linting, releases
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseBqualityBmaintenanceMCP server that provides cross-session persistent memory for AI coding assistants using local vector database and semantic search, enabling automatic recall of project context, issues, and tasks.991Apache 2.0
- Alicense-qualityDmaintenancePersistent memory MCP server for Claude Code that captures and recalls project context across sessions, eliminating the need to re-explain architecture and decisions daily.2441MIT
- Alicense-qualityDmaintenanceA persistent memory MCP server for Claude Code that enables long-term recall across sessions via hybrid search, code intelligence, and tools for reading/writing memory.311MIT
- Alicense-qualityDmaintenanceMCP server that captures and recalls coding session memory (failures, decisions, diffs) for AI agents, enabling cross-agent continuity and preventing repeated mistakes.114MIT
Related MCP Connectors
Persistent memory and cross-session learning for AI coding assistants (hosted remote MCP).
Cloud-hosted MCP server for durable AI memory
Hosted MCP memory: save sessions/decisions once, search from Claude, Cursor, ChatGPT. EU-hosted FTS.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/kunickiaj/codemem'
If you have feedback or need assistance with the MCP directory API, please join our Discord server