# Run on its own

Leave the phases running. /junji goal runs them in your agent's chat; yokai --headless runs them in a terminal, on a server or in CI. Either way, Koi stops and shows why when it needs you.

Once the plan is agreed and the phases are on the board, you do not need to stay. Two things can run the phases on their own. Both read the same `.koi/run/`, both check every phase before the next one starts, and both stop the same way: when they need a person, they stop and show why.

## Two ways to run

| | `/junji goal` | `yokai --headless` |
| --- | --- | --- |
| Where it runs | In your agent's chat | In a terminal, on a server or in CI |
| Each phase | A fresh child runs `/junji next --subagent` | Plan, Build and Seal, each in fresh agent sessions |
| Checks | The child runs the verification bar | Yokai runs the reviewed sensor scripts itself, and a read-only judge reviews the change |
| On a miss | Stops. It never retries | Recovery repairs or diagnoses the miss and tries again (on by default) |
| Budget | None | `--max-cost`, `--max-tokens`, `--max-iters` |
| Needs | Junji, and an agent with long-running goals and subagents | A fully prepared project: `yokai setup` once, checked with `yokai doctor` |
| Tells you | A report in the chat | Exit code `0` or `2`, and the reason on stderr |

Neither runs `/junji iterate` or `/junji consolidate`. When the board is empty, both point at `/junji consolidate` and stop. Closing the run is always yours.

Pick `goal` when you are already in the chat and want the lighter path. Pick Yokai when the run is long, when it should not depend on your chat staying open, or when you want a judge, recovery and a cost ceiling.

## In your agent's chat: /junji goal

```text
/junji goal --until P3
```

Junji asks your agent for its long-running goal tool and hands it one objective: run the runnable phases one by one. For each phase, the agent starts a fresh child with `/junji next --subagent`, waits for its report, then reads the board again. The goal stops:

- after the phase named in `--until`, which is included;
- at a red check, a gated phase, or a child that fails;
- when no runnable phase is left. It then points at `/junji consolidate`.

It never retries a phase. If your agent has no goal or subagent tool, `goal` says so and changes nothing. Your agent has to stay open while the goal runs.

Two more options:

- `--allow-gated` authorizes every gated phase in this goal, subject to the standing overrides in `CONTEXT.md`.
- `--review` adds a review loop: run the phases, review the branch with `/junji review`, run the fix phases it adds, review again. It stops on approval, on a halt, or after three review rounds.

The [goal reference](/en/docs/junji/goal) has the details.

## In a terminal, on a server or in CI: yokai --headless

Headless never opens setup and never writes defaults. Prepare the project once in an interactive terminal with `yokai setup`: reviewed sensors, a tier and reason for every unfinished phase, saved settings. Then check it on the machine that will run:

```bash
yokai doctor
yokai --headless --max-cost 25
```

Each phase runs Plan, then a Build loop, then Seal. In Build, a coder turn changes the code, Yokai runs the sensors, and a read-only judge reviews the change. The judge can send the coder back for another iteration but never declares a phase done; only the sensors do. Seal records the outcome and makes one commit. Yokai then checks the result on disk: the card is `done`, there is a new commit, the gate is green and the tree is clean. If not, recovery repairs the bookkeeping or diagnoses the miss and tries again. Yokai moves from phase to phase until a halt or the end of the board.

You do not always need `--headless`. Any launch whose stdin or stdout is not a terminal runs headless too: a CI job, a pipe, `nohup`.

| Flag | Effect |
| --- | --- |
| `--once` | Run one phase, then exit |
| `--max-cost <usd>` | Halt before a turn once the run has spent this much. A turn already running can go past it |
| `--max-tokens <n>` | The same in tokens, for agents that report no cost |
| `--max-iters <n>` | Build iterations per phase |
| `--allow-gated` | Authorize gated phases for this launch. Standing overrides still apply |
| `--permission <mode>` | `approve-all` (the default), `approve-reads` or `deny-all` |

Recovery has no cycle limit of its own. For an unattended run, set `--max-cost` or `--max-tokens` so the run has a brake.

When it ends, the exit code says how:

- `0`: no runnable phase is left, or `--once` advanced one phase.
- `2`: a halt. The reason is on stderr, after `⚠ halt —`.
- `141`: whatever read stdout closed the pipe, for example `| head`. Yokai stops the run, kills the agent and exits without a message. The next launch picks the phase up again. To keep a run going without a reader, write to a file, as in the `nohup` recipe below.
- Any other non-zero code: Yokai could not start, for example because preparation is missing or preflight failed. No phase ran.

More flags are in [Run phases](/en/docs/yokai/run) and [Cockpit and headless](/en/docs/architecture/interfaces).

## Recipes

### Leave it running overnight

In `tmux` you keep the cockpit and can look in whenever you like:

```bash
tmux new -s koi 'yokai --max-cost 25'
```

Detach with `Ctrl-b d` and attach again with `tmux attach -t koi`. At a halt the cockpit stays open with `HALT` and the reason.

Without `tmux`, run it in the background and keep a log:

```bash
nohup yokai --headless --max-cost 25 > yokai.log 2>&1 &
```

### Get your own alert on a halt

Koi sends no notifications. The exit code is the signal, and you can wire it to anything you already use. On macOS:

```bash
yokai --headless --max-cost 25 \
  || osascript -e 'display notification "yokai stopped. Read the reason." with title "koi"'
```

Or post to a webhook you own:

```bash
yokai --headless --max-cost 25 > yokai.log 2>&1
status=$?
if [ "$status" -ne 0 ]; then
  curl -fsS -X POST -H 'Content-Type: application/json' \
    -d "{\"text\":\"yokai exited with $status\"}" "$MY_WEBHOOK_URL"
fi
```

Both catch every non-zero exit. A halt (`2`) and a failed start both need you.

### Run in CI

A sketch for GitHub Actions. The run's branch must already hold a prepared `.koi/`, committed. Adapt the install and sign-in steps to your agent.

```yaml
name: koi
on: workflow_dispatch
jobs:
  phases:
    runs-on: ubuntu-latest
    timeout-minutes: 360
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
        with:
          ref: koi/orders-export
      - name: Install koi, yokai and your agent
        run: |
          # the koi installer from the Install page, then:
          koi setup --yes
          # install and sign in your coding agent here
      - name: Git identity for the phase commits
        run: |
          git config user.name "koi"
          git config user.email "koi@users.noreply.github.com"
      - name: Run the phases
        run: yokai --headless --max-cost 25
      - name: Push what passed
        if: always()
        run: git push
```

The job fails on a halt, so the failed run is your signal. Its log shows the reason. Commits from phases that passed are pushed either way.

## Where you come in

- **A gated phase.** You marked it as needing your approval. Read the phase, then authorize it: `yokai --allow-gated`, `/junji goal --allow-gated`, or approve it in the chat with `/junji next`. Preparing Yokai or importing a plan never counts as approval.
- **A halt.** Read the reason, fix the cause, and launch again. The run continues from the card status. See [When a run stops](/en/docs/koi/resume).
- **A judge that keeps saying no.** Its findings go to `.koi/run/FEEDBACK.md` and drive another Build iteration. You see them only if the run then halts, for example at the cost ceiling.
- **The end of the board.** Try the change yourself. Add work with `/junji iterate`, or close the run with `/junji consolidate`. Consolidation always needs a person.

## Cards to read next

- [![](/art/verbs/goal-card.webp) goal · Run phases in sequence](/en/docs/junji/goal)
- [![](/art/verbs/yokai-card.webp) Yokai · Run prepared phases](/en/docs/yokai)
