Skip to contents

Enable Claude to persist information across conversations using file-based storage.

Usage

claude_memory(memory_dir)

Arguments

memory_dir

Character. Directory where memory files are stored. Must be writable. Created if it doesn't exist.

Value

A tool specification for use with claude_new().

Details

The memory tool allows Claude to:

  • Create new memory files

  • Read existing memory files

  • Update memory file contents

  • Delete memory files

Memory persists between sessions, enabling long-running agents to build knowledge over time.

Requires: beta = beta_headers$BETA_CONTEXT_MGMT

API Reference: https://docs.claude.com/en/docs/agents-and-tools/tool-use/memory-tool

Examples

if (FALSE) { # \dontrun{
# Create memory-enabled chat
memory_dir <- tempfile("claude_memory_")
chat <- claude_new(
  tools = list(claude_memory(memory_dir)),
  beta = beta_headers$BETA_CONTEXT_MGMT
)
chat$chat("Remember that my favorite color is blue")

# New session - memory persists
chat2 <- claude_new(
  tools = list(claude_memory(memory_dir)),
  beta = beta_headers$BETA_CONTEXT_MGMT
)
chat2$chat("What is my favorite color?")
# Returns "blue" from memory

# Long-running agent example
agent_memory <- tempfile("agent_")
chat <- claude_new(
  tools = list(claude_memory(agent_memory)),
  beta = beta_headers$BETA_CONTEXT_MGMT
)
chat$chat("Track that project X started on 2024-01-15")
chat$chat("Add note: first milestone completed")
chat$chat("What's the status of project X?")
} # }