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.
- Terminal
- Coding agent
--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_DIRandCODEX_HOMEpoint the cookbook at moved history folders, as they do for the agents. - An LLM key in
.env. BesidesLLM_API_KEY, anOPENAI_API_KEYor anANTHROPIC_API_KEYworks too; when several are set, the first in that order wins. With an Anthropic key, cognee runs onclaude-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.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.
[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.
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.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.
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
PROMPTinscripts/ask.pyto 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--limitonce the answers look right. - Ask from your coding agent. Have the agent run
scripts/ask.pybefore it starts a task, so it opens with what you and the other agent already did in that repo.
Clean Up
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.