> ## Documentation Index
> Fetch the complete documentation index at: https://supermemory-capy-add-llmstxt-summary-and.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Memory Tool

> Use Claude's native memory tool with Supermemory as the backend

Claude has a native memory tool that allows it to store and retrieve information across conversations. Supermemory provides a backend implementation that maps Claude's memory commands to persistent storage.

<Info>
  This integration works with Claude's built-in `memory` tool type, introduced in the Anthropic API. It requires the `context-management` beta flag.
</Info>

## Installation

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
npm install @supermemory/tools @anthropic-ai/sdk
```

## Quick start

```typescript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import Anthropic from "@anthropic-ai/sdk"
import { createClaudeMemoryTool } from "@supermemory/tools/claude-memory"

const anthropic = new Anthropic()

const memoryTool = createClaudeMemoryTool(process.env.SUPERMEMORY_API_KEY!, {
  projectId: "my-app",
})

async function chatWithMemory(userMessage: string) {
  // Send message to Claude with memory tool
  const response = await anthropic.beta.messages.create({
    model: "claude-sonnet-4-5",
    max_tokens: 2048,
    messages: [{ role: "user", content: userMessage }],
    tools: [{ type: "memory_20250818", name: "memory" }],
    betas: ["context-management-2025-06-27"],
  })

  // Handle any memory tool calls
  const toolResults = []
  for (const block of response.content) {
    if (block.type === "tool_use" && block.name === "memory") {
      const toolResult = await memoryTool.handleCommandForToolResult(
        block.input as any,
        block.id
      )
      toolResults.push(toolResult)
    }
  }

  // Send tool results back to Claude if needed
  if (toolResults.length > 0) {
    const finalResponse = await anthropic.beta.messages.create({
      model: "claude-sonnet-4-5",
      max_tokens: 2048,
      messages: [
        { role: "user", content: userMessage },
        { role: "assistant", content: response.content },
        { role: "user", content: toolResults },
      ],
      tools: [{ type: "memory_20250818", name: "memory" }],
      betas: ["context-management-2025-06-27"],
    })

    return finalResponse
  }

  return response
}

// Example usage
const response = await chatWithMemory(
  "Remember that I prefer React with TypeScript for my projects"
)
console.log(response.content[0])
```

## Configuration

```typescript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { createClaudeMemoryTool } from "@supermemory/tools/claude-memory"

const memoryTool = createClaudeMemoryTool(process.env.SUPERMEMORY_API_KEY!, {
  // Scope memories to a project or user
  projectId: "my-app",

  // Or use container tags for more flexibility
  containerTags: ["user-123", "project-alpha"],

  // Custom memory container prefix (default: "claude_memory")
  memoryContainerTag: "my_memory_prefix",

  // Custom API endpoint
  baseUrl: "https://custom.api.com",
})
```

## How it works

Claude's memory tool uses a file-system metaphor. Supermemory maps these operations to document storage:

| Claude Command | Supermemory Action |
| - | - |
| `view` | Search/retrieve documents |
| `create` | Add new document |
| `str_replace` | Update document content |
| `insert` | Insert content at line |
| `delete` | Delete document |
| `rename` | Move document to new path |

### Memory path structure

All memory paths must start with `/memories/`:

```
/memories/preferences.txt       # User preferences
/memories/projects/react.txt    # Project-specific notes
/memories/context/current.txt   # Current context
```

<Note>
  Paths are normalized for storage: `/memories/preferences` is stored as `--memories--preferences`.
</Note>

## Commands reference

### View (read/list)

```typescript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
// List directory contents
{ command: "view", path: "/memories/" }

// Read file contents
{ command: "view", path: "/memories/preferences.txt" }

// Read specific lines
{ command: "view", path: "/memories/notes.txt", view_range: [1, 10] }
```

### Create

```typescript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  command: "create",
  path: "/memories/preferences.txt",
  file_text: "User prefers dark mode\nFavorite language: TypeScript"
}
```

### String replace

```typescript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  command: "str_replace",
  path: "/memories/preferences.txt",
  old_str: "dark mode",
  new_str: "light mode"
}
```

### Insert

```typescript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  command: "insert",
  path: "/memories/notes.txt",
  insert_line: 5,
  insert_text: "New note added here"
}
```

### Delete

```typescript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{ command: "delete", path: "/memories/old-notes.txt" }
```

### Rename

```typescript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  command: "rename",
  path: "/memories/old-name.txt",
  new_path: "/memories/new-name.txt"
}
```

## Complete example

```typescript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import Anthropic from "@anthropic-ai/sdk"
import { createClaudeMemoryTool } from "@supermemory/tools/claude-memory"

const anthropic = new Anthropic()
const memoryTool = createClaudeMemoryTool(process.env.SUPERMEMORY_API_KEY!, {
  projectId: "assistant",
})

async function runConversation() {
  const messages: Anthropic.MessageParam[] = []

  // Helper to chat with memory
  async function chat(userMessage: string) {
    messages.push({ role: "user", content: userMessage })

    let response = await anthropic.beta.messages.create({
      model: "claude-sonnet-4-5",
      max_tokens: 2048,
      messages,
      tools: [{ type: "memory_20250818", name: "memory" }],
      betas: ["context-management-2025-06-27"],
    })

    // Handle tool calls
    while (response.stop_reason === "tool_use") {
      const toolResults = []

      for (const block of response.content) {
        if (block.type === "tool_use" && block.name === "memory") {
          const result = await memoryTool.handleCommandForToolResult(
            block.input as any,
            block.id
          )
          toolResults.push(result)
        }
      }

      messages.push({ role: "assistant", content: response.content })
      messages.push({ role: "user", content: toolResults })

      response = await anthropic.beta.messages.create({
        model: "claude-sonnet-4-5",
        max_tokens: 2048,
        messages,
        tools: [{ type: "memory_20250818", name: "memory" }],
        betas: ["context-management-2025-06-27"],
      })
    }

    messages.push({ role: "assistant", content: response.content })
    return response
  }

  // Have a conversation with persistent memory
  await chat("My name is Alex and I'm a backend developer")
  await chat("I prefer Go for systems programming")
  await chat("What do you remember about me?")
}

runConversation()
```

## Environment variables

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
SUPERMEMORY_API_KEY=your_supermemory_key
ANTHROPIC_API_KEY=your_anthropic_key
```

## Comparison with other approaches

| Feature | Claude Memory Tool | OpenAI SDK Tools | AI SDK Tools |
| - | - | - | - |
| Automatic memory | ✅ Claude decides | ❌ Manual control | ❌ Manual control |
| Filesystem metaphor | ✅ Files/directories | ❌ Flat storage | ❌ Flat storage |
| Path organization | ✅ Hierarchical | ❌ Tags only | ❌ Tags only |
| Integration | Anthropic SDK only | OpenAI SDK only | Vercel AI SDK |

## Next steps

<CardGroup cols={2}>
  <Card title="AI SDK integration" icon="https://mintcdn.com/supermemory-capy-add-llmstxt-summary-and/LIMkcglt81IfjBVR/icons/hugeicons/triangle.svg?fit=max&auto=format&n=LIMkcglt81IfjBVR&q=85&s=b6c75f5c803a6762c13e97aef3def3b7" href="/integrations/ai-sdk" width="24" height="24" data-path="icons/hugeicons/triangle.svg">
    Use with Vercel AI SDK for streamlined development
  </Card>

  <Card title="OpenAI SDK" icon="https://mintcdn.com/supermemory-capy-add-llmstxt-summary-and/LIMkcglt81IfjBVR/icons/hugeicons/flash.svg?fit=max&auto=format&n=LIMkcglt81IfjBVR&q=85&s=3cb7e337be4be7f18dd98e01022d8ae4" href="/integrations/openai" width="24" height="24" data-path="icons/hugeicons/flash.svg">
    Memory tools for OpenAI function calling
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.