# Run phases

Start a run with yokai or yokai --once, set limits so it can run unattended, continue after a stop, and read the ledger to see what happened.

## Start

From the repository root of a prepared project:

```bash
yokai --once     # run one phase, then exit
yokai            # run phases until a halt or the end of the board
```

Without `--once`, Yokai keeps going on its own, phase after phase. You do not need to watch. When it needs you it stops and shows why. To run without the cockpit, on a server or in CI, add `--headless` or see [Run on its own](/en/docs/koi/autonomous).

Each unfinished card needs a reviewed tier, and the gate needs a review that matches the current scripts. If either is missing, an interactive launch opens [setup](/en/docs/yokai/preparation); `--headless` stops with a message.

Yokai stops at a card with `"gated": true`. To authorize gated phases for this launch only:

```bash
yokai --allow-gated
```

Standing overrides in `CONTEXT.md` still apply. Nothing you do in setup counts as that authorization.

## Limits for one launch

```bash
yokai --max-iters 3        # Build iterations per phase
yokai --max-cost 5.00      # stop before a turn once $5 is spent
yokai --max-tokens 2000000 # the same, in tokens, when the agent reports no cost
```

The cost and token ceilings exist only as flags. Before each turn Yokai sums the ledger and halts if the ceiling is reached. A turn already running can go past it. Leave both out for no ceiling.

`--max-iters` overrides `build.max_iters` from the settings. Settings resolve as: built-in defaults, then `.koi/yokai.yml`, then `.koi/run/yokai.yml`, then flags.

## Pin an agent for one launch

```bash
yokai --agent claude --model opus --effort high
```

These flags build one candidate for every turn and skip the tier lists. Leave them out to use the [tiers](/en/docs/architecture/models).

## Permissions

| `--permission` | Effect |
| --- | --- |
| `approve-all` | Approve every tool request (default) |
| `approve-reads` | Approve reads, deny writes |
| `deny-all` | Deny everything, a dry run |

The safety net for unattended work is the gate and Git, not prompts.

## After a stop

A run continues from the files on disk, so a stop loses nothing that was verified. If you stopped a phase with `x`, press `r` in the cockpit. After a halt, fix the cause and launch again. If you closed the terminal or the machine restarted, run `yokai` again in the same repository. It reads the card status: a `building` card continues in Build, a `sealing` card continues in Seal. An interrupted agent turn can reattach to its session through `.koi/run/live-session.json`.

There is no `--resume` flag. Launching again is how a run continues. See [When a run stops](/en/docs/koi/resume).

## Sessions and token savings

By default each agent turn gets a fresh session and reads what it needs from disk. With token savings, a phase keeps two sessions: one for planning, coding and sealing, one for reviews.

```bash
yokai --token-savings      # this launch
yokai --no-token-savings   # override a saved true
```

Token savings always runs the judge and forbids the agent from delegating to subagents. The next phase starts new sessions. See [Configure Yokai](/en/docs/yokai/configuration#token-savings).

## Read what happened

`.koi/run/ledger.jsonl` has one row per phase run:

```json
{"phase":"P2","agent":"claude","model":"sonnet","session_id":"...","tokens":131526,"cost_usd":0.41,"gate_passed":true,"advanced":true,"commit_made":true,"head_before":"07fe780...","head_after":"7e534a0...","ended_at_unix":1790357649}
```

Skip rows (`"kind": "skip"`) record a candidate that could not open a session; totals ignore them.

```bash
jq -r 'select(.kind != "skip") | "\(.phase) gate=\(.gate_passed) commit=\(.commit_made) $\(.cost_usd // 0)"' .koi/run/ledger.jsonl
jq -s 'map(select(.kind != "skip") | .cost_usd // 0) | add' .koi/run/ledger.jsonl
```

`.koi/run/sessions.jsonl` has one row per agent turn, with the act, the iteration and the role. `consolidate` deletes both files; copy them first if you want them outside Git.

In headless mode the exit code tells you the result: `0` when the run advanced or completed, `2` on a halt. Yokai sends no notifications; wire the exit code to your own alert if you want one ([recipes](/en/docs/koi/autonomous#recipes)).

## What can go wrong

| Message or symptom | What to do |
| --- | --- |
| Preflight fails at launch | Run `yokai doctor --probe` |
| Missing or incomplete phase assessment | Approve the tier and reason in `yokai setup` |
| Halt at a gated phase | Expected. Review the phase, then use `--allow-gated` if you approve it |
| `cost ceiling reached` | Raise or drop `--max-cost` / `--max-tokens` |
| Every candidate skipped | Fix the agent's login or quota, or wait `retry_after_secs` (3600 by default) |
| Gate red on every phase | Run each sensor by hand; see [Sensors](/en/docs/yokai/sensors) |

More in [Run troubleshooting](/en/docs/yokai/troubleshooting).
