---
title: "CLI & Headless Host"
description: "Reference for the offline card toolchain, SillyTavern unroller, terminal play, Workshop CLI, and headless server."
---

> Documentation Index
> Fetch the complete documentation index at: https://tavern.piepia.space/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI & Headless Host

Run `tavern` for the command menu, or `bun run tavern` from the repository root. Use `tavern start --help` to see startup options.

## Install

| Where | Install | Update |
| --- | --- | --- |
| Android (Termux), Linux, macOS | `curl -fsSL https://github.com/piepiaspace/effect-tavern/releases/latest/download/install.sh \| sh` | `tavern update` |
| Windows (PowerShell) | `irm https://github.com/piepiaspace/effect-tavern/releases/latest/download/install.ps1 \| iex` | `tavern update` |
| Homebrew (macOS, Linux) | `brew install piepiaspace/tavern/tavern` | `brew upgrade tavern` |
| Docker | `docker run -d -p 127.0.0.1:7777:7777 -v tavern:/data ghcr.io/piepiaspace/effect-tavern` | pull the new image, recreate the container |

Run `tavern start` to open the tavern. A binary that came from Homebrew or the image refuses `tavern update` and names its package manager's command instead.

**Which build.** The install script picks the build by the loader the machine has: on Linux glibc's, then musl's, then Android's `/system/bin/linker64`. Native Termux gets the Android build; a GNU/Linux distro on the same phone and a server get the Linux one. macOS goes by architecture (a shell under Rosetta still gets arm64). Each binary carries its own asset name, so `tavern update` fetches the same build.

**Where it goes.** `$PREFIX/bin/tavern` on Termux, `~/.local/bin/tavern` elsewhere (the script says so when that is not on the `PATH`), `%LOCALAPPDATA%\Programs\tavern` on Windows. The library lives in `~/.tavern` (`TAVERN_DATA` moves it; `/data` in the container). Running the install command again replaces an older launcher and keeps the library.

**Uninstall.** A script install: `rm "$(command -v tavern)"`; `rm -r ~/.tavern` removes the library too. Homebrew: `brew uninstall tavern`.

## 0. Running the Tavern (`start`, `stop`, `status`, `update`, `doctor`)

The player's commands, the same on a phone (Termux) and on a computer. Help (`tavern --help`, `tavern <command> --help`) is in the player's language (Chinese; English with `TAVERN_LANG=en`) and fits a 48-column phone terminal.

| Command | What it does | Exit codes |
| --- | --- | --- |
| `tavern start` | Serves the page and its API. Holds the device's wake lock while it serves (Termux's `termux-wake-lock`); on a terminal, opens the page once the server answers (`--no-open` turns that off). A second `tavern start` while one serves the same library says where it runs and exits `0`. A busy port is refused with the command to try; the port never moves by itself. | `0`, `1` |
| `tavern stop` | Stops the tavern serving this data directory (found through its address file and PID) and waits for it to exit. The dev session (`vp dev`) is left to its own terminal. | `0` (also when none runs), `1` |
| `tavern status` | Instant and offline: running or not, the address, the data directory, the version. `--json` gives `{running, url?, pid?, data, version}`. | `0` running, `3` not |
| `tavern update [--yes] [--check]` | Reads the release's `release.txt`, shows the current and latest version and what changes, asks (on a terminal only), checks free space, downloads the binary's own build (the asset name stamped into it at compile) beside it, requires the new file's `--version` to answer the expected version, then renames it over the running binary. Any failure leaves the old binary in place. A tavern still serving keeps the old program until restarted. `TAVERN_MIRROR` names a mirror (an https URL or a directory). Refused from source. | `0`, `1`, `2` (no terminal and no `--yes`) |
| `tavern doctor [--verbose]` | One line per check, marked `✓`, `!` or `✗`, each with one next step: device and platform, the command's location and version, the data directory, free space against an update, the running tavern and its port, the network to the release, the device's tools, leftovers of the old launcher, and the last failed turn from `<data>/log/turns.jsonl`. | `0`, `1` (any `✗`) |

