# Built-in tools

This page lists all built-in tools and session commands included in the Bub app layer.

- **Naming convention**: dots in tool names are converted to underscores when exposed to the model (e.g., `fs.read` becomes `fs_read`), while direct terminal commands keep the dotted name (e.g., `,fs.read path=README.md`).
- **Command argument syntax**: supports positional arguments and `key=value` pairs; write booleans as `true` / `false`, lists as JSON strings, and quote values containing spaces:
  ```text
  ,bash command='printf "hello world"' timeout_seconds=10
  ,tool.describe names='["web.fetch", "tape.search"]'
  ```
- **Execution environment**: `fs.*`, `bash*`, and `run_code` run through the session's `Environment`, which defaults to running directly on the host under the current user (no security sandbox).

## Processes {#processes}

### `bash` {#bash}

```text
bash(command, cwd=None, timeout_seconds=30, background=False)
```

| Parameter | Type | Description |
| --- | --- | --- |
| `command` | `str` | Shell command string to execute |
| `cwd` | `str \| None` | Working directory; relative paths resolve against `Environment.workspace` |
| `timeout_seconds` | `float` | Foreground wait timeout in seconds (default 30); on timeout, the process moves to the background and returns a `shell_id` instead of failing |
| `background` | `bool` | Start directly in the background and return `shell_id` immediately (ignores `timeout_seconds`) |

A non-zero foreground exit code returns a tool error containing any captured output; a successful foreground command with no output returns `(no output)`.

### `bash.output` {#bash-output}

```text
bash.output(shell_id, offset=0, limit=None)
```

| Parameter | Type | Description |
| --- | --- | --- |
| `shell_id` | `str` | Background process ID returned by `bash` (e.g. `bsh-12345678`) |
| `offset` | `int` | Starting **character offset** (not line number; clamped between `0` and current buffer length) |
| `limit` | `int \| None` | Maximum characters to read |

Returns `status`, `exit_code` (`null` while running), `output`, and `next_offset` for the next incremental read.

### `bash.kill` {#bash-kill}

```text
bash.kill(shell_id)
```

Terminates the specified background Shell process and returns its final status and exit code.

## Files {#files}

### `fs.read` {#fs-read}

```text
fs.read(path, offset=0, limit=None)
```

| Parameter | Type | Description |
| --- | --- | --- |
| `path` | `str` | File path to read |
| `offset` | `int` | Zero-based starting line number (default `0`) |
| `limit` | `int \| None` | Maximum number of lines to read (reads to end of file when omitted) |

In addition to UTF-8 text files, `.png`, `.jpg`, `.jpeg`, `.webp`, and `.gif` files up to 10 MiB are returned as multimodal image objects for the model to inspect (`offset` and `limit` are ignored for images).

### `fs.write` {#fs-write}

```text
fs.write(path, content)
```

Writes complete UTF-8 text to `path` (creates missing parent directories automatically and overwrites existing files).

### `fs.edit` {#fs-edit}

```text
fs.edit(path, old, new, start=0)
```

Replaces all exact literal occurrences of `old` with `new` starting from line `start` (zero-based); returns a tool error if no match is found.

## Web {#web}

### `web.fetch` {#web-fetch}

```text
web.fetch(url, headers=None, timeout=10)
```

| Parameter | Type | Description |
| --- | --- | --- |
| `url` | `str` | Target HTTP/HTTPS URL |
| `headers` | `dict \| None` | Optional request headers (overrides default `Accept: text/markdown`) |
| `timeout` | `float` | Total request timeout in seconds (default 10) |

Sends an HTTP GET request and returns the final `url`, HTTP `status`, `content_type`, and response body (non-2xx statuses return a tool error).

## Skill and tool discovery {#discovery}

### `skill` {#skill}

```text
skill(name=None)
```

Lists available skills and descriptions when `name` is omitted; returns the skill path and variable-expanded `SKILL.md` body when `name` is provided (`(no such skill)` if not found).

### `tool.describe` {#tool-describe}

```text
tool.describe(names)
```

Loads the full description and JSON Schema for deferred tools (`deferred=True`). Loaded tools become callable from the **next Step** and stay loaded until the session Tape is reset (unrecognized names are returned under `unknown`, and previously loaded tools under `already_loaded`).

## Session Tape management {#tape}

### `tape.info` {#tape-info}

No parameters. Returns the physical Tape name, total entry count (`entries`), anchor count (`anchors`), latest anchor (`last_anchor`), entries since the latest anchor (`entries_since_last_anchor`), and the latest token usage and cache hit rate.

### `tape.search` {#tape-search}

```text
tape.search(query, limit=20, start=None, end=None, kinds=["message", "tool_result"])
```

| Parameter | Type | Description |
| --- | --- | --- |
| `query` | `str` | Search keyword (case-insensitive; `FuzzyFileTapeStore` searches newest-first, deduplicates identical text, and supports fuzzy matching for queries of 3+ chars) |
| `limit` | `int` | Maximum matching entries to return (default 20) |
| `start` / `end` | `str \| None` | Optional inclusive ISO date or timestamp bounds |
| `kinds` | `list[str]` | Entry kinds to search |

Returns `matches` and the count of `filtered` duplicate/self-search entries.

### `tape.anchors` {#tape-anchors}

No parameters. Lists all anchor names in the current session Tape in recording order (`(no anchors)` if empty).

