Skip to main content

Claude Code Integration

Claude Code is Anthropic’s command-line AI assistant. Cognee can connect to it in two ways:
  • Cognee memory plugin: recommended for Claude Code memory across sessions. The plugin captures prompts, tool traces, and assistant responses into session memory, injects relevant context on each prompt, and syncs session memory into the permanent knowledge graph at session end.
  • MCP server: use this when you want Claude Code to call Cognee MCP tools from an existing Cognee MCP server.
For most users, the Cognee memory plugin is the simpler path — it adds persistent memory with two commands and no separate MCP server to run. The MCP setup below is for connecting Cognee’s full MCP tool set.

Prerequisites

  • Node.js and npm installed
  • For plugin local mode: LLM_API_KEY
  • For plugin Cloud or remote mode: COGNEE_BASE_URL and COGNEE_API_KEY
  • For MCP mode: Cognee MCP server running (see Quickstart or Local Setup)

Plugin Setup

1

Install Claude Code

2

Install the Cognee memory plugin

Install from your shell before launching Claude Code, so the first claude session can bootstrap memory cleanly:
3

Choose local or Cloud mode

Local mode is the default. The plugin starts a local Cognee API at http://localhost:8011. Only LLM_API_KEY is required; the Cognee API key is auto-minted if absent.
4

Confirm the connection

On startup, Claude Code should show a Cognee Memory Connected system message.
The plugin hooks into Claude Code’s lifecycle: SessionStart selects mode and sets up identity, UserPromptSubmit injects dataset-scoped context, PostToolUse captures tool traces, Stop writes the assistant’s answer, PreCompact preserves memory across context resets, and SessionEnd syncs the session into the permanent graph. See the plugin README for sessions, datasets, and full configuration.

MCP Setup

Use MCP if you already run Cognee MCP and want Claude Code to call Cognee tools through the Model Context Protocol.
1

Navigate to your project

2

Add the Cognee MCP server

Choose the command that matches how you started Cognee MCP:
Use this if you started Cognee MCP with Docker:
This creates a configuration in your project’s .mcp.json file that connects to the HTTP endpoint.Options:
  • -s project: Stores configuration in the project and requires approval per project
  • Omit -s project: Stores configuration at user level
3

Start Claude Code and approve MCP

On first run in this project, Claude Code asks whether to approve project MCP servers. Select Enable or press Enter.
4

Use Cognee tools

Claude Code will use Cognee tools when relevant to your requests. You can explicitly ask:
  • “Remember this design note in Cognee”
  • “Recall authentication patterns from Cognee”
  • “Improve the project memory in Cognee”

Where MCP Configuration Lives

The MCP configuration is stored in .mcp.json in your project directory when you pass -s project, or in your user settings when you omit it. Claude Code reads this file when starting a session in that directory.

Need Help?

Join Our Community

Get support and connect with other developers using Cognee.