# Local sessions

URL: https://swb.one/docs/local-sessions

A local session is an open workspace for a terminal agent on a paired device. SwB lists it as a target. A target is an address that can receive a message.

## Pair the device [#pair-the-device]

Follow [Pair a device](/docs/companion#pair-a-device). Use the command for your agent below. Use one `--cap` option for each feature. To change the features on a paired device, [disconnect it](/docs/companion#disconnect) first.

Ask an agent with SwB owner access to call `targets(block="local")`. Copy the address of your session. It has the format `local:session:<companion>:<harness>:<session>`. The program that runs the agent is part of the address.

## Send a message [#send-a-message]

Pass the session address as `to` in `send`. SwB tries to deliver the message to the open session. For a session with a matching agent, mailbox delivery requires access to that agent's mailbox. Use the returned conversation ID with `result` to read the reply.

| Status | Meaning |
| --- | --- |
| `working` | The agent is working |
| `blocked` | The agent is waiting for approval or input |
| `idle` | The agent is ready for work |
| `done` | The agent completed its work |
| `unknown` | The status is still to be confirmed |

For a blocked session, respond to the request in the session. SwB keeps the message in the mailbox if the sender can use that mailbox.

The companion reports session status to your SwB server. It can also report the session name and folder name. The companion can send back one answer to each message it delivers directly. The rest of the session stays on the device.

## Status hooks [#status-hooks]

A hook runs a command when an agent reports a change. Status hooks work on macOS and Linux.

```sh
swb companion connect https://swb.example.com --cap hooks
```

Install the `swb` command with [pipx](/docs/install). Make `swb` available on the agent's command search path. If you set `SWB_COMPANION_HOME`, use the same folder for the agent and the companion.

| Agent | Event command | Configuration |
| --- | --- | --- |
| Claude Code | `swb hook claude-code` | Merge the `hooks` from `channel/hooks/hooks.json` into `~/.claude/settings.json` |
| Antigravity CLI | `swb hook antigravity <event>` | Install the SwB plugin as shown below |
| Codex | `swb hook codex` | Merge the `hooks` from `integrations/codex/hooks.json` into `~/.codex/hooks.json` |

Use the files from the [SwB release checkout](/docs/deploy#docker-compose). The SwB Claude Code plugin also includes these hooks. For a custom Codex settings folder, use the `hooks.json` in that folder.

```sh
swb hook antigravity --install-plugin
```

Open a new session after you set up the hook. Check for its address in `targets(block="local")`. With the hooks capability by itself, sessions receive messages through their mailboxes.

## Herdr [#herdr]

Open a terminal agent in a Herdr pane, an area in the terminal. The companion gets session events through Herdr's socket. A socket is a connection that programs use on the same device.

For a named session or a custom socket path, see the [Herdr companion settings](https://github.com/ZhehanZhang/SwB/blob/main/src/switchboard/companion/caps/herdr.py#L36-L48).

```sh
swb companion connect https://swb.example.com --cap herdr --cap hooks
```

For replies from the pane, set up the applicable [status hook](#status-hooks). Check for a `local:session:<companion>:herdr:<session>` target. Send a short test message to the target. Check that it appears in the pane. If you set up a status hook, check the reply with `result`.

## Rex [#rex]

Rex is a terminal app from Superlogical. A Rex server keeps sessions running. A pane is one terminal area in Rex, and each pane has a block ID that stays the same.

Use Rex 0.1.0-preview.25 or later. The companion lists the terminal panes of the Rex server on the device.

```sh
swb companion connect https://swb.example.com --cap rex --cap hooks
```

Each pane becomes the target `local:session:<companion>:rex:<block uuid>`. The block uuid is the part of the block ID after `block:`. SwB pastes the message into the pane and presses Enter. SwB delivers a message to a pane that runs a known agent, such as Claude Code, Codex, or Antigravity CLI. For a pane with a shell or another program, SwB keeps the message in a mailbox.

For replies from the pane, set up the applicable [status hook](#status-hooks). The hook reads `REX_BLOCK`, which Rex sets in each pane. The state of a session shows as `unknown` until a status hook reports it. Send a short test message to the target. Check that it appears in the pane. If you set up a status hook, check the reply with `result`.

To list panes on other Rex hosts, set `SWB_REX_HOSTS` to host labels from `rex hosts`, separated by commas. A host is a computer that runs a Rex server. Status hooks run where the agent runs. Replies come from panes on the companion's own device. Run a companion on the other host for replies there. See [Rex setup](/docs/setup/rex).

## Codex [#codex]

The Codex app server is a process that gives other programs access to open Codex sessions. Start it in one terminal.

```sh
codex app-server --listen unix://
```

Open a session from a second terminal.

```sh
codex --remote unix://
```

Use a separate terminal for the companion. Use the same Codex settings folder in all terminals. For a custom socket, use `unix://<path>` in both commands above. Set `SWB_CODEX_SOCKET` to that path in the companion's terminal.

```sh
swb companion connect https://swb.example.com --cap codex
```

The companion reads session events from the app server. Check for a `local:session:<companion>:codex:<session>` target. Send a short test message to the target. Check the reply with `result`.

## OpenCode [#opencode]

Start the OpenCode server on the device.

```sh
opencode serve --hostname 127.0.0.1 --port 4096
```

Open a session on that server. Set `SWB_OPENCODE_URL` to the server's local address. For a password-protected server, see the [OpenCode companion settings](https://github.com/ZhehanZhang/SwB/blob/main/src/switchboard/companion/caps/opencode.py#L225-L228).

```sh
SWB_OPENCODE_URL=http://127.0.0.1:4096 swb companion connect https://swb.example.com --cap opencode
```

The companion reads session events from the OpenCode server. Check for a `local:session:<companion>:opencode:<session>` target. Send a short test message to the target. Check the reply with `result`.

## DeepSeek [#deepseek-harness]

Use DeepSeek `0.2.2-rc.5`. A profile is a set of app settings. Install the SwB bridge in the `web` profile. The bridge sends session events to the companion.

Use a local copy of the `main` branch. Replace `/path/to/SwB` with the full path to that copy.

```sh
dsh plugin --profile web add /path/to/SwB/integrations/dsh
```

Restart DeepSeek with the `web` profile. Open a session. If you set `SWB_COMPANION_HOME`, use the same absolute path for DeepSeek and the companion.

```sh
swb companion connect https://swb.example.com --cap dsh
```

Check for a `local:session:<companion>:dsh:<session>` target. Send a short test message to the target. Check the reply with `result`.

## Apps with open sessions [#agent-tools]

Orca and Paseo use a driver, which tells the companion how to list and message open sessions. Amp uses a plugin, which adds features to Amp. Open sessions appear in `targets(block="local")`. Use the full address from the result.

### Orca [#orca]

Install the [Orca command](https://orca.dev/docs/cli/overview). Run the companion in an Orca terminal. Start the agent in a second Orca terminal.

```sh
swb companion connect https://swb.example.com --cap ade --cap hooks
```

SwB uses Orca's message system to send work and collect replies. Ask the agent to answer on the same Orca message thread. See [Orca setup](/docs/setup/orca) to connect the agent's tools.

### Paseo [#paseo]

Start the Paseo background service on the device. Open an agent session. Run the companion with the same Paseo settings.

```sh
swb companion connect https://swb.example.com --cap ade --cap hooks
```

SwB sends work to a session that is ready. It reads the reply from Paseo. See [Paseo setup](/docs/setup/paseo) to connect the agent's tools.

### Agent of Empires, Claude Squad, cmux and Emdash [#terminal-apps]

These apps use a driver too. Each setup page shows what the companion needs.

```sh
swb companion connect https://swb.example.com --cap ade --cap hooks
```

[Agent of Empires](/docs/setup/agent-of-empires) [Claude Squad](/docs/setup/claude-squad) [cmux](/docs/setup/cmux) [Emdash](/docs/setup/emdash)

### Amp [#amp]

Install Amp. Make `swb` available on Amp's command search path. Install the SwB plugin on the device that runs Amp.

```sh
swb hook amp --install-plugin
swb companion connect https://swb.example.com --cap hooks
```

Open a new local Amp thread. The plugin reports the thread's state and passes work from SwB to the thread. See [Amp setup](/docs/setup/amp) to connect the agent's tools.
