Skip to main content
Add persistent memory to the Codex CLI backed by your Cognee Cloud tenant with the Cognee memory plugin — no code and no pip install. The plugin captures your prompts, tool traces, and answers into session memory, injects relevant context on every prompt, and syncs the session into your knowledge graph on session end. Sessions are disposable; your memory isn’t.

1. Enable hooks and install

The plugin depends on Codex lifecycle hooks. Enable them first, then install from the Codex marketplace:
You can enable hooks manually instead by adding a [features] section with hooks = true to ~/.codex/config.toml. If Codex prompts you to review the hooks, approve the Cognee hooks so it can call the plugin on prompt submit, tool use, stop, compaction, and session end.
On startup the status line shows cognee: <dataset> · <mode> to confirm the plugin is active, or cognee: auto (<dataset>) · <mode> while recall is auto (the default; see Choose a dataset).

2. Point it at Cognee Cloud

Write both variables once into ~/.cognee/.env, using your tenant base URL and an API key. The file is created with a commented template on the first session start, is shared with the Claude Code plugin, and its values act like shell exports — except you only set them once, and they survive closing the terminal:
Re-running the block is safe — when a key appears more than once the last value wins, so pasting again updates the credentials instead of stacking duplicates. Changes apply on the next codex launch.
When COGNEE_BASE_URL is set, the plugin runs as a pure thin HTTP client to your tenant — it does not install a local Cognee runtime. When COGNEE_BASE_URL is unset, the plugin instead bootstraps a local API at http://localhost:8011. Setting the Cloud URL and key is what routes memory to your tenant.
Keeping a local-mode LLM_API_KEY in the same file is fine: cloud still wins, because a configured URL is what selects cloud. To send one terminal to local instead, export COGNEE_BACKEND=local before launching — unset COGNEE_BASE_URL does not work, because the env file re-injects the URL at the next launch. See Which mode wins.

3. Choose a dataset

All writes go to a single dataset, selected with the COGNEE_PLUGIN_DATASET environment variable. By default both the Codex and Claude Code plugins use agent_sessions, so memory is shared across both integrations automatically. On your tenant that sharing is real rather than nominal: each plugin authenticates as its own agent sub-user, and they join one cognee-agent role holding read and write on your datasets, which the plugins then address by canonical UUID. Set COGNEE_SHARED_AGENT_MEMORY=false for separated, per-plugin memory. Set a custom dataset at launch:
COGNEE_PLUGIN_DATASET names where saves go; it does not restrict recall. Recall is auto by default: the server picks the readable dataset(s) on your tenant most likely to hold the answer, or searches every readable one when it cannot narrow the query. Set COGNEE_PLUGIN_RECALL_MODE=pinned to keep recall on the session’s dataset instead. COGNEE_PLUGIN_DATASET is read only at launch, so changing the variable mid-session does nothing. To move the running session to another dataset, ask Codex to switch datasets (the cognee-switch-datasets skill) — it syncs the current session into its dataset first, then registers a fresh session on the chosen one, restricts recall to it, and its choice beats COGNEE_PLUGIN_DATASET for the rest of the launch. The same skill pins recall to the active dataset or sets it back to auto without a new session. See Auto recall.
Data added to the same dataset outside Codex (via the SDK or the server) is visible in Codex through the plugin. Searching one dataset without switching. While recall is restricted to one dataset and a search comes back empty, Codex offers the other datasets your API key can read — read-only ones included, since a search needs no write access — as a numbered list, and runs a one-off graph-only search on the one you pick without moving the session. See Searching one dataset without switching for the full flow.

4. Pick a session (optional)

By default the session_id is derived from the Codex thread, so a new conversation starts a new one and codex resume continues the same one. Set COGNEE_SESSION_ID to pin a specific named session, or to deliberately share one live session across two terminals:

5. Verify

Quit Codex — the SessionEnd hook syncs the session into Cognee (an exit-watcher fallback covers a hard exit). Then start a fresh session and ask:
What do you know from cognee?
Answering from a clean session confirms it’s recalling from your Cloud memory. The status line should say cloud, and the conversation appears on the Sessions page; if it doesn’t, see No sessions showing. Alongside automatic capture, the plugin ships skills for explicit requests — ask for what you want and Codex picks the matching one: What reaches your tenant. Prompts, tool traces, and answers are captured automatically, with credential paths (.env, *.pem, */.ssh/*, and the rest) skipped outright, including when a shell command such as cat ~/.aws/credentials names one, and common secrets redacted before anything is sent. Text you wrap in <private>…</private> is replaced with [private] before it is stored or sent as a query, for automatic capture and explicit remember alike. COGNEE_CAPTURE=false stops automatic capture entirely while leaving recall and explicit remember working — see What gets captured. Two things about the code graph differ against a Cloud tenant. Repositories are not indexed automatically — the plugin only auto-indexes against a local server, so a private checkout is never shipped to a hosted tenant on its own initiative. Ask for it with the codebase skill and give it a git URL: your tenant clones the repo rather than reading your disk, which is also why the graph reflects your last pushed commit rather than your working tree. A local path is not an option here — the server cannot see it. See Code graph.
Memory is captured and synced from your sessions over time, and writes build the graph in the background — so a brand-new setup may recall nothing until at least one session has synced. An empty first recall is expected.
Share specific datasets with connected agents from the Connections page to grant scoped read access. A dataset you can only read still shows up as a search target in the flow above.
When the workspace balance runs out, every billable operation is refused with HTTP 402 and memory goes quiet. The status line says so rather than leaving you guessing, in three shapes:
  • credits: $0.61 · top up: https://platform.cognee.ai/billing — a dollar or less left. The link tracks the balance, so it appears before anything has actually been refused.
  • credits: $2.04 (not enough for recall) — a request was refused while the balance still read healthy. The refused operation is named only above that one-dollar threshold; below it you get the top-up link instead.
  • credits: not enough for recall · top up: … — refused with no balance to print, because the billing lookup itself failed.
Recall, session saves, /remember, and background improve runs each report themselves this way. The next billable operation that succeeds clears the note, so a top-up shows through on the following prompt. See When credits run out.

Configuration reference

Precedence: environment variables → ~/.cognee/.env → defaults. There is no config.json; older versions wrote one, and SessionStart now deletes a leftover file. The COGNEE_BACKEND / COGNEE_CODEX_BACKEND mode switch follows the same precedence. Wherever it is set, it pins that terminal’s mode regardless of where the connection variables are defined. Update the plugin with codex plugin marketplace upgrade cognee — the cognee marketplace tracks main, and updates are not automatic. See the full integration guide for the session-distillation variables; the advanced session-sync and update-notification knobs are covered in the plugin README.

Disconnect

To stop Codex from using your Cognee Cloud credit, remove the plugin and restart Codex:
To also revoke its key on the Cloud side, see Disconnect a plugin. Disconnecting keeps everything the agent stored.

Full integration guide

Manual config, hooks reference, and debugging

Claude Code

The same memory plugin for Claude Code