Tutorials
How to Reduce AI Agent Context Usage with Strands Stash
Strands Stash stores tool results, memory, and connected data sources as files outside an AI agent's context window. Learn how to configure it with Claude Code and reduce unnecessary context consumption.
An AI agent calls an MCP tool to retrieve information about a GitHub issue. The response contains hundreds of comments, metadata, timestamps, and references to other issues.
The agent needs only three of those comments.
Nevertheless, depending on how the agent’s environment handles tool results, the entire response may enter the model’s context window and remain there during subsequent requests.
After several similar operations, the context contains considerably more information than the current task requires.
On December 1, 2026, the Strands Agents team introduced Strands Stash 0.1.0, an open-source tool that approaches this problem through a local filesystem.
Instead of immediately placing every large result into the model’s context, Stash stores the data as files and returns a compact representation. The agent can then retrieve specific parts when needed.
How Strands Stash manages context
Stash runs a local daemon alongside the agent. The daemon maintains a directory containing information from configured sources, including MCP servers, memory providers, and knowledge bases.
The agent can access that directory using ordinary tools such as grep, cat, and jq.
Consider the difference between two ways of processing a large MCP response:
flowchart TD
A["MCP tool response"] --> B["Without Stash"]
A --> C["With Stash"]
B --> D["Full tool response"]
D --> E["Model context"]
C --> F["Full response saved locally"]
C --> G["Compact preview"]
G --> H["Model context"]
F --> I["Read relevant data"]
I --> H
Stash calls this approach progressive disclosure.
For MCP results of up to 20,000 characters, Stash returns the complete information, potentially using a more compact representation for JSON. Larger responses receive a preview.
When the full result fits within the configured storage limits, the preview includes its file path.
This distinction is useful because a shorter representation does not necessarily mean information has been discarded. The original response can remain available on disk.
However, if the agent subsequently reads the entire file, much of the context-saving benefit disappears.
Stash provides a mechanism for selective access. The agent still needs to use it appropriately.
1. Install Strands Stash
The initial release supports Linux on x86-64 and ARM64, as well as macOS on Apple silicon.
Native Windows support is not available in version 0.1.0.
With Node.js and npm installed, run:
npm install -g @strands-agents/[email protected]
Verify the installation:
stash --version
The global installation matters here.
When Stash connects to Claude Code or another supported agent, it writes the executable’s path into the integration configuration.
Installing it temporarily through npx could leave those references pointing to a binary that no longer exists.
The local setup does not require an AWS account. Cloud credentials are only necessary when connecting sources that require them.
2. Create a local context workspace
Open an existing project directory and create stash.toml:
mount_point = "/tmp/project-context"
harnesses = ["claude"]
[extraction]
enabled = true
The mount point must be an absolute path that either does not exist or refers to an empty directory.
The harnesses setting identifies Claude Code as the agent environment.
The extraction option enables local notes, which can preserve useful findings between sessions. It is not required merely to compact MCP responses.
Create the mount and attach it to the current project:
stash create project --config stash.toml --attach
The command starts the daemon and configures the Claude Code integration.
It adds or updates the following files:
| File | Purpose |
|---|---|
CLAUDE.md |
Instructions for accessing the Stash workspace |
.claude/settings.local.json |
Integration hooks |
.mcp.json |
Registration of the Stash MCP server |
Existing content outside Stash-managed entries is preserved.
The command may return before initialization finishes, so check the mount’s state:
stash status project
Continue once the state is ready.
3. Preserve information between agent sessions
Before connecting an external service, we can demonstrate the local memory mechanism.
Suppose a project uses PostgreSQL, and a previous investigation established that a particular database query needs optimization.
Save that finding as a note:
stash note save project --topic "database findings" <<'EOF'
The application uses PostgreSQL.
The reports endpoint loads more columns than necessary.
Before introducing a caching layer, inspect the SQL
query and reduce the selected columns.
EOF
Inspect the saved notes:
ls /tmp/project-context/local/memories/
Start Claude Code from the attached project:
claude
Then ask:
Read the saved database findings from the Stash workspace.
What should be investigated before adding a caching layer?
The agent can retrieve the existing note instead of reconstructing the previous investigation.
The note remains available to future sessions while its local storage is retained.
This demonstrates persistent local context. Handling large MCP responses uses the same workspace but a different retrieval mechanism.
4. Connect an MCP server
Suppose your team has an MCP server that provides access to an issue tracker.
A single ticket may contain its description, hundreds of comments, and additional metadata.
You can register such a server as a Stash source.
Extend the configuration:
[sources.ticketing]
kind = "mcp"
description = "Project tickets and comments"
url = "https://tickets.example.com/mcp"
auth = { bearer = { env = "TICKETING_MCP_TOKEN" } }
The URL is illustrative. Replace it with your actual MCP endpoint, and provide the corresponding bearer token through the environment before starting the daemon.
For a local MCP server, use command and args instead of url.
One configuration detail is easy to overlook: Stash retains a copy of the configuration when creating a mount.
Editing stash.toml does not automatically update an existing mount.
For this tutorial, create a separate mount with the extended configuration and a different, empty mount point, or recreate the original mount after preserving any notes you still need.
Once the configured mount is ready, inspect the available tools:
stash tool list project
Assuming the example server exposes a get_ticket tool, call it through Stash:
stash tool call project ticketing/get_ticket \
--input '{"id": "INC-1001"}'
For sufficiently large responses, the terminal displays a compact preview and, when the result was saved successfully, its location.
The original data is stored under a directory resembling:
/tmp/project-context/
└── mcp/
└── ticketing/
├── _tools/
└── _tools_results/
└── get_ticket/
└── <call-id>/
├── call_metadata.json
└── content/
└── 1.json
The exact call identifier and content files depend on the response.
The attached agent can also invoke this source through the Stash MCP server, rather than calling the original server directly.
Avoid leaving duplicate native MCP tools enabled when evaluating Stash. Otherwise, the agent may continue using the original integration and bypass the compact-response mechanism.
5. Read only the information the agent needs
Suppose the saved JSON contains this structure:
{
"id": "INC-1001",
"status": "open",
"comments": [
{
"author": "developer",
"text": "The issue appeared after deployment."
},
{
"author": "maintainer",
"text": "Investigate the connection pool."
}
]
}
A real response might contain hundreds of comments rather than two.
Instead of reading the complete document, the agent can filter it with jq:
jq '.comments[] | select(.author == "maintainer") | .text' \
/tmp/project-context/mcp/ticketing/_tools_results/get_ticket/<call-id>/content/1.json
Replace <call-id> with the actual directory reported by Stash.
The expected output for the illustrative JSON is:
"Investigate the connection pool."
Only the selected information needs to enter the model’s context.
There is another potential benefit. If the agent later needs a different comment from the same saved response, it can read the cached file without necessarily contacting the original MCP server again.
That may reduce remote tool calls, provided the cached information is still available and sufficiently current.
6. Measure whether Stash reduces token usage
A smaller tool response does not automatically establish a lower overall execution cost.
The agent might perform additional file reads. It might take longer to locate relevant information, or it might retrieve a large portion of the original response anyway.
The useful comparison is therefore between complete tasks, not just individual tool results.
Run the same multi-turn task twice using the same model and comparable settings.
In the first scenario, connect the agent directly to the MCP server.
In the second, route the same server through Stash.
Record the following measurements:
| Metric | What it reveals |
|---|---|
| Total input tokens | How much information was sent to the model |
| Output tokens | How much content the model generated |
| Cached input tokens | Whether provider-side prompt caching affected the comparison |
| Remote MCP calls | Whether stored responses were reused |
| Local file reads | How much additional retrieval Stash introduced |
| Total execution cost | Whether token savings translated into lower cost |
| Task accuracy | Whether both agents reached the correct result |
Repeat each scenario several times. Agents do not necessarily follow identical execution paths, even when given the same instructions.
The Strands Stash repository also includes a /stash-run-eval skill intended for this kind of comparison using Claude Code.
It performs real model and tool calls, so evaluation can incur charges.
Without running such an experiment, there is no reliable basis for claiming a particular percentage of token savings.
7. Storage limits and security
Stash does not retain every response regardless of its size.
Version 0.1.0 documents two relevant limits for MCP results:
- Responses larger than 32 MiB are not retained.
- Individual files larger than 25% of
cache_max_bytesare not written.
A preview may still be returned when the complete result cannot be saved.
This means an agent should not assume that every preview has a recoverable full-response file.
Remote MCP authentication also has limitations. Stash does not acquire or refresh OAuth tokens automatically, and the supported remote MCP transport is Streamable HTTP rather than the older standalone SSE transport.
There is a separate security consideration.
Moving information outside the model’s context window does not make it private.
The information is still present on the host filesystem. Anyone with sufficient access to the mount can potentially read it.
Keep the mount and Stash data directory away from shared or publicly accessible locations. Connect sources using restricted credentials, and do not expose tools that the agent should not be authorized to call.
Stash is not an access-control system.
It also collects anonymous usage analytics, which can be inspected and disabled:
stash usage-analytics status
stash usage-analytics disable
The Stash software itself is open source under Apache 2.0. Model inference and connected services may still incur their usual charges.
8. Remove the workspace
When you no longer need the demonstration workspace, exit Claude Code and run:
stash delete project --yes --remove-data
This removes the mount, its local data, and the associated Stash integration entries.
Be careful with --remove-data if you have saved notes that you intend to use later.
Deleting the local workspace does not automatically delete the original records from connected external services.
When does Stash make sense?
Consider an agent that repeatedly investigates incidents, reads lengthy issue discussions, or processes large responses from internal APIs.
Much of the retrieved information may remain useful, but rarely does the agent need all of it at every step.
A filesystem-backed workspace allows the agent to retain that information without immediately carrying every detail into the model’s context.
For smaller tasks with short tool responses, the additional retrieval mechanism may provide little benefit.
For larger investigations, the difference can be more substantial.
The underlying question is how much information the agent actually needs for its next decision.
Strands Stash provides a place for everything else to remain accessible until it becomes relevant.