Back Claude's memory tool with checks on every write

4 min read · For developers building on the Claude API, the Agent SDK or Claude Code

TL;DR: Claude's memory tool (memory_20250818) is client-side: Claude asks to read or write files under /memories, and your code does it. That makes the handler a security boundary. ThumbGate ships one: paths cannot leave /memories, secrets are redacted before anything is written, sizes are capped, and your thumbs-down rules appear read-only at /memories/thumbgate-rules.md. Copy the loop below, or run npx thumbgate init --memory-tool for Claude Code.

Why the handler matters

Anthropic's memory tool docs name the risks you own when you implement it: path traversal out of the memory folder, sensitive data written into memory, and files that grow without bound. A memory file outlives the conversation. An API key Claude read in a tool result and then wrote into a note stays on disk, and comes back into every later session that views it.

ThumbGate's handler checks each command before it touches disk:

Copy and paste: Messages API

npm install thumbgate @anthropic-ai/sdk, set ANTHROPIC_API_KEY, then:

const Anthropic = require('@anthropic-ai/sdk');
const { createMemoryTool } = require('thumbgate/adapters/claude-agent-sdk/memory-tool.js');

const memory = createMemoryTool({ root: './agent-memory' });
const client = new Anthropic();
const messages = [{ role: 'user', content: 'Pick up where we left off on the release checklist.' }];

async function main() {
  for (;;) {
    const res = await client.messages.create({ model: 'claude-opus-5-5', max_tokens: 4096, tools: [memory.definition], messages });
    messages.push({ role: 'assistant', content: res.content });
    const uses = res.content.filter((b) => b.type === 'tool_use' && b.name === 'memory');
    if (!uses.length) return res;
    messages.push({ role: 'user', content: uses.map((b) => {
      const r = memory.execute(b.input);
      return { type: 'tool_result', tool_use_id: b.id, content: r.content, is_error: r.isError };
    }) });
  }
}
main().then((res) => console.log(res.content.filter((b) => b.type === 'text').map((b) => b.text).join('\n')));

memory.definition is { type: 'memory_20250818', name: 'memory' }. Results use the wording the memory tool docs give, and errors come back with is_error: true. ThumbGate's test suite runs this exact snippet from the README against a stand-in client on every change.

Claude Code, Cursor and other MCP clients

  1. Run npx thumbgate init --memory-tool, or answer yes when npx thumbgate init asks.
  2. Restart the agent. It now has a claude_memory tool, stored in .thumbgate/memories in the project you selected.

Or set it by hand on the ThumbGate server in .mcp.json: "env": {"THUMBGATE_MEMORY_TOOL": "1"}. ThumbGate's own repository runs with it on.

What this does not do

Sources

ThumbGate is an independent project and is not made by or affiliated with Anthropic.

Memory with a gate on it

Pre-action gates built from your own thumbs-down, and a memory tool that cannot leak a key into a note.

npx thumbgate init --memory-tool
Claude's memory, checked on every write npx thumbgate init --memory-tool Setup guide