Metadata-Version: 2.4
Name: stagehands
Version: 0.2.0
Summary: Manage coding agents across repositories and resume their native conversations.
License-Expression: MIT
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: PyYAML>=6.0.2
Dynamic: license-file

<h1 align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="docs/assets/stagehands-logo-dark.svg">
    <img alt="stagehands" src="docs/assets/stagehands-logo.svg" width="420">
  </picture>
</h1>

stagehands manages coding agents across Git repositories and keeps an exact binding to their native conversations. This MIT-licensed CLI supports local Codex and Claude Code sessions and explicit handoffs. It runs on macOS and Linux with Python 3.11+, Git, and at least one installed provider CLI.

[User guide](docs/guide.md) · [Video walkthrough](#reuse-a-workflow)

## Terminal workspace

```sh
stagehands board
stagehands board cache-fix
```

The board opens in tmux. The **Orchestrator** pane shows your agents, their current activity, assignments, explicit routes, and inbox. Each role has a separate live pane showing its provider, selected model, task, and output.

![The tmux workspace shows the Orchestrator, implementer, reviewer, and test roles in separate panes.](docs/assets/tmux-workspace.png)

- **N** adds a role and asks for its provider, model, assignment, and Git checkout. A new role starts inactive.
- **E** edits the selected role's assignment and model. The model selection applies to the next turn and keeps the same native conversation ID.
- **U** starts the role. Its saved assignment becomes its first prompt unless a handoff is ready to deliver.
- **S** sends a follow-up. **D** stops the role while retaining its worktree and conversation. **Enter** focuses its pane.
- **A** opens the selected role's live Activity view. See commands, file edits, approvals, turn results, and handoffs as the provider reports them. Use the arrow keys to scroll, **End** to jump to the latest activity, and **Esc** to go back.
- **R** opens the role's Git diff. Press **C** there to read GitHub PR checks for the branch. [Review a role](docs/guide.md#review-a-role)
- **T** filters to roles that need attention. **I** shows the selected role's usage and any allowance the provider reported. [Activity and usage](docs/guide.md#activity-and-usage)
- **P** opens the selected role's pending approval. Read the request and choose **Approve** or **Deny**. [Board controls](docs/guide.md#board-controls)
- **X** archives the selected task after confirmation. Reopen it with `stagehands task restore TASK`. [Workspace setup and archive](docs/guide.md#workspace-setup-and-archive)
- **?** opens shortcut help. Prompts, assignments, and handoff messages wrap and support multiline paste. **Ctrl+N** adds a new line and **Enter** submits.
- **L** creates a directional link. The board shows an **AGENT** sender for native tool handoffs or **OPERATOR** for a handoff you initiate.
- **W** sets the selected role's wake mode. Automatic wake requires an eligible recipient and a link set to wake on handoff.
- **Ctrl+b d** detaches the view. The daemon keeps the agents running.

![The Activity view shows a file change, a test command, and a completed turn.](docs/assets/board-activity.webp)

Use `stagehands board --detach` to create the workspace and print its tmux attach command. The board requires tmux. The remaining CLI commands work from an ordinary terminal.

The same model and assignment settings are available through the installed CLI. [Edit a role on the board (15 sec)](docs/assets/tmux-setup.mp4)

```sh
stagehands role configure cache-fix/reviewer --model sonnet \
  --assignment 'Review the implementer’s diff for compatibility regressions.'
```

## Install

```sh
uv tool install stagehands    # or: pipx install stagehands
stagehands doctor
stagehands daemon start
```

To install from source instead:

```sh
git clone https://github.com/duriantaco/stagehands.git
cd stagehands
python3 -m venv .venv
.venv/bin/python -m pip install .
source .venv/bin/activate
```

Sign in to each provider using its native CLI. stagehands starts `codex app-server` or Claude's headless CLI with the saved configuration directory. Codex 0.172.0 app-server mode and Claude Code 2.1.332 headless mode report a compatibility error for unsupported named profiles. Use `CODEX_HOME` or `CLAUDE_CONFIG_DIR` before starting a daemon to select a separate provider configuration directory. [Codex app-server protocol](https://learn.chatgpt.com/docs/app-server) · [Claude CLI reference](https://code.claude.com/docs/en/cli-reference)

## Reuse a workflow

[![Workflow tutorial showing an implementer and reviewer in two separate repositories.](docs/assets/tutorial-poster.webp)](docs/assets/workflow-tutorial.mp4)

[Watch the multi-repo workflow (3 min 26 sec)](docs/assets/workflow-tutorial.mp4) · [English captions](docs/assets/workflow-tutorial.vtt)

Run these commands from the repo you want the agents to work in. `workflow init` creates `stagehands.yaml` in the current directory. Edit the generated task name, prompts, and expected outcomes before applying it. [Generated example](examples/workflow.yaml)

```sh
stagehands repo add app .
stagehands workflow init --repo app
stagehands workflow apply
```

Open the board for the task named in the file and press **U** to start a role. Applying the file prepares roles and links. Each role gets its prompt and expected outcome as its saved assignment.

```yaml
task: checkout-v2
repo: app
agents:
  implementer:
    provider: codex
    prompt: Fix checkout validation and run the tests.
    expected_outcome: The validation tests pass and the diff is ready for review.
  reviewer:
    provider: claude
    prompt: Inspect checkout validation and flag compatibility risks.
    expected_outcome: A list of risks with supporting file references.
```

Set `repo` under an agent to choose its primary repo. You can also supply a default with `workflow apply --repo app` or pass a different YAML file as a positional argument.

Give one role several worktrees with `extra_repos: [api, docs]` under that agent, or repeat `--extra-repo` when setting up a new role from the CLI. [Several repos for one role](docs/guide.md#several-repos-for-one-role)

Roles run independently on a new task by default. To give the implementer a route to the reviewer, add this to the same file.

```yaml
handoffs:
  - from: implementer
    to: reviewer
    wake: manual
```

The link lets you send a handoff with **H** on the board. You can also ask a managed Codex role to send one using its handoff tool. With manual wake, the handoff waits in the reviewer's inbox until you start the role. Use `wake: on-handoff` to let an incoming handoff start an eligible recipient. The recipient gets the handoff along with its saved assignment. Applying the YAML reuses matching roles and links. Use the board or CLI to change existing roles and routes.

## Work on a task

Register a local Git repository. This creates no agent or worktree. Run `stagehands up` for the terminal picker, or specify the task and role directly.

```sh
stagehands repo add cli ~/src/my-cli
stagehands up cache-fix/implementer --repo cli --provider codex \
  --prompt 'Find why changes to imported modules can leave the scan cache stale.'
```

The short form records the task and role and provisions its Git worktree. For an existing role, `up` uses its saved provider and checkouts. Defining roles with `task new` and `role add` leaves them unstarted. Use `--worktree existing` for the registered checkout, a registered worktree path to select it directly, or `role add --checkout-of TASK/ROLE --access read` to share an exact checkout. Codex confirms its read-only sandbox for a read-only role.

In another terminal:

```sh
stagehands ps --watch
stagehands watch cache-fix/implementer --follow
```

Pressing Ctrl-C in the watcher detaches it. Use `--json` for finite output, or `--jsonl --after SEQUENCE` with `watch --follow` to replay from a cursor and continue live.

```sh
printf '%s\n' 'Check which tests cover that case.' |
  stagehands send cache-fix/implementer --stdin --request-id cache-tests-1
stagehands approvals
stagehands inspect cache-fix/implementer
stagehands down cache-fix/implementer
stagehands daemon stop
stagehands daemon start
stagehands resume cache-fix/implementer --detach
```

`down` keeps the worktrees and exact native ID, reports Git changes for the primary repo, and stops turn delivery. Send with `--queue` to leave a message for a stopped conversation. Use `up` to reopen it and drain its queued prompts, or `resume` to reopen without submitting a prompt. `interrupt` cancels the active turn. `history` and `inspect` read local state without launching a provider. Press **P** on the board or use `approve ID` or `deny ID` in the CLI to answer a pending native permission request.

## Open a native conversation directly

```sh
stagehands native cache-fix/implementer --print-command
stagehands native cache-fix/implementer --release
```

The command contains the exact native ID, checkout, and saved Codex configuration directory. Use `--release` before running it in another terminal so the daemon releases the session. In Codex's picker, use `codex resume --all --include-non-interactive` to include app-server conversations. Codex 0.172.0 can reopen a new thread directly before its first prompt, while the picker lists it after a user turn is recorded.

Claude has a reserved UUID before its first turn. That turn creates its native history and sets the friendly label. Afterward, `native` prints the exact `claude --resume` command with the original checkout and Claude configuration directory.

If the original conversation cannot be opened, the error includes its saved ID, checkout, and profile. `session relink TASK/ROLE --native-id ID` validates a replacement before changing the mapping. `session fresh TASK/ROLE` explicitly creates a new conversation. `session import TASK/ROLE --native-id ID` binds a native chat whose original checkout matches the role. Old bindings and their queued messages stay associated with the old session.

## Connect independent roles

[Watch a handoff from Codex to a Claude Code reviewer (45 sec)](docs/assets/tmux-workspace.mp4)

```sh
stagehands role add cache-fix/reviewer --provider claude \
  --checkout-of cache-fix/implementer --access read
stagehands link cache-fix/implementer cache-fix/reviewer --on handoff --wake manual
stagehands handoff cache-fix/implementer cache-fix/reviewer \
  --message 'Review the cache invalidation change and check the stale-cache case.' \
  --diff --request-id cache-review-1
stagehands inbox cache-fix/reviewer
stagehands up cache-fix/reviewer
```

Roles start with zero links. This route sends the message and selected diff in one direction. With manual wake, the handoff remains in the inbox until the operator starts the recipient. Use `--file`, `--test-result`, or `--ci-url` for other evidence. Claude's restricted tool inventory is verified in read-only roles. `inspect` distinguishes that provider restriction from Codex's read-only sandbox.

For automatic wake, set the target's `role activation` to `on_event` and the link's wake policy to `on-handoff`. An explicit `down`, a disabled role, or `automation pause TASK` blocks automatic dispatch. A handoff bound to a conversation stays with that conversation after a replacement. Managed Codex threads started with the handoff tool can submit a scoped handoff over an enabled route.

## Local state and verification

By default, the daemon stores data under `${XDG_STATE_HOME:-~/.local/state}/stagehands`. Set `STAGEHANDS_HOME` to an isolated state directory for a test. The daemon opens a private Unix socket and stores bindings, turns and ordered events in SQLite WAL mode. A daemon restart leaves stopped roles stopped and records interrupted in-flight turns.

```sh
python3 -m unittest discover -s tests -v
```

The test suite includes real daemon subprocesses, named Unix sockets, and deterministic provider fixtures. Installed CLI acceptance also ran on Linux with Codex 0.172.0 and Claude Code 2.1.332 against isolated loopback model endpoints. It checked exact native recall after restart, CLI-level approvals and interruption, and shared-checkout handoffs.

Run `python3 examples/verify_codex.py --provider codex` or `--provider claude` with the installed command on PATH to test live recall in two temporary worktrees. It submits turns through the daemon, restarts it, renames one task, reopens the conversations in reverse order, and checks recall through the native CLI by exact ID.
