This page lists each `stash` command, its flags, and its exit codes. For the config file, see the [configuration reference](/docs/user-guide/stash/reference/configuration/index.md).

## Command shape

```text
stash [--log-level LEVEL] [-v|--verbose] <command>
```

| Option | Default | Description |
| --- | --- | --- |
| `--log-level LEVEL` | `info` | The log filter: a level (`error`, `warn`, `info`, `debug`, `trace`, `off`), or a comma-separated list of levels and `target=level` filters, such as `stash=debug,warn`. Another value exits `1`. |
| `-v`, `--verbose` | off | Uses the `debug` filter. It takes priority over `--log-level`. |
| `-h`, `--help` | n/a | Shows help for the command. |
| `-V`, `--version` | n/a | Shows the version of the binary. |

`RUST_LOG` overrides both options. The options set the level of Stash itself. Libraries log at `warn`, or at `error` when the level is stricter, unless `RUST_LOG` names them, for example `RUST_LOG=aws_config=debug`. No filter shows the log lines in which the AWS SDK writes an access key ID.

## Output

Results go to stdout: a table, `key: value` lines, search hits, or JSON. Messages about what the command did go to stderr. So `x=$(stash ...)` captures only the results. On a terminal, the output has colors. A pipe or a file gets plain text. Set `NO_COLOR` to turn off the colors.

## Exit codes

| Code | Meaning |
| --- | --- |
| `0` | Success. Help and `--version` also exit `0`. |
| `1` | Failure, also a flag or an argument that does not parse. |

No command exits `2`, because some harnesses read `2` from a hook as “stop the turn”. Each command section below names its other `0` and `1` cases.

## The daemon

Most commands talk to one background daemon over a control socket.

| Commands | Daemon |
| --- | --- |
| `daemon start`, `create`, `update`, `usage-analytics disable`, `usage-analytics enable` | Start the daemon when none runs. |
| `bind`, `delete`, `attach`, `detach`, `search`, `tool list`, `tool call`, `mcp`, `note save`, `compact`, `hook` | Need a running daemon, and exit `1` without one. They never start one. |
| `ls`, `status`, `daemon status`, `daemon stop` | Exit `0` when no daemon runs. |
| `redrive`, `usage-analytics status`, `configure` | Do not need the daemon. |

