> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cognee.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code

> Connect Claude Code to Cognee with the memory plugin or MCP tools.

# 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.

<Tip>
  For most users, the [**Cognee memory plugin**](/integrations/claude-code-integration) 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.
</Tip>

## 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](/cognee-mcp/mcp-quickstart) or [Local Setup](/cognee-mcp/mcp-local-setup))

## Plugin Setup

<Steps>
  <Step title="Install Claude Code">
    ```bash theme={null}
    npm install -g @anthropic-ai/claude-code
    ```
  </Step>

  <Step title="Install the Cognee memory plugin">
    Install from your shell before launching Claude Code, so the first `claude` session can bootstrap memory cleanly:

    ```bash theme={null}
    claude plugin marketplace add topoteretes/cognee-integrations
    claude plugin install cognee-memory@cognee
    ```
  </Step>

  <Step title="Choose local or Cloud mode">
    <Tabs>
      <Tab title="Local">
        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.

        ```bash theme={null}
        export LLM_API_KEY="sk-..."
        claude
        ```
      </Tab>

      <Tab title="Cloud or remote">
        Set both variables before launching Claude Code:

        ```bash theme={null}
        export COGNEE_BASE_URL="https://your-instance.cognee.ai"
        export COGNEE_API_KEY="ck_..."
        claude
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Confirm the connection">
    On startup, Claude Code should show a **Cognee Memory Connected** system message.
  </Step>
</Steps>

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](https://github.com/topoteretes/cognee-integrations/tree/main/integrations/claude-code) 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.

<Steps>
  <Step title="Navigate to your project">
    ```bash theme={null}
    cd /path/to/your/project
    ```
  </Step>

  <Step title="Add the Cognee MCP server">
    Choose the command that matches how you started Cognee MCP:

    <Tabs>
      <Tab title="Docker (HTTP)">
        Use this if you started Cognee MCP with Docker:

        ```bash theme={null}
        claude mcp add --transport http cognee http://localhost:8000/mcp -s project
        ```

        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
      </Tab>

      <Tab title="Local (stdio)">
        Use this if you cloned the repository and run Cognee MCP from source:

        ```bash theme={null}
        claude mcp add cognee \
          -s project \
          -e LLM_API_KEY="your-openai-key" \
          -- uv --directory /absolute/path/to/cognee-mcp run cognee-mcp
        ```

        Replace:

        * `your-openai-key` with your OpenAI API key
        * `/absolute/path/to/cognee-mcp` with the path to your local `cognee-mcp` directory
      </Tab>
    </Tabs>
  </Step>

  <Step title="Start Claude Code and approve MCP">
    ```bash theme={null}
    claude
    ```

    On first run in this project, Claude Code asks whether to approve project MCP servers. Select **Enable** or press Enter.
  </Step>

  <Step title="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"
  </Step>
</Steps>

## 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?

<Card title="Join Our Community" icon="discord" href="https://discord.gg/m63hxKsp4p">
  Get support and connect with other developers using Cognee.
</Card>
