Skip to main content
Each agent only sees its own past sessions. After the import, one question covers what Claude Code did last month and what Codex did yesterday.

What You’ll Build

Claude Code and Codex save every session on your machine, in ~/.claude/projects and ~/.codex/sessions. The cookbook reads that history: each prompt you typed and the agent’s final answer to it. cognee remembers it all in one dataset, with each agent’s sessions tagged separately. Then it answers your question over every agent’s history together, and over each agent’s history alone. Building the memory takes one cognee.remember call per agent, and every answer is one cognee.recall call. The complete cookbook is examples/cookbooks/import_agent_sessions/.

Try It on Sample Data

The sample is four sessions from two weeks of work on a made-up web shop, acme-shop. Claude Code added an order history page and fixed double charges on checkout retries. Codex fixed a checkout bug that let two orders buy the last item in stock, and added rate limiting to the public API. You need only an LLM key, not any history of your own.
LLM_API_KEY alone is enough for OpenAI, cognee’s default LLM provider. Other providers, such as Anthropic, Gemini, Azure OpenAI, AWS Bedrock or a local model through Ollama, need a few more lines in the same .env: LLM Providers lists them for each provider. Embeddings need no key: the cookbook always embeds locally with fastembed (BAAI/bge-small-en-v1.5, downloaded once, about 70 MB), whichever LLM key you use. If you set EMBEDDING_PROVIDER in .env instead, keep it for every run, because all vectors in a dataset must come from one model.
Without --agents the cookbook always runs this demo and never reads your own history. The answer joins both agents’ work. The order history page comes from a Claude Code session, and the overselling fix comes from a Codex session. The run then prints a Claude Code only answer and a Codex only answer, each about its own agent’s sessions. The demo uses its own dataset, imported_agent_sessions_demo, so it never mixes with your history.

Run It on Your Data

  • Claude Code or Codex history on this machine. CLAUDE_CONFIG_DIR and CODEX_HOME point the cookbook at moved history folders, as they do for the agents.
  • An LLM key in .env. Besides LLM_API_KEY, an OPENAI_API_KEY or an ANTHROPIC_API_KEY works too; when several are set, the first in that order wins. With an Anthropic key, cognee runs on claude-haiku-5-5. Embeddings stay local with every key. Every imported session is sent to that key’s provider.
--check lists the agents it found, their sessions and the project folders they were started in, and reports what is missing without importing anything. --agents names whose history to import: claude, codex or both. --project takes a folder path from the --check output. Running it again adds new sessions and skips unchanged ones. The README lists every option, such as --agents, --since and --limit. Later questions don’t need a new import: uv run python examples/cookbooks/import_agent_sessions/scripts/ask.py "...".

How It Works

Step 1: Start From an Empty Memory

Source: scripts/clear.py This step forgets what an earlier run imported. It runs only with --clear, which a demo run always turns on.
cognee’s part is one call: cognee.forget(dataset="imported_agent_sessions"), which deletes the dataset and everything extracted from it. Your files in ~/.claude and ~/.codex are never touched.

Step 2: Read Each Agent’s History

Source: scripts/read_sessions.py This step reads the newest 20 sessions of each chosen agent, not your whole history; pass --limit N to change how many. --project and --since narrow it to one repo or period.
It keeps your prompts and the agent’s final answers, and drops tool calls, thinking, subagents and the instructions the harness injects. Secrets become [redacted]: text in the format of a known key or token, the password in a URL, and the value assigned to a name that says it is secret, such as DB_PASSWORD=.... It skips a session changed in the last two minutes, because that is a session still running, such as the one importing. No LLM and no cognee are used.

Step 3: Write One File per Session

Source: scripts/read_sessions.py This step saves each session as a Markdown file in sessions/<agent>/, so you can read exactly what cognee will get.
Each file holds the session’s folder, git branch, start time and title, then its turns. The folder is git-ignored. Redaction catches common key formats only, so open a few files before you import a lot.

Step 4: Remember the Sessions

Source: scripts/ingest_sessions.py This step saves every chosen agent’s sessions into one memory, so a question can see them all at once.
cognee’s part is one cognee.remember call per agent, into the dataset imported_agent_sessions, the named memory everything goes into. Each call tags its files with a node set, a tag you can later recall from alone: imported_agent_sessions:claude_code or imported_agent_sessions:codex. The tags carry the dataset’s name because, with access control off, all datasets share one graph. A resumed session’s earlier copy is forgotten first, so no session is stored twice.

Step 5: Ask Over Every Agent, Then Each

Source: scripts/ask.py This step answers your question over all chosen agents, then over each agent alone.
Each answer is one cognee.recall with HYBRID_COMPLETION, which answers from the matching session passages and the graph around them. node_name picks the node sets: every agent’s for the first answer, one agent’s for each of the others. Each answer runs in a new session, cognee’s short-term memory for one conversation, so earlier answers never leak into it.

Make It Yours

  • Change what it answers. Edit PROMPT in scripts/ask.py to get a standup of last week’s work, or a list of files touched per ticket.
  • Import one project. Pass --project <repo folder> and --since YYYY-MM-DD, then raise --limit once the answers look right.
  • Ask from your coding agent. Have the agent run scripts/ask.py before it starts a task, so it opens with what you and the other agent already did in that repo.

Clean Up

The export line matters: cognee refuses to open a dataset with a different embedding model than the one it was built with, and the cookbook builds both datasets with fastembed. If your .env sets EMBEDDING_PROVIDER, cognee uses that instead, which is what the cookbook used too. To also delete the files the cookbook wrote, remove sessions/ and sample/ in the cookbook folder.

The Claude Code and Codex Plugins

The cognee Claude Code and Codex plugins record new sessions from the moment they are installed. They don’t see this import yet. They run their own cognee server with its own database, recall from their own dataset (agent_sessions by default), and list only recorded sessions in their recap and standup.

Self-Hosted AI Companion

Build another one: a companion that knows your notes.

NodeSets

How a tag lets you recall from one part of a dataset.

Recall

The search types behind each answer.

Claude Code with Cognee Cloud

Record new Claude Code sessions as they happen.