A daemon gets its environment once, from the command that starts it. A running daemon ignores the environment of each later command, for example a new `AWS_PROFILE`. To change it, run `stash daemon stop`, then run the command again. See [AWS credentials](/docs/user-guide/stash/reference/configuration/index.md#aws-credentials).

## Data and control roots

| Variable | Purpose |
| --- | --- |
| `STASH_DATA_ROOT` | The durable data root. The default is `$HOME/.stash`. AgentCore Runtime ignores it. |
| `STASH_CONTROL_ROOT` | The folder of `control.sock`. The default is `/tmp/stash-control`. The socket path must fit the Unix-socket limit of the platform. |
| `STASH_STORAGE_PREFIX` | On AgentCore Runtime only: the durable storage path below which Stash puts each session. It is required before the first `create`. |

Each client command must use the same roots as the daemon. A running daemon writes its control root to `daemon.control` in the data root, and a client that shares the data root uses it. An explicit `STASH_CONTROL_ROOT` takes priority. The default control root allows one daemon on each machine. Put more mounts in that daemon. A command for another data root refuses the running daemon.

Only `daemon start` has `--data-root`. It takes priority over `STASH_DATA_ROOT`. Set `STASH_DATA_ROOT` to the same path for later commands.

On AgentCore Runtime, the entry point is `create --session-id ID`. Stash uses `$STASH_STORAGE_PREFIX/sessions/<ID>/.stash` as the data root, and `$STASH_STORAGE_PREFIX/sessions/<ID>/mounts/NAME` as the mount point. Later commands and hooks find this home through a locator under `/tmp`. Runtime refuses `--data-root`. A missing `STASH_STORAGE_PREFIX` is a deployment error: configure the Runtime storage mount and deploy again. See [Deploy on AgentCore Runtime](/docs/user-guide/stash/integrations/agentcore-runtime/index.md).

The data root needs working advisory file locks. Outside Runtime, use a local disk.

## `stash daemon start`

Start the daemon in the background.

```text
stash daemon start [--data-root DIR]
```

| Option | Description |
| --- | --- |
| `--data-root DIR` | The data root of this daemon. |

The command is idempotent: it exits `0` when the daemon already runs. When it starts the daemon, it can print the [usage analytics](#stash-usage-analytics) notice on stderr.

## `stash daemon stop`

Stop the daemon. Each mount is suspended, and the next `daemon start` restores it.

```text
stash daemon stop
```

The command exits `0` when no daemon runs. When the socket does not answer, it sends SIGTERM to the process in `daemon.pid`.

The daemon does not wait for write-back. A send in flight stops, and each unsent turn stays queued on disk. The next `daemon start` sends it. The configs, bindings, workspace routes, and files of each mount stay. To forget a mount, use [`stash delete`](#stash-delete).

## `stash daemon status`

Show whether the daemon runs, and its mounts.

```text
stash daemon status
```

```text
data_root: /home/alice/.stash
control_root: /tmp/stash-control
control_socket: /tmp/stash-control/control.sock
daemon: running
version: 0.1.0
usage_analytics: on
mounts: 1
  team [ready] /tmp/stash
```

`version` is the version of the daemon. It can differ from the `stash` that you run, and reads `unknown` when the daemon does not send it. A stopped daemon exits `0`. A daemon that runs but does not answer exits `1`.

## `stash configure`

Create or edit a config file with an interactive wizard.

```text
stash configure [--config PATH]
```

| Option | Default | Description |
| --- | --- | --- |
| `--config PATH` | `stash.toml` | The file to create or edit. |

Stdin and stdout must be terminals. The wizard asks for the mount point (an absolute path with no `~`), the harnesses, and each source. For each write that a kind can do, it asks yes or no. A valid file opens on the menu: save, add a source, or answer one part again. An edit keeps the comments and the layout of the file. When a question has a value, Enter keeps it and `-` clears it. The wizard validates the whole config before it writes. It does not overwrite an invalid or unreadable file.

After it saves, the wizard can run `stash create NAME --config PATH`, and optionally attach the current directory. It then exits with the code of `create`. Cancel writes nothing and exits `0`.

## `stash create`

Create a named mount. The daemon then hydrates and serves it.

```text
stash create NAME --config PATH [--session-id ID] [--attach [DIR]] [--global] [--no-mcp]
```

| Argument or option | Default | Description |
| --- | --- | --- |
| `NAME` | required | The name of the mount. |
| `--config PATH` | required | The config file. |
| `--session-id ID` | none | Required on AgentCore Runtime, where it selects the session home. Elsewhere, it gives the value of `${sessionId}` when the config uses that variable. |
| `--attach [DIR]` | no attach | Attaches `DIR` (default `.`) after the start, as [`stash attach`](#stash-attach) does. |
| `--global` | off | With `--attach` and no `DIR`: attaches all agent sessions. |
| `--no-mcp` | off | With `--attach`: attaches as `attach --no-mcp` does. |

A name has 1 to 255 bytes of ASCII letters, digits, `-`, `_`, and `.`, and is not `.` or `..`. `--global` and `--no-mcp` need `--attach`. `--attach DIR --global` exits `1` before the mount is created.

`create` copies the config to `$STASH_DATA_ROOT/mounts/NAME/config.toml`, and the daemon serves that copy. A later edit of `PATH` does not change the mount. To change it, use [`stash update`](#stash-update).

`create` is idempotent: the same name and config are safe to send again. A different config for an existing name exits `1`, and the error names `stash update`.

`create` does not wait for the mount to be ready. It exits `0` and prints the state, usually `starting`. Run `stash status NAME` until it shows `state: ready`. Until then, a search or a tool call fails with `mount "NAME" is starting`. A mount that cannot start becomes `failed`. `create` still exits `0`, and `stash status NAME` shows the error. To try again, delete the mount and create it again.

When a step of the first load fails, the daemon writes one `WARN` line to the daemon log. The line names the source, the step, and the error:

```text
agentcore-memory/team: hydration listing /actor/alice/* failed: access denied (AccessDeniedException: User is not authorized to perform: bedrock-agentcore:ListMemoryRecords)
```

A config with unbound `${...}` variables makes a pending mount: `state: pending_config_resolution`. `create` prints the `bind` command to run, and exits `0`. See [Template variables](/docs/user-guide/stash/reference/configuration/index.md#template-variables).

`create` does not attach a pending or a failed mount. An attach that fails prints a warning, and `create` still exits `0`.

On AgentCore Runtime, `create` needs `--session-id` and `STASH_STORAGE_PREFIX`. Stash ignores `mount_point` and warns when the config sets it. The same create again is idempotent. A different session cannot replace the active session of the same Runtime process.

## `stash bind`

Give values to the template variables of a pending mount.

```text
stash bind NAME --set KEY=VALUE [--set KEY=VALUE ...]
```

| Argument or option | Description |
| --- | --- |
| `NAME` | The mount. |
| `--set KEY=VALUE` | One value. Repeat it for each variable. The value is all the text after the first `=`. |

You can give some values now and the others later. The command exits `1` for a variable that the config does not name, and for an empty value. Until the mount starts, a new value replaces the old one. After the start, the same value is a no-op, and a different value exits `1`. To change a value then, delete the mount and create it again.

The daemon writes the values to `mounts/NAME/bindings.json`. When the last variable has a value, the daemon checks the whole config. A value that makes it invalid exits `1`, and nothing is written. Then the mount starts, and `bind` exits without a wait. Until then, `bind` prints the variables that have no value.

## `stash update`

Change the config of a mount. The daemon stops only this mount, applies the new config, and starts the mount again.

```text
stash update NAME --config PATH
```

| Argument or option | Description |
| --- | --- |
| `NAME` | The mount. |
| `--config PATH` | The whole new config. A source that it leaves out is removed, with its files. |

`update` checks the config as `create` does, prints the plan, and applies it with no prompt:

```text
$ stash update team --config team.toml
mount team:
  + docs-mcp         added
  - wiki-mcp         removed: 120 records and 4 tool results go
  ~ notes-mem notes  moves: 2 queued writes go to the new destination; no failed write; a send in flight can go to both
  ~ extraction       off
     Updated the steering in 1 attached workspace: /home/me/work/app
mount team is updated
```

| Line | Meaning |
| --- | --- |
| `+ SOURCE added` | The new config adds the source. |
| `- SOURCE removed: …` | The source goes, with its files and tool results. |
| `~ SOURCE changed: … go` | A key that chooses what the source reads changes, so its files go. All keys do except `description`, the intervals, and `write`. |
| `~ SOURCE changed: its files stay` | Only `description` or an interval changes. |
| `+ SOURCE turns` or `notes` | The source starts to write back that kind. An added source gets only the writes after the update. |
| `- SOURCE turns` or `notes` | The source stops writing that kind. Its queued writes of that kind are not sent. |
| `~ SOURCE turns` or `notes` | That kind moves to another memory, endpoint, region, actor, or namespace. Its queued writes go to the new destination. |
| `~ extraction` | `[extraction]` turns `on` or `off`. |
| `~ harnesses` | `harnesses` changes. Run `stash attach` again in each workspace. |

When a kind stops or moves, its failed writes go to `mounts/NAME/writers/<writer>/dequeued/`. Nothing sends a file there, and [`stash redrive`](#stash-redrive) does not move it. A send in flight to the old destination can arrive at both destinations. The notes in `local/memories/` do not change.

During the update, a call in flight on the mount gets up to 5 seconds, then fails with `the mount did not answer`. A call that changes data can stop part of the way. Each local server of the mount gets up to 5 seconds to exit. Other requests to the daemon, also the hooks of other mounts, wait for the update. A search or a tool call on this mount fails with `mount "NAME" is updating`.

After the start, `update` writes the steering block again in each attached workspace. It installs no hook. It prints one line for each source that did not start, and still exits `0`:

```text
source drive did not start: service unavailable (could not start drive-mcp: No such file or directory (os error 2))
```

A new config with a variable that has no value makes the mount wait for `stash bind`. `update` exits `0`, and prints the `bind` command. Values of variables that the new config still names stay.

A new `from_env` value comes from the environment of the daemon. To give it a value, stop the daemon, then run `update` from that shell.

On AgentCore Runtime, each session start runs `create --session-id` with its config file. Change that file too, or the next `create` exits `1`.

### What `update` refuses

A refusal changes nothing. In the last row, the update applied, but the mount did not start.

| Case | Exit |
| --- | --- |
| The mount serves the new config | `0` |
| The config text is the same, other than layout and comments: prints `no change` | `0` |
| The mount is not recorded, or has no stored config | `1` |
| The config fails the checks of `create` | `1` |
| A change of `mount_point`, `cache_max_bytes`, or `[telemetry]`. Delete the mount with `--remove-data`, and create it again | `1` |
| The stored config changed after `update` read it: ``the config of mount "NAME" changed since `stash update` read it; run `stash update` again`` | `1` |
| The daemon refuses or fails the update. The old config starts again | `1` |
| The mount is `failed`, or still `starting` after 120 seconds | `1` |

### When the daemon stops

When no answer comes, because the daemon stops or dies or the wait ends, `update` waits for the mount to leave `starting`, then reads the stored config. If it is the new config, the update applied: when the mount serves, `update` reports it as applied; otherwise it exits `0`, and tells you to run `stash status NAME` and `stash attach NAME` again. If it is the old config, `update` exits `1`.

## `stash delete`

Stop a mount and forget it. With `--remove-data`, also remove its data.

```text
stash delete NAME [-y|--yes] [--remove-data [--force]]
```

| Argument or option | Description |
| --- | --- |
| `NAME` | The mount. |
| `-y`, `--yes` | Skips the prompt. With `--remove-data`, it refuses while the mount has unsent writes, unless you also give `--force`. |
| `--remove-data` | Also removes the data of the mount. |
| `--force` | With `--remove-data` only: discards each unsent write. |

Without `--yes`, the command needs a terminal for the prompt.

The data of a mount is each file in its mount point, with `local/memories/` and `local/scratchpad/`, and all of `$STASH_DATA_ROOT/mounts/NAME/`.

-   **Without `--remove-data`**, the data stays. The mount stops, leaves `stash ls`, and each workspace is detached. A `create NAME` with the same config serves it again, and sends the writes that stayed queued. A `create NAME` with another config exits `1` until a delete with `--remove-data`.
-   **With `--remove-data`**, Stash removes the mount point with every file in it, also files that Stash did not write, and `mounts/NAME/`. It also removes the kept data of a name that is no longer a mount. It exits `1` when the mount point of another mount is inside this one.

A delete that the daemon stop interrupts finishes at the next daemon start.

`--remove-data` counts the unsent writes before it removes anything:

| Command | No unsent writes | Unsent writes |
| --- | --- | --- |
| `delete NAME` | Deletes, keeps the data. | Deletes, keeps the writes queued. |
| `delete NAME --remove-data` in a terminal | Asks. | Asks, and names the writes. `y` discards the failed writes, but not the queued turns. |
| `delete NAME --yes --remove-data` | Deletes. | Exits `1`, and names `--force`. |
| `delete NAME --yes --remove-data --force` | Deletes. | Deletes, and discards the writes. |

```text
$ stash delete team-memory --remove-data
Mount "team-memory" has unsent writes that will be discarded:
  1 refused by the store (waiting for redrive)
Run `stash redrive team-memory` first to try sending them again.
Warning: the delete removes every file in /mnt/team-memory, also each file that Stash did not write.
Delete "team-memory" and discard them? [y/N]
```

A queued turn clears when the mount sends it (see `stash status NAME`). A failed write does not clear by waiting: run `stash redrive` first. When Stash cannot read the writers of a mount, for example because its stored config does not parse or has unbound variables, each queued turn counts as unsent. Then only `--force` removes the data. Files in `dequeued/` are not unsent writes.

A refused delete exits `1` and changes nothing. After a delete, Stash detaches each workspace of the mount. A cleanup error of a harness file is a warning.

## `stash attach`

Connect a workspace, or all agent sessions, to one mount.

```text
stash attach NAME [DIR] [--global] [--no-mcp]
```

| Argument or option | Default | Description |
| --- | --- | --- |
| `NAME` | required | The mount. |
| `DIR` | `.` | The workspace folder. It must exist, and cannot be your home folder: use `--global`. |
| `--global` | off | Installs the files in the home of each harness. |
| `--no-mcp` | off | Does not add the [`stash mcp`](#stash-mcp) server. The steering then names `stash search` and `stash tool call`. |

The config must name at least one harness in `harnesses`. One mount owns each workspace route. An attach of the same mount again is idempotent.

A mount gets only the turns from the time of the attach. It does not get earlier turns, also when a workspace moves back to a mount. A turn with no timestamp is sent.

The Claude Code and Codex hooks run `stash` by name, through `sh -c`, so the harness must find `stash` on its `PATH`. When the `PATH` of `attach` does not find the running `stash`, `attach` prints a note that names the folder to add.

The Claude Code hooks are in exec form (`command` and `args`), which needs Claude Code 2.1.139 or later. When `claude --version` names an older version, `attach` prints a note.

When one harness fails to install, `attach` removes its files, and exits `1`. The workspace stays attached for the other harnesses. Fix the problem, and run the same command again. After a local attach, Stash warms the mount from the workspace. A warm-up error does not undo the attach.

### Installed files

| Harness | Local attach | Global attach |
| --- | --- | --- |
| Claude | `DIR/.claude/settings.local.json`, `DIR/CLAUDE.md` | `~/.claude/settings.json`, `~/.claude/CLAUDE.md` |
| Codex | `DIR/.codex/hooks.json`, `DIR/AGENTS.md` | `~/.codex/hooks.json`, `~/.codex/AGENTS.md` |
| Kiro | `DIR/.kiro/hooks/strands-stash.json`, `DIR/.kiro/steering/strands-stash.md` | `~/.kiro/hooks/strands-stash.json`, `~/.kiro/steering/strands-stash.md` |

The MCP server entry, named `stash`, unless you give `--no-mcp`:

| Harness | Local attach | Global attach |
| --- | --- | --- |
| Claude | `DIR/.mcp.json`, and `stash` in `enabledMcpjsonServers` of `DIR/.claude/settings.local.json` | `~/.claude.json`, through `claude mcp add-json --scope user`. When `claude` is missing, fails, or takes more than 30 seconds, `attach` warns and prints the command to run. |
| Codex | `DIR/.codex/config.toml` | `~/.codex/config.toml` |
| Kiro | `DIR/.kiro/settings/mcp.json` | `~/.kiro/settings/mcp.json` |

When `CLAUDE_CONFIG_DIR` is set, a global attach to Claude uses that folder in place of `~/.claude` and `~/.claude.json`. Run `detach --global`, `delete`, and `update` with the same value.

Each harness gets a `Stop` hook, which sends each turn, and a `SessionStart` hook, which warms the mount and tells the agent what it holds. Claude and Codex also get a `PostToolUse` hook for [note requests](#note-requests). Kiro gets no `PostToolUse` hook, because it drops its output. Codex runs a new hook only after you trust it in `/hooks`. Kiro support is the v3 engine (`kiro-cli chat --v3`). The v2 engine does not read `.kiro/hooks`.

Stash owns only its hook entries, its `stash` MCP entry, and the steering block between its markers. It writes no permission rule. It keeps each byte outside the markers. A file with a marker that has no partner, or with two blocks, makes `attach` and `detach` exit `1` with no change. Fix the markers by hand. A `stash` MCP server that Stash did not add also makes `attach` exit `1` with no change to that file. Rename or remove that server, and run `attach` again. On a global Claude attach, `attach` warns and leaves such a server.

So that the agent can save a note with no prompt, `attach` does this. With no `[extraction]` there is no note to save, so it does the last column instead:

| Harness | What `attach` does | With no `[extraction]` |
| --- | --- | --- |
| Claude | Prints the allow rules to add yourself: `Bash(stash note save:*)` and `mcp__stash__save_note`, in `.claude/settings.local.json`, or in `~/.claude/settings.json` with `--global`. | Prints nothing. |
| Codex | Nothing: Codex asks before each `stash note save` and `stash search`. | Names `stash search` alone. |
| Kiro | Prints the rule to add to `~/.kiro/settings/permissions.yaml`. | Prints nothing. |

`attach` and `detach` change no permission.

Claude asks one time before it runs a `.mcp.json` server in a folder that it does not trust. Codex reads `.codex/config.toml` only in a trusted project. Trust the project, or attach with `--no-mcp`.

A harness can also run its own copy of an `mcp` source of the mount. Then the agent sees each tool twice. `attach` names these sources, and prints how to turn off the copy: `/mcp` or `disabledMcpjsonServers` in Claude, `enabled = false` in Codex, and `"disabled": true` in Kiro.

The steering block lists each source with its search path, and the tools of each MCP server. It tells the agent where earlier notes are, and that `local/scratchpad/` is the one folder that it writes in. With `[extraction]`, it also has a Note-taking section. Run `attach` again to update an older block.

## `stash detach`

Remove Stash from a workspace, or from all agent sessions.

```text
stash detach [DIR] [--global]
```

| Argument or option | Default | Description |
| --- | --- | --- |
| `DIR` | `.` | The workspace. It must exist, and cannot be your home folder: use `--global`. |
| `--global` | off | Removes the global integration and route. |

`detach` takes no mount name. It removes the hooks, the steering block, the `stash` MCP entry, and the route. It removes a file or a folder that `attach` made when it is then empty. A file with your content stays. When a running daemon has a route for a folder that no longer exists, `detach` removes that route too.

It prints `Detached` when it removed something, or `Skipped …, not attached`, and exits `0`. A cleanup error is a warning. When `detach` removed nothing and a cleanup failed, it exits `1`. To see the workspaces of a mount, run [`stash status NAME`](#stash-status).

## `stash ls`

List the mounts of the daemon.

```text
stash ls
```

The table has `NAME`, `MOUNT POINT`, `STATE`, and `UPTIME`. A stopped daemon prints `no mounts (daemon not running)`.

## `stash status`

Show one mount.

```text
stash status NAME
```

```text
Mount
  name: team
  state: ready
  health: degraded (1 of 2 sources not started: web)
  uptime: 6m19s
  version: 0.1.0
  mount_point: /tmp/stash
  directory consumption: 0.5% (5.1 MiB of 1 GiB)
Sources
  team (agentcore-memory): started
  web (gateway.web-search): not started (service unavailable)
Workspaces
  /home/me/proj [claude, codex]
```

| Field | Description |
| --- | --- |
| `state` | `pending_config_resolution`, `starting`, `ready`, or `failed`. |
| `health` | `ok`: `ready`, and each source started. `degraded`: `ready`, and a source did not start. `waiting`: pending or starting. `failed`: the state is `failed`. It checks nothing else, such as expired credentials. |
| `unbound` | The variables that wait for `bind`. |
| `version` | The version of the daemon. |
| `directory consumption` | The bytes of the files of the sources against `cache_max_bytes`. Sizes are binary (`1 GiB` is 1073741824 bytes). |
| `Sources` | Each source in file order: `started`, or `not started` and the reason. The local store shows only when it did not start. When no configured source starts, the mount is `failed`. |
| `Workspaces` | The attached workspaces and their harnesses. A global attach reads `global`. |

`Sources` and `directory consumption` show only while the mount serves. A stopped daemon prints `state: daemon not running` and exits `0`. A name that is not a mount prints `mount "NAME" does not exist` on stderr and exits `1`.

## `stash search`

Search one serving mount.

```text
stash search NAME QUERY --path PATH [--path PATH ...] [--top-k N] [--json]
```

| Argument or option | Default | Description |
| --- | --- | --- |
| `NAME` | required | The mount. |
| `QUERY` | required | The query. |
| `--path PATH` | required | A path inside the mount to search. Repeat it for more scopes. |
| `--top-k N` | `10` | The most hits for each path. At least `1`. |
| `--json` | off | Versioned JSON output. |

`PATH` is inside the mount, not on the host. It starts with the folder of a source: `[sources.team-memory]` of kind `agentcore-memory` is `/agentcore-memory/team-memory`, and `[sources.web]` of kind `gateway.web-search` is `/gateway/web-search/web`. The leading `/` is optional. A `.` or `..` part is an error that names the form that `--path` expects.

For a memory namespace, add it after the folder of its source. A path that ends in `*` selects a subtree, and one without `*` selects one namespace. Quote paths with `*`:

```sh
stash search team-memory "deployment policy" \
  --path '/agentcore-memory/team-memory/actor/alice/*'
```

A path outside each of the `namespaces` of a memory source fails, and the error names them ([Memory namespaces](/docs/user-guide/stash/reference/configuration/index.md#memory-namespaces)). Two paths with the same scope make one search.

The daemon writes each hit to the mount before the command prints it, so you can `cat` the file at once. A hit on a copy of a note of this mount names the note in `local/memories/`. When the harness gives a session ID, the notes that this session saved are left out, and do not count in `--top-k`.

Text output groups the hits by path. Each hit is its file path, then its preview. When the hits of a path share a long folder, the output prints it once on a `folder:` line, and each hit is relative to it:

```text
/agentcore-memory/team/actor/agent/* — 3 result(s):
  folder: /tmp/stash/team/agentcore-memory/team/actor/agent/notes/
  - glossary/a.md
    Glossary: red-file …

  - payments/b.md
    Payments: 137 rows
```

| Source | Preview |
| --- | --- |
| AgentCore Memory | Episode: `[<assessment>] <intent>`. Summary: one line for each topic. Preference: the context and the preference. Note: the best-matching sentences. Other records: the whole text. |
| Knowledge base, web search | The best-matching sentences, by rank: about 1,200 characters for the top 5 (or the top 10% when there are more than 50), about 150 for the next 20% (at most 10), and about 100 for the rest. A web hit starts with the page title or URL. |
| AWS Context | The whole answer. The file `<date>/<query>.md` holds the answer, the retrieved context, the citations, and the request. The same query on the same day replaces the file. |
| Other | The first lines, up to 150 characters. |

The previews of one command share 20,000 characters, in rank order. After that, each hit shows only the first line of its preview, up to 150 characters, then `[preview omitted, listing budget reached]`. Read the file for the whole record. Passages from one web page merge into one hit, so a listing can have fewer hits than `--top-k`. A knowledge base or an aws-context target sets its own number of results.

JSON output has `"version": 1`, the query, and for each path its hits with full paths, previews, and scores. A hit past the budget has `"preview_omitted": true`.

A path whose source has no search, such as an `mcp` source, prints one line that says where its files are, and the command still exits `0`:

```text
/mcp/deepwiki/* — mcp/deepwiki has no search. Browse its files locally: ls, cat, or grep /tmp/stash/mcp/deepwiki/
```

A search that fails prints at most 200 characters of the error:

```text
search failed for "/agentcore-memory/team/*": access denied (AccessDeniedException: User is not authorized to perform: bedrock-agentcore:RetrieveMemoryRecords)
```

The daemon log has the whole error, with one `INFO` or `WARN` line for each search: the source, the scope, `top_k`, the hit count, the bytes, and the time. It holds no record content. The daemon also adds one line for each search to `mounts/NAME/logs/search/<UTC-day>.log`, with the paths, `--top-k`, the hit count, and the query.

The command waits up to 180 seconds for each `--path`. It exits `1` with no daemon, with no `--path`, and for a `--top-k` below `1`.

## `stash tool list`

List the tools of the sources of a serving mount.

```text
stash tool list NAME [--source SOURCE]
```

| Argument or option | Default | Description |
| --- | --- | --- |
| `NAME` | required | The mount. |
| `--source SOURCE` | every source | Only the tools of this source. |

```text
$ stash tool list team --source issues
TOOL                  DESCRIPTION           SCHEMA
issues/search_issues  Find issues by text.  /tmp/stash/mcp/issues/_tools/search_issues.json
issues/get_issue      (none)                /tmp/stash/mcp/issues/_tools/get_issue.json
```

Each row is the address `SOURCE/TOOL`, the first sentence of the description (cut at 60 characters), and the schema file. The list is the one that each source got when the mount started, so the command calls no server. Only `mcp` and Gateway sources have tools. A Gateway tool shows without its `<target>___` prefix. The search tool of a Gateway source, such as `WebSearch`, does not show: use `stash search`. Rows sort by source, then by tool, with no case.

A source that the mount does not serve exits `1`. Its `_sources/SOURCE.md` page gives the reason.

For each source of the mount that did not start, the command writes one warning to stderr with the reason, as `stash status` shows it: `SOURCE (KIND): not started (REASON)`. With `--source`, it writes no warning. When it lists no tool and an `mcp` or Gateway source did not start, it exits with status `1`. A mount whose sources all started and have no tools exits with status `0`, and so does a mount where only a source of another kind did not start.

## `stash tool call`

Call one tool, and write its result into the mount.

```text
stash tool call NAME SOURCE/TOOL [--input JSON | --input-file PATH]
```

| Argument or option | Default | Description |
| --- | --- | --- |
| `NAME` | required | The mount. |
| `SOURCE/TOOL` | required | The tool, as `stash tool list` prints it. |
| `--input JSON` | `{}` | The arguments, as one JSON object. The schema file of the tool says what it takes. |
| `--input-file PATH` | none | Reads the arguments from a file, or from stdin for `-`. Use it for input with quotes, line breaks, or code. |

The input is at most 9371648 bytes (9 MiB less 64 KiB).

```text
$ stash tool call team issues/search_issues --input '{"q": "bug"}'
{"total_count": 2, "items": [{"number": 7, "title": "bug"}, {"number": 9, "title": "crash"}]}
```

The command prints the result, so the agent need not read the files. It prints the folder of the result first only for a failure, a result of several files, a file that is not text, or a partial view.

| Result | Output |
| --- | --- |
| At most 20,000 characters | The whole result. JSON prints as compact tables that keep each value, when that saves room. |
| Longer, with one JSON part | The JSON view, with rows cut from the end, and a line such as `… and 415 more records of tickets`. |
| Longer, JSON inside one string value | The view or card of that JSON, with a jq path such as `.body | fromjson | .items`, and a line with the members outside the string. |
| Longer, other text | A preview: a card of the fields and values of a JSON list, or the start of the text with an outline of its headings. At most 15,000 characters for each file. |
| A file that is not text | One line with its size and path. |
| Base64 data of 1,000 characters or more | A note, such as `[base64 data, 45 KiB, not shown: the file of the result has it]`. |
| A paging field, such as `next_token` | A last line that names it. Call the tool again with that value. |

The output stays within 20,000 characters. A partial view names each file that it cuts, and how to read the rest, for example with `jq`, `sed -n`, or `grep`:

```text
  /tmp/stash/mcp/issues/_tools_results/search_issues/20261025T093005123Z-a1b2c3d4/
  call_metadata.json  content/1.json
[partial view, the whole answer is in the folder above:
  content/1.json: 8% of 144 KiB; search .items with jq]
```

A line before the result marks a failure: `[the tool reported an error]`, `possible error: …` for JSON that says it failed, or `error: …` for a call that got no answer.

The folder is `SOURCE-ROOT/_tools_results/TOOL/TIME-HASH/`. `TIME` is the UTC time of the call, and `HASH` comes from the tool and its input. `call_metadata.json` holds the input and the error. `content/` holds each block of the result. A result over 32 MiB is not kept. A file over 25% of `cache_max_bytes` is not saved, and the output names it. The results stay until the cache needs the room, or until their expiry if you set one.

The daemon logs each call that reaches a source, also through [`stash mcp`](#stash-mcp), in its daily log. An answer gives an `INFO` line with the source, the tool, the bytes, the time, and `is_error`. A failed call gives a `WARN` line with its error; for a call that the tool flagged, it holds the first 150 characters of the answer. No line holds the input or other output:

```text
mcp/issues: tool search_issues: 2048 bytes in 153 ms, is_error false
mcp/issues: tool get_issue: 41 bytes in 98 ms, is_error true
mcp/issues: tool get_issue reported an error in 98 ms: error: failed to get issue: 404 Not Found
mcp/issues: tool search_issues got no answer in 300002 ms: timed out (the call did not finish within 300 s; the server may still run it)
```

Stash calls the tool one time, and never again on a failure, because a call can change data. A call that does not finish in 5 minutes writes its folder and says so. The server can still run it, so check its effect before you call again. The command waits up to 330 seconds: give the shell a timeout of at least that.

| Case | Exit |
| --- | --- |
| The tool ran, also when it failed or got no answer | `0` |
| No call: the mount or source does not serve, the source has no tools, the tool is unknown, the input is not one JSON object, or `--input-file` cannot be read | `1` |

## `stash mcp`

Serve the tools of a mount as one MCP server on stdin and stdout. A harness starts it as a local (stdio) server.

```text
stash mcp NAME
```

| Argument | Description |
| --- | --- |
| `NAME` | The mount. |

```text
$ claude mcp add stash -- stash mcp team
```

At start, `stash mcp` checks that the daemon has a mount named `NAME`, in any state. It retries for up to 2 seconds after a daemon start. If the check fails, it prints why on stderr, and exits `1`. The harness then shows the server as failed.

| Tool | Does |
| --- | --- |
| `search` | [`stash search`](#stash-search), with `query`, `path` (a list or one string), and `top_k` (default 10). |
| `status` | [`stash status NAME`](#stash-status) of the mount `name`, with no colors: its state, each source, and why each source that did not start failed. Read-only. With no `name`, for a mount that does not exist, or with no daemon, it answers with `isError`. |
| `save_note` | Only with `[extraction]`: [`stash note save`](#stash-note-save), with `topic` and `body`. The session comes from the variable of the harness. |
| `SOURCE__TOOL` | [`stash tool call`](#stash-tool-call) of one tool of `stash tool list`, such as `issues__search_issues`. |

A character that MCP does not allow in a name becomes `_`. A name over 64 characters, or one that another tool has, ends with 8 characters of a hash. Each tool keeps the description, input schema, and annotations of the source tool. The answer is the text that the command prints, with no `structuredContent`. A tool failure, or a call that cannot start, answers with `isError`. Calls run at the same time, and each waits up to 330 seconds.

The server instructions name the servers of the mount, then add the instructions of each one, in at most 4,096 characters in total. When they do not fit, each server gets an equal share, and a cut text ends with `…`.

The instructions, and the steering that `attach` writes with the server, tell the agent to call `status` when a tool that it expects is missing.

A harness reads the instructions and lists the tools once, when it starts the server. So while the mount starts, `initialize` and `tools/list` wait for it, until 25 seconds after the server started. When the mount does not serve then, for example because each of its sources failed, the instructions name no server, and `tools/list` gives only `search`, `status`, and `save_note`, so the agent can call `status` to learn why.

`stash mcp` serves only tools: no resources, no prompts, and no `notifications/tools/list_changed`. It exits `0` when its stdin closes, after the requests in flight end.

## `stash note save`

Save one note of a mount, for later sessions.

```text
stash note save NAME --topic TOPIC < BODY
```

| Argument or option | Description |
| --- | --- |
| `NAME` | The mount. |
| `--topic TOPIC` | The topic: short, lowercase, named after its subject. At most 200 characters, with at least one ASCII letter or digit. |

The body comes on stdin. The mount must have `[extraction]` and be `ready`. The daemon writes the note as one read-only file, and gives a copy to each source with `write.notes`. The command prints `Saved` or `Replaced`, and the path:

```text
/mnt/team/local/memories/3f2a9c1e/build-steps.md   (a note of a session)
/mnt/team/local/memories/build-steps.md            (a note with no session)
```

The file name comes from the topic: lowercase ASCII letters and digits, with `-` between words. A topic with another character, such as `C++ tips`, adds a short hash: `c-tips-1015d6c0`. A name over 64 characters is cut, and also ends with the hash. Two topics are the same when they are equal in ASCII lowercase, with one `-` for each run of whitespace: `Build steps` and `build STEPS` are one topic.

A save of the same topic in the same folder replaces the whole file, also a file that someone edited. To add to a note, read it, and save the old and the new text together. Stash does not track the file after a save.

The session comes from the first variable of this list that is set. A value that is not a session ID exits `1`. With none, the note has no session.

| Harness | Variable |
| --- | --- |
| Strands integration | `STRANDS_SESSION_ID` |
| Kiro | `KIRO_SESSION_ID` |
| Codex | `CODEX_THREAD_ID` |
| Claude Code | `CLAUDE_CODE_SESSION_ID` |

The body has 1 to 16,000 characters. It has a title line, then one or more of these sections, each at most once, in any order. No other heading is allowed:

```markdown
<title: the headline lesson, searchable: exact message fragments, exact
 names, exact values>

## Key facts
- <exact fact> (true when: <conditions>; evidence: <how established>)

## Workflows
- <procedure worth reusing>

## Decisions
- <what was decided> because <reason>

## Diagnosis
- <the chain from symptom to cause; alternatives considered>
- hypothesis [open|confirmed|refuted]: <assumption the work rests on>
```

The command exits `1` for a note that fails a check, a mount without `[extraction]`, a mount that is not `ready`, and no daemon. The message names the reason.

## `stash compact`

Remove files of a mount: the least recently used files down to a target size, or the files written before a time.

```text
stash compact NAME [--target-percent PERCENT | --older-than AGE]
```

| Argument or option | Default | Description |
| --- | --- | --- |
| `NAME` | required | The mount. |
| `--target-percent PERCENT` | `80` | The target, as a percent of `cache_max_bytes`, from 0 to 100. |
| `--older-than AGE` | none | Removes the files that searches, hydration, or tool calls wrote more than `AGE` ago. `AGE` is a whole number of at least 1 with `d`, `h`, or `m`, such as `7d`. |

The two options cannot be combined. Both also remove tool results. An agent finds a removed file again with a search, and a removed tool result with a new call.

```text
Compacted "team"
  removed: 412 files (21.3 MiB)
  directory consumption: 80% (819.2 MiB of 1 GiB)
```

The command exits `0`, also when it removes nothing. It exits `1` for a name that is not a serving mount, both options, or a value out of range.

## `stash redrive`

Send the write-back groups that a writer gave up on again.

```text
stash redrive [NAME]
```

| Argument | Description |
| --- | --- |
| `NAME` | One mount. Without it, each stored mount config. |

For each writer, the command moves the groups in `writers/<writer>/terminal/` to `writers/<writer>/redrive/`, and that writer sends them again. It skips a note whose source has a newer text of it. It does not move a group in `dequeued/`. The form with no name skips pending mounts and read-only mounts.

The output has `redriven_records` and `redrive_errors`. The command exits `1` when `redrive_errors` is not `0`, and for a named mount with no source that writes back. It reads the queues on disk directly.

## `stash usage-analytics`

Turn the anonymous usage analytics of the data root off or on, or show it.

```text
stash usage-analytics disable | enable | status
```

| Subcommand | Description |
| --- | --- |
| `disable` | Turns usage analytics off. Prints `Disabled usage analytics`, or `Unchanged usage analytics, already off`. |
| `enable` | Turns it on, and prints the notice again. Exits `1` with no change when `DO_NOT_TRACK` or `CI` is set in the shell. |
| `status` | Shows `on`, or `off` and the reason: `disabled`, `DO_NOT_TRACK was set`, `CI was set`, `state.json does not parse`, or `state.json is from a newer Stash`. While on, it also shows `next ping:`. It reads the file only, and sends nothing to the daemon. |

Only the daemon writes `usage-analytics/state.json`. A missing file means on, unless `DO_NOT_TRACK` or `CI` is set in the shell. A variable that is empty, `0`, or `false` is not set. When the daemon cannot save the file, the command prints `could not update usage analytics: <error>. Fix it and run the command again.` `disable` and `enable` then exit `1`.

Off wins:

| Condition | Effect |
| --- | --- |
| `create`, `daemon start`, `disable`, or the daemon sees `DO_NOT_TRACK` or `CI` | Off until `enable`. |
| `disable` | Off until `enable`. |
| `state.json` does not parse | Off until `enable` or `disable` writes it again. |
| A newer Stash wrote `state.json` | Off. `enable` and `disable` exit `1`. Upgrade Stash. |

While it is on, a `create` or `daemon start` that starts the daemon prints a notice of what is sent. The daemon sends an HTTP POST to `https://telemetry.strandsagents.com/stash/ping`:

-   `start/1`: one time for each data root, when a mount has been ready for five minutes. A `disable` in those five minutes stops it.
-   `heartbeat/1`: about 24 hours after the last ping, with a random change of up to one hour.

A daemon sends no ping in its first five minutes, and none when it stops. A failed ping is not sent again. A host that sleeps sends no heartbeat; after it wakes, the daemon sends it within one hour. The daemon log names each ping.

```json
{"v":1,"event":"heartbeat/1",
 "context":{"version":"1.2.3","os":"macos","runtime":"other","harnesses_attached":["claude"],
            "sources":[{"kind":"agentcore-memory","count":1},{"kind":"mcp","count":2}]},
 "data":{"operations":[]}}
```

| Field | Values |
| --- | --- |
| `v` | `1`. |
| `event` | `start/1` or `heartbeat/1`. |
| `context.version` | The Stash version as `x.y.z`, with no prerelease tag. |
| `context.os` | `linux`, `macos`, or `other`. |
| `context.runtime` | `agentcore-runtime` or `other`. |
| `context.harnesses_attached` | Each of `claude`, `codex`, and `kiro` that `attach` installed, and `strands` when a Strands agent was active on a ready mount since the last ping. |
| `context.sources` | For each kind of source in all mounts, its count, up to 1000: `agentcore-memory`, `mcp`, `plugin`, `gateway.web-search`, `gateway.bedrock-knowledge-bases`, `gateway.aws-context`, or `other`. A mount that waits for `bind`, or whose config does not read, adds nothing. |
| `data.operations` | Only in `heartbeat/1`: always `[]`. |

A ping never holds a name, path, URL, host, ARN, Region, account, ID, query, tool name, or content. The ping sends no `User-Agent`.

On AgentCore Runtime, each session has its own data root, so `disable` cannot run before `create --session-id`. Run it within five minutes after the mount is ready, or set `DO_NOT_TRACK` where the agent runs `create`.

## `stash hook`

Take events from the installed hooks of a harness, and batches from an integration. The command is hidden from help. `attach` installs the harness hooks. Call `hook` yourself only to build an integration.

```text
stash hook --name NAME --event EVENT --source SOURCE [--no-mcp]
```

| Option | Values | Description |
| --- | --- | --- |
| `--event EVENT` | `turn-end`, `tool-end`, `session-start`, `ingest` | The event. |
| `--source SOURCE` | `claude`, `kiro`, `codex`, `strands` | Who sends it. `turn-end` and `tool-end` need a harness. |
| `--name NAME` | mount name | The mount. |
| `--no-mcp` | off | Only for `session-start` with `--source strands`: see [Session context for an integration](#session-context-for-an-integration). Elsewhere, the hook fails as its event fails. |

| Event | Behavior |
| --- | --- |
| `session-start` (harness) | Prints what the mount holds: JSON with `hookSpecificOutput.additionalContext` for Claude and Codex, text for Kiro. With `[extraction]`, the first line names the notes folder of the session once it has a note. On a mount with local notes, the notes of earlier sessions come last: the topic and the first line of each, oldest first, in what the size limit leaves. |
| `tool-end` | Counts text for [note requests](#note-requests). Captures no turn. Always exits `0`. |
| `turn-end` | Captures the turn. Exits `0` and writes nothing for a mount that waits for `bind` or is being deleted. Exits `1` when no daemon answers, or when the queue of a write-back source fails. A read-only mount and a Kiro turn exit `0` in that case, and the daemon logs a warning. Codex gets `{}`. |
| `ingest` | See [Direct ingest](#direct-ingest). |

The hook never starts a daemon. The turn of the agent goes on in each case.

### Note requests

With `[extraction]` on and the mount `ready`, the hooks ask the agent for a note when one is due. The daemon counts 4 characters of new message text as one token: user and assistant text, tool calls, and tool output, with no thinking, images, or subagent text. A note is due after 45,000 tokens since the last request or the last note of the session. A `stash note save` or `save_note` of the session starts the count again.

| Case | Claude Code and Codex | Kiro |
| --- | --- | --- |
| A note is due | `tool-end` prints `{"hookSpecificOutput":{"hookEventName":"PostToolUse","additionalContext":"REQUEST"}}`, exits `0` | `turn-end` prints the request on stderr, exits `1` |
| No note is due | `tool-end` prints nothing, exits `0` | `turn-end` prints nothing, exits `0` |

Kiro reads exit `1` as “keep working”. It runs `Stop` hooks at most once for each turn, so a request that the agent ignores gets no retry. A tool call of a subagent counts nothing; the next tool call of the main agent gets the request. The request points to the Note-taking section of the steering. A due check that fails asks for nothing, and the turn is still captured.

### Session context for an integration

`session-start` with `--source strands` prints, as plain text, the steering block that `attach` writes, then a digest of the mount and, with local notes, the notes of earlier sessions. A Strands app puts this text in the system prompt of its agent.

```sh
stash hook --name team-memory --event session-start --source strands
```

The steering names the tools of [`stash mcp NAME`](#stash-mcp): give those tools to the agent. With `--no-mcp`, it names `stash search` and `stash tool call`.

The command reads no stdin and warms nothing. It prints only for a `ready` mount. When no daemon answers, or the mount is missing or not ready, it prints nothing and warns on stderr. It exits `1` when `--name` is missing or the data root cannot resolve, and `0` in each other case. On AgentCore Runtime, the data root resolves only after `stash create NAME --session-id ID --config PATH`.

### Direct ingest

`ingest` takes a JSON batch on stdin, and writes it durably before it exits.

```sh
stash hook --name team-memory --event ingest --source strands <<'JSON'
{
  "version": 1,
  "session_id": "session-123",
  "batch_id": "run-456:0-1",
  "source": "my-framework",
  "messages": [
    {
      "id": "run-456#0",
      "role": "USER",
      "content": "How should retries work?"
    }
  ]
}
JSON
```

| Field | Required | Rule |
| --- | --- | --- |
| `version` | yes | `1`. |
| `session_id`, `batch_id` | yes | 1 to 256 bytes. |
| `source` | no | 1 to 128 bytes. |
| `messages` | yes | 1 to 100 messages, with at most 1 MiB of content in total. |
| `messages[].id` | yes | 1 to 256 bytes, unique in the batch. |
| `messages[].role` | yes | `USER`, `ASSISTANT`, `TOOL`, or `OTHER`. |
| `messages[].content` | yes | 1 to 100,000 bytes. |
| `messages[].timestamp` | no | A finite, nonnegative number. |

Stdin is at most 8 MiB. Unknown fields are refused. A retry must use the same batch and message IDs. The command exits `1` when no daemon answers, when the mount waits for `bind`, and when the mount cannot write the batch.

Each source that writes back sends the batch, and the mount reads it for the files that the agent read. With `[extraction]` and a `ready` mount, the daemon counts the content for [note requests](#note-requests). When a note is due, the command prints the request on stdout, and the integration gives it to its agent.