### `tape.handoff` {#tape-handoff}

```text
tape.handoff(name="handoff", summary="")
```

Appends a new anchor named `name` (storing `summary` in `state.summary`), advancing the default model context start point to this anchor. Does not automatically generate a summary.

### `tape.reset` {#tape-reset}

```text
tape.reset(archive=False)
```

Clears the current session Tape and writes a new `session/start` anchor. When `archive=True`, backs up the main Tape and sidecars to `<BUB_HOME>/tapes/` with a UTC timestamp and `.bak` suffix before clearing.

## Subagents {#subagent}

### `subagent` {#subagent-tool}

```text
subagent(prompt, agent=None, description=None, model=None, reasoning_effort=None,
         session="temp", allowed_tools=None, allowed_skills=None, timeout_seconds=None)
```

| Parameter | Type and default | Description |
| --- | --- | --- |
| `prompt` | `str \| list` (required) | Task instructions for the subagent |
| `agent` | `str \| None` (`None`) | [Subagent profile](/docs/app/subagents/#profiles) name; explicit call arguments override profile settings |
| `description` | `str \| None` (`None`) | Short task label; defaults to the first line of `prompt` |
| `model` | `str \| None` (`None`) | Model for the subagent (`provider:model`); defaults to profile model or parent model |
| `reasoning_effort` | `str \| None` (`None`) | Reasoning effort for the subagent |
| `session` | `str` (`"temp"`) | Session mode: `"temp"` (blank session discarded on exit), `"fork"` / `"inherit"` (snapshot copy of current conversation discarded on exit), or a custom session ID string (persisted) |
| `allowed_tools` | `list[str] \| None` (`None`) | Allowed tool names (must be a subset of the parent's tools; `subagent*` is always excluded) |
| `allowed_skills` | `list[str] \| None` (`None`) | Allowed skill names (subset of parent's skills; `[]` disables skills) |
| `timeout_seconds` | `int \| None` (`None`) | Timeout in seconds; defaults to profile timeout, then `BUB_SUBAGENT_TIMEOUT_SECONDS` |

`subagent` starts the task asynchronously in the background and returns `task_id` with initial status `queued` or `running`. When the child finishes, the parent receives a `<subagent-notification>` containing the child's final answer before its next Step. The parent run waits for all subagents it started to finish before completing.

### `subagent.wait` {#subagent-wait}

```text
subagent.wait(task_ids=None, timeout_seconds=60)
```

Waits for and returns subagent results (`task_ids` defaults to all unread tasks in the session; `timeout_seconds=0` checks status without blocking). Tasks read via `subagent.wait` do not send a duplicate `<subagent-notification>`.

### `subagent.send` {#subagent-send}

```text
subagent.send(task_id, message)
```

Sends a follow-up instruction to a running task (read before its next Step), or resumes a finished task that used a custom named session (finished `temp` / `fork` tasks cannot be resumed).

### `subagent.cancel` {#subagent-cancel}

```text
subagent.cancel(task_id)
```

Cancels a running subagent task, setting its status to `cancelled` and preserving partial output.

### Subagent events {#subagent-events}

Subagents emit three events on `agent.events` (importable from `bub.builtin.subagents`, each carrying `event.task: SubagentTask`):

| Event class | When it fires |
| --- | --- |
| `SubagentStarted` | Task leaves the queue and begins running |
| `SubagentOutput` | Child run yields a `StreamEvent` (stored on `event.event`) |
| `SubagentFinished` | Task finishes as `completed`, `failed`, or `cancelled` |

## Code mode and large outputs (Spill) {#code-and-spill}

### `run_code` {#run-code}

```text
run_code(code, timeout_seconds=120)
```

Executes Python code in code mode. Call other tools inside the code via `await tools.<name>(key=value)` (keyword arguments); only `print()` output and explicitly attached media are returned.

### `attach_image` / `attach_audio` / `attach_video` {#attach-media}

```text
attach_image(image)
attach_audio(audio)
attach_video(video)
```

Attaches a Republic media object, local file path, or URL to the current `run_code` result (`exposure="code"`, callable only inside `run_code`).

### `spill.read` {#spill-read}

```text
spill.read(handle, cursor=0, count=1, from_end=False)
```

| Parameter | Type | Description |
| --- | --- | --- |
| `handle` | `str` | Spill handle ID from the truncated tool output preview |
| `cursor` | `int` | Starting chunk cursor |
| `count` | `int` | Number of consecutive chunks to read (up to 4) |
| `from_end` | `bool` | Read backward from the end |

Returns `next_cursor` and `complete`. The spill threshold is controlled by [`BUB_SPILL_THRESHOLD`](/docs/reference/settings/#spill-settings).

## Session control commands {#session-commands}

These tools have `exposure="command"` and can only be called directly with the command prefix (`,` by default); they are not exposed to the model:

| Command | Parameters | Purpose |
| --- | --- | --- |
| `,help` | None | List available internal commands and the active command prefix |
| `,model` | `model_id` | Switch the session model starting from the next Turn (recorded in the Tape) |
| `,reasoning_effort` | `reasoning_effort` | Set session reasoning effort starting from the next Turn |
| `,code_mode` | `enable=true` / `false` | Enable or disable code mode for the session (from the next Turn) |
| `,quit` | None | Clear pending messages, cancel active subagents, and terminate background Shell processes for the session |