Local refusals have a plain-language explanation: what happened, the likely cause, the one next step marked `>`, what was left as it was, and one line of raw facts. Under `--json` a failure is one line on stderr: `{"error":{"code","message","next"}}`.

The server prints each model request and reply to stderr by default. Choose `tavern start --log turn` for summaries or `--log quiet` for failures. Provider errors retain their HTTP status and original text. Failed requests are recorded in `<data>/log/turns.jsonl`.

## 1. Offline Card Toolchain (`card`)

Run `tavern card <subcommand>` (`bun run tavern card <subcommand>` from source). Offline commands never open the library or call external LLM APIs.

```sh
bun run tavern card init my-card --template chat
bun run tavern card check my-card.yaml --json
bun run tavern card view my-card.yaml --stage narrate --state hp=2 --events won
bun run tavern card test my-card.yaml scenario.yaml
```

### `card init <id> [--template chat|readout|rpg|world]`
Creates `<id>.yaml` exclusively in the current directory (fails if the file already exists). Templates express the two card coordinates without pre-installing opinionated combat or romance subsystems:

| Template | `persona` Slot | Default `input` | Typical Use |
| --- | --- | --- | --- |
| `chat` | Present | `act` | One-on-one or ensemble conversation |
| `readout` | Present | `note` | Guided interactive fiction with readout bands |
| `rpg` | Absent | `act` | Action-and-dice tabletop adventure |
| `world` | Absent | `note` | Protagonist-free world simulation |

### `card check <card> [--json]`
Validates YAML syntax, `Card` schema decoding, initial rule state, static lint rules, `drawn` field meter types, per-greeting state/window previews, and section token estimates. Exits `1` on any `error` diagnostic (`0` on warnings only).

### `card view <card> [flags]`
Renders the exact prompt sections, cache breakpoints, slot origins, and `Cond` clause evaluations for a stage (`--stage narrate|direct|record|lookup`).
- `--greeting <n>`: Apply `greetings[n].do` first (`0`-based).
- `--state <k=v>`: Override field values after greeting settlement (repeatable).
- `--events <a,b>`: Supply turn events for `lore` `offer` preview.
- `--pin <id>`: Simulate player invocation of an unlocked `player: true` resource (`card:<id>` or `pack:<row>/<entry>`).
- `--persona <text>`: Override player persona prose.
- `--lore`: Include fully unlocked lore entries with no active window.
- `--hat <file.hat.json>`: Wear an exported hat: its messages, and on `narrate` its delivery tool (name, description, parameter) and, under its wrap, the description carrying the story context.

### `card test <card> [scenario.yaml]`
Executes the full runtime `Session` against the deterministic `fake` model at zero token cost. Omitting `scenario.yaml` runs a one-turn smoke check.

```yaml
seed: 42 # first roll uses seed + 1, incrementing by 1 per roll
greeting: 0
steps:
  - text: 向前走
    replies:
      narrate: ["你走到了门口。"]
      record:
        - notes: 已到门口
          options: []
    expect:
      events: []
      windows: []
      lore: []
      end: end
      products: { notes: 已到门口 }
```

## 2. Unrolling SillyTavern Cards (`card unroll`)

`tavern card unroll` inspects SillyTavern PNG (`ccv3` / `chara` chunks) or V2/V3 JSON exports in ST's assembly order without mutating files or calling models:

```sh
bun run tavern card unroll card.png --user 李
bun run tavern card unroll card.json --json
```

Paragraph boundaries are preserved so Markdown output can feed directly into `tavern card sort`.

## 3. Host, Workshop & Story CLI (`tavern`)

Run `bun run tavern <subcommand>` from the repository root (`packages/server/bin/tavern.ts`).

- **Finding the library (default):** The data directory is `--data`, else `TAVERN_DATA` (legacy `DATA`), else `~/.tavern` for the compiled binary and `./.tavern` from source; the root `bun run tavern` script sets `TAVERN_DATA=.dev`, the dev server's library. When a running `tavern start` or `vp run dev` holds that library, it has written its address beside the lock (`tavern.db.address`) and the command goes through it over HTTP/SSE, saying so on stderr. When nobody holds it, the command opens `<data>/tavern.db` itself and answers its own requests with the same handler, in-process. A live owner that never says its address within about two seconds is exit code 3 naming its PID; `MODEL=fake` meeting a tavern on a real model is exit code 3 too.
- **Another machine (`--server`):** Pass `--server http://192.168.1.20:7777` (or set `TAVERN_SERVER`) to talk to that tavern over HTTP/SSE; no local file is read.
- **Anywhere on the line:** `--json`, `--data <dir>`, `--server <url>`, `-h/--help`, `-V/--version`. Exit codes: `0` done, `1` refused or failed, `2` the command line was wrong, `3` the library cannot be reached.

```sh
# The shelf: a new library has no cards. Install from a file, list, export, remove
bun run tavern card install ./my-card.yaml     # over the card of that id, when there is one
bun run tavern card install https://example.com/cards/my-card.yaml   # one card by its own link
bun run tavern card list
bun run tavern card export my-card -o my-card.yaml
bun run tavern card remove my-card             # refused while the card has stories

# Card libraries: an optional place to take cards from (a directory or https URL holding index.json)
bun run tavern depot add https://example.com/cards/
bun run tavern depot add ./my-cards            # a directory: local library mode only
bun run tavern depot list
bun run tavern depot show <library-id>         # its cards, each against the shelf
bun run tavern depot pull <library-id> <card>  # copy one onto the shelf; --replace to update
bun run tavern depot remove <library-id>       # the cards taken from it stay

# Workshop operations
bun run tavern card compile ./my-card.yaml --select fiction.setting --intent "Add a bond readout" -o candidate.yaml
bun run tavern card sort ./my-card.yaml ./notes.md -o candidate.yaml
bun run tavern card review ./my-card.yaml --json

# Story lifecycle
bun run tavern story list --json
bun run tavern story new my-card
bun run tavern story show 1
bun run tavern story export 1 --format md > story.md
bun run tavern story remove 1

# Server (API only with --headless) and the compiled binary (bin/tavern.ts with the built page inside)
MODEL=fake bun run tavern start --headless --port 7777
cd packages/server && bun run compile && ./dist/tavern --version
```

## 4. Terminal Play (`tavern play`)

Pass a numeric story ID to resume an existing story, or an installed card's ID to create a new story (add `--card` to force card ID interpretation for numeric card names). Supports interactive readline, single-shot `--input`, stdin pipes, `--user <name>` (persisting `{{user}}` on the card for this and subsequent stories), and `--jsonl` event streaming:

```sh
MODEL=fake bun run tavern play my-card --greeting 1 --set bond=3 --user "陆沉" --note "雨夜初见"
```

| Slash Command | Action |
| --- | --- |
| `/greet [index]` | Start a root opening (`0` by default) |
| `/act <text>` / `/note <text>` | Send on the `act` or `note` channel |
| `/pin <resource-id>` | Arm a context resource (`card:guide`, `pack:p/entry`) for the next turn |
| `/set <field=value>` | Apply `setField` on the current node |
| `/swipe [node]` / `/reword [note]` | Create a `swipe` or `reword` sibling |
| `/checkout <node\|root>` | Move `head` to a branch's newest leaf or empty root |
| `/tree` / `/context` / `/detail [node]` | Inspect log tree JSON, active `WorldState`, or turn deltas |
| `/inspect [node]` | Print recorded LLM call traces (honors server `inspect` gate) |
| `/attach` / `/stop` / `/quit` | Re-attach in-flight turn, stop active generation, or exit cleanly |

Source: https://tavern.piepia.space/cli/index.mdx
