Skip to content
AgenticAIWiki
  1. Learn
  2. Part 11
  3. 58. Context engineering
  4. 58.6

Lesson 58.6 · 6 of 7 · 5 min read · Reviewed 24 Nov 2026

Worked example: context editing and a memory tool

By the end, you can

  • Describe Claude's context editing feature.
  • Describe Claude's memory tool and who stores the data.

Claude’s API offers two features that put 54.3 and 54.5 into practice.

Context editing

You set a rule such as: when the input grows beyond a threshold, clear the oldest tool results, keeping the most recent few. The API replaces cleared results with a placeholder, so Claude knows something was removed.

Options let you choose the trigger, how many recent tool usesTool use: Letting a model call functions you define, by returning a structured request your code executes. to keep, and tools to exclude, such as one whose results must never be cleared.

Memory tool

The memory tool gives Claude a directory of files to use as long-term memoryLong-term memory: Information kept outside the context window, in files or databases, and brought back when relevant.. Claude can view, create, edit, rename and delete files there, for example to save what it learned about a project, a customer’s preferences or progress on a long task. In the next conversation it checks the directory first.

It’s a client tool: Claude asks for file operations and your code performs them on storage you choose. That means you decide:

  • Where data lives, and for how long.
  • Who can see it, and how it’s kept apart per user.
  • What must never be saved, such as secrets.

Together

Context editingContext editing: Removing or replacing parts of an agent’s context, such as old tool results, while it runs. keeps the working context lean; the memory tool keeps what matters beyond it. Pair them for long-running agentsAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done..

Key points

  • Context editing can automatically clear older tool results once the context passes a threshold you set.
  • The memory tool lets Claude create, read and update files in a memory directory that persists across conversations.
  • With the memory tool, your application stores the files, so you control where data lives and how long.
Hands-on labOn your own machine

Turn on context editing and the memory tool

Call the Claude API from your own machine with context editing and the memory tool enabled, and watch old tool results cleared while notes persist across conversations.

You will have: A small script and a log showing input tokens per turn with and without context editing, plus the memory files written.

Steps

  1. Set your API key in an environment variable on your machine (never paste it into this site or into code).
  2. Follow the context editing docs to add a clear-tool-results rule with a low trigger so it fires in a short test.
  3. Run a 10-turn loop with a tool that returns long text, and log usage input tokens per turn, once with and once without the rule.
  4. Add the memory tool, implement its file operations on a local folder of your choice, and refuse paths outside it.
  5. Start a new conversation and check that the agent reads its memory directory before starting.

Done when

  • Input tokens level off with context editing on and keep growing with it off.
  • Cleared results appear as placeholders in the conversation.
  • The second conversation uses a note written in the first.

Docs: Context editing (Claude docs) · Memory tool (Claude docs)

Quick checkWith Claude's memory tool, where are the memory files stored?
How sure are you?
Pick an answer and how sure you are