apps/docs/memory-api/sdks/anthropic-claude-memory.mdx
Enable Claude's native memory tool functionality with Supermemory as the persistent storage backend. Claude can automatically store and retrieve information across conversations using familiar filesystem operations.
<Card title="Supermemory tools on npm" icon="npm" href="https://www.npmjs.com/package/@supermemory/tools"> Check out the NPM page for more details </Card>npm install @supermemory/tools @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk"
import { createClaudeMemoryTool } from "@supermemory/tools/claude-memory"
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY!,
})
const memoryTool = createClaudeMemoryTool(process.env.SUPERMEMORY_API_KEY!, {
projectId: 'my-app',
})
async function chatWithMemory(userMessage: string) {
const response = await anthropic.beta.messages.create({
model: 'claude-sonnet-4-5',
max_tokens: 8096,
tools: [{ type: 'memory_20250818', name: 'memory' }],
betas: ['context-management-2025-06-27'],
messages: [{ role: 'user', content: userMessage }],
})
// Handle memory tool calls
for (const block of response.content) {
if (block.type === 'tool_use' && block.name === 'memory') {
const result = await memoryTool.handleCommandForToolResult(
block.input as MemoryCommand,
block.id
)
console.log('Memory operation result:', result)
}
}
return response
}
Claude's memory tool uses a filesystem metaphor to manage persistent information:
/memories/user-preferences)/memories/preferences are stored as --memories--preferencesimport { createClaudeMemoryTool } from "@supermemory/tools/claude-memory"
const memoryTool = createClaudeMemoryTool(
process.env.SUPERMEMORY_API_KEY!,
{
projectId: 'my-app', // Project identifier
baseUrl: 'https://api.supermemory.ai', // Optional: custom API endpoint
}
)
const memoryTool = createClaudeMemoryTool(
process.env.SUPERMEMORY_API_KEY!,
{
containerTags: ['user:alice', 'app:chat'],
}
)
Claude automatically performs these operations when managing memory:
List directory contents or read file contents:
// Claude will automatically check /memories/ directory
// This maps to searching Supermemory documents with path prefix
Store new information:
// Claude creates: /memories/user-preferences.txt
// Stored as document with customId: "--memories--user-preferences.txt"
Update existing memories using string replacement:
// Claude performs str_replace on file contents
// Updates the corresponding Supermemory document
Remove information:
// Claude deletes: /memories/old-data.txt
// Removes document from Supermemory
Reorganize memory structure:
// Claude renames: /memories/temp.txt -> /memories/final.txt
// Updates document customId in Supermemory
Here's a full example with conversation handling:
import Anthropic from "@anthropic-ai/sdk"
import { createClaudeMemoryTool, type MemoryCommand } from "@supermemory/tools/claude-memory"
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY!,
})
const memoryTool = createClaudeMemoryTool(process.env.SUPERMEMORY_API_KEY!, {
projectId: 'chat-app',
})
async function chat() {
const messages: Anthropic.MessageParam[] = []
// First message: store information
messages.push({
role: 'user',
content: 'Remember that I prefer dark mode and use TypeScript'
})
let response = await anthropic.beta.messages.create({
model: 'claude-sonnet-4-5',
max_tokens: 8096,
tools: [{ type: 'memory_20250818', name: 'memory' }],
betas: ['context-management-2025-06-27'],
messages,
})
// Process tool calls
const toolResults: Anthropic.ToolResultBlockParam[] = []
for (const block of response.content) {
if (block.type === 'tool_use' && block.name === 'memory') {
const result = await memoryTool.handleCommandForToolResult(
block.input as MemoryCommand,
block.id
)
toolResults.push(result)
}
}
// Continue conversation with tool results
if (toolResults.length > 0) {
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: 8096,
tools: [{ type: 'memory_20250818', name: 'memory' }],
betas: ['context-management-2025-06-27'],
messages,
})
}
console.log(response.content)
}
chat()
Control where Claude stores information:
// Claude automatically organizes by path
// /memories/preferences/editor.txt
// /memories/projects/current.txt
// /memories/notes/meeting-2024.txt
// Each path is normalized and stored with appropriate metadata
Handle operations gracefully:
const result = await memoryTool.handleCommandForToolResult(command, toolUseId)
if (result.is_error) {
console.error('Memory operation failed:', result.content)
// Handle error appropriately
} else {
console.log('Success:', result.content)
}
Track memory operations:
for (const block of response.content) {
if (block.type === 'tool_use' && block.name === 'memory') {
console.log('Operation:', block.input.command)
console.log('Path:', block.input.path)
const result = await memoryTool.handleCommandForToolResult(
block.input as MemoryCommand,
block.id
)
console.log('Result:', result.is_error ? 'Failed' : 'Success')
}
}
/memories/user-preferences/theme.txt is better than /mem1.txt/memories/
├── user-profile/
│ ├── name.txt
│ ├── preferences.txt
│ └── settings.txt
├── projects/
│ ├── current-task.txt
│ └── goals.txt
└── notes/
├── meeting-notes.txt
└── ideas.txt
createClaudeMemoryTool(apiKey, config)Creates a memory tool instance for Claude.
Parameters:
apiKey (string): Your Supermemory API keyconfig (optional):
projectId (string): Project identifiercontainerTags (string[]): Alternative to projectIdbaseUrl (string): Custom API endpointReturns: ClaudeMemoryTool instance
handleCommandForToolResult(command, toolUseId)Processes a memory command and returns formatted result.
Parameters:
command (MemoryCommand): The memory operation from ClaudetoolUseId (string): Tool use ID from Claude's responseReturns: Promise<MemoryToolResult> with:
type: "tool_result"tool_use_id: The tool use IDcontent: Operation result or error messageis_error: Boolean indicating success/failureClaude uses these command types internally:
| Command | Description | Example |
|---|---|---|
view | List directory or read file | /memories/ or /memories/file.txt |
create | Create new file | Create /memories/new.txt with content |
str_replace | Edit file contents | Replace "old text" with "new text" |
insert | Add content at line | Insert at line 5 |
delete | Remove file | Delete /memories/old.txt |
rename | Rename/move file | Rename old.txt to new.txt |
ANTHROPIC_API_KEY=your_anthropic_key
SUPERMEMORY_API_KEY=your_supermemory_key
The Claude Memory Tool is ideal for:
| 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 |
/) are normalized to -- for storage