Skip to main content
Add persistent memory to Claude Code with the Cognee memory plugin — no code and no pip install. The plugin hooks into Claude Code’s lifecycle, so it:
  • captures your prompts, tool traces, and assistant responses into session memory
  • injects relevant context on every prompt submit
  • syncs the session into your knowledge graph on session end
Sessions are disposable; your memory isn’t.

Install

Install from the Claude Code marketplace. Run these in your terminal (or type the equivalent /plugin … slash commands directly in the Claude Code chat):
On startup you’ll see a “Cognee Memory Connected” message, and the status line shows cognee: <dataset> · <mode>.

Configure your backend

Set environment variables in the shell that launches Claude Code.
Point the plugin at Cognee Cloud or a remote server by setting both:
Cognee’s LLM calls do not run through Claude Code. Your Claude Code plan pays only for your conversation with Claude. Everything Cognee does on its own — entity and relationship extraction during cognify, summarization, embeddings, and search-time completions — happens inside the Cognee backend against the LLM provider configured there, and is billed by that provider. In local mode you configure it with LLM_API_KEY; in Cloud/remote mode your tenant holds the key server-side, so no local LLM key is needed.
In local mode, the single LLM_API_KEY above covers extraction, summarization, and embeddings: Cognee defaults to openai/gpt-5-mini for the LLM and openai/text-embedding-3-large for embeddings, and embeddings reuse LLM_API_KEY when EMBEDDING_API_KEY is unset. To use another provider, set LLM_PROVIDER, LLM_MODEL, and — for Azure, Ollama, or OpenAI-compatible endpoints — LLM_ENDPOINT. Changing only the LLM leaves embeddings on OpenAI, so also set the EMBEDDING_* variables or set EMBEDDING_API_KEY to an OpenAI key so the default embeddings keep working. See LLM providers and embedding providers. You can also persist settings in ~/.cognee-plugin/claude-code/config.json:

Use it

Just use Claude Code as usual — memory is captured and recalled automatically. You can also invoke the skills explicitly: To verify the connection, open a fresh session and ask: “What do you know from cognee?”
With the plugin active, Cognee is the preferred memory: the SessionStart hook steers Claude to treat Cognee as authoritative over Claude Code’s built-in MEMORY.md. Set COGNEE_PREFER_MEMORY=false to turn the steer off.

Sessions & datasets

  • Sessions — set COGNEE_SESSION_ID before launching Claude Code to resume or share a named live session across terminals. If you do not set it, the plugin chooses a session id from its configured session strategy.
  • Datasets — all writes and recall are scoped to one dataset (agent_sessions by default). Set COGNEE_PLUGIN_DATASET to use a custom one. The Claude Code and Codex plugins share the default dataset, so memory carries across both.

How It Works

The plugin registers Claude Code lifecycle hooks: A background idle watcher persists the session cache after periods of inactivity, and a final sync on session end bridges the session into the permanent graph.

Session distillation (self-improvement)

The Cognee coding-agent plugins (Claude Code, Codex) run session distillation for you — you never call improve() by hand. A distillation pass fires on three triggers:
Overlapping triggers are safe. A per-session improve lock on the server serializes concurrent runs, and unchanged session content dedups server-side by content hash — so a repeat improve over content that hasn’t changed is a cheap no-op, not duplicated work.

Configuration

All triggers are tuned through environment variables read by the plugin. The defaults are chosen so distillation stays out of your way; you rarely need to change them.
The plugin READMEs document additional advanced knobs — timing (poll deadlines, busy-retry intervals for a held session lock), session-sync retries, and the update-notification variables (COGNEE_UPDATE_CHECK, COGNEE_UPDATE_CHECK_INTERVAL). You almost never need them — reach for the table above first.

Turning it down or off

  • Stop idle-triggered improves: set COGNEE_IDLE_DISABLED=1 before launching the agent. Session-end and per-turn improves still run.
  • Reduce mid-session improves: raise COGNEE_AUTO_IMPROVE_EVERY to a large value so the per-turn trigger effectively never fires within a session.
  • Session-end distillation always runs when the plugin is active — it’s how a finished session reaches permanent memory.

Confirming it happened

  • Cloud UI: the Self-improvement card at the top of a session on the Sessions page shows the status of the last graph enrichment and the dataset it wrote to.
  • Plugin hook log: each automatic run emits an improve_fired event you can grep for when debugging (in local SDK mode, where the plugin calls the library directly instead of the HTTP endpoint, look for auto_improve_fired instead).
  • improve-unsupported.json marker: if this file appears in the plugin’s shared state directory (24h TTL), the server rejected the improve endpoint and the plugin fell back to the legacy remember bridge for that window — a signal the server predates session-aware improve.

Debugging & Resuming Sessions

Hooks are callbacks from Claude Code, not a durable job queue: events that happen while the plugin is uninstalled, failing, or unable to reach the backend are not replayed later. When memory does not appear, check these layers first: A resumed or second terminal continues the same live session only when the session id and dataset match: set COGNEE_SESSION_ID before launching Claude Code and keep COGNEE_PLUGIN_DATASET unchanged, otherwise the resumed work lands in a new session. After changing credentials, dataset, or session id, restart Claude Code so SessionStart can run with the new state.
Hook commands run with python3, falling back to python if python3 isn’t found. If neither resolves on PATH — most commonly on Windows, where the python.org installer doesn’t always register a python3 alias — every hook fails and no memory is ever captured. Run python3 --version or python --version in the same shell that launches Claude Code to confirm one is available, or reinstall Python with “Add python.exe to PATH” checked.
For a clean handoff into long-term memory, run /cognee-memory:cognee-sync or exit Claude Code normally so SessionEnd can trigger the final graph sync. If the process is killed instead, recent session cache entries may exist, but the final session-to-graph sync may not have run yet.

Configuration Reference

Precedence: environment variables → ~/.cognee-plugin/claude-code/config.json → defaults.

Update or Remove

There’s no automatic update — reinstall to pull a new plugin version:

GitHub Repository

View source code and the full configuration reference

Codex plugin

The same memory plugin for the Codex CLI