# First run

Plan a change in an existing repository with Junji, run the first phase, and optionally hand the rest to Yokai.

This page assumes you have [installed](/en/docs/koi/install) the Junji skill. Starting from an empty repository? Follow the [walkthrough](/en/docs/koi/greenfield) instead.

## Plan and run with Junji

Open your coding agent at the repository root and run these verbs in order. They are messages to the agent, not shell commands.

```text
/junji begin
/junji plan Add CSV export to the orders page. Done when a user can download every order, including later pages, and the file opens in a spreadsheet.
/junji refine
/junji next
```

1. `begin` creates `.koi/run/` and records what it finds: languages, build and test commands, skills. It decides nothing.
2. `plan` asks you questions until the change is pinned down, then writes `PLAN.md` and the verification bar in `CONTEXT.md`: the commands every phase must pass.
3. `refine` splits the plan into phases, saved as cards in `.koi/run/BOARD.json`, and marks irreversible ones as gated.
4. `next` runs the first phase: it writes the phase plan, implements it, runs every command in the bar and commits.

Check the result before you continue:

```bash
git log -1 --stat
cat .koi/run/BOARD.json
```

The first card should show `"status": "done"` with a short outcome, and `nextAction` should be `/junji next`. If the first phase looks right, let the rest run on its own with `/junji goal`. It runs each remaining phase in a fresh subagent and stops at a red check, a gated phase, or the end of the board. You can also keep running `/junji next` one phase at a time. See [Run on its own](/en/docs/koi/autonomous).

When every phase is done, try the change yourself. To add more work, use `/junji iterate <request>`. When you accept the result, `/junji consolidate` writes the final document to your repository and removes `.koi/run/`.

## Hand the remaining phases to Yokai

With [Yokai installed](/en/docs/koi/install#3-install-yokai-optional) and the agent signed in, run this from the same repository:

```bash
yokai setup --once
```

Setup opens a wizard with five steps:

1. Configuration. Choose One model or Use tiers, then the agent, the model and the environment (host or sandbox).
2. Environment. Yokai checks the host or sandbox. A sandbox that needs a new image waits for you to approve the build.
3. Checks. Yokai proposes sensor scripts from your verification bar, or opens existing ones. Read them, then choose Approve and test. It saves the checks only if every one passes.
4. Phases. Yokai proposes a model tier and a reason for each unfinished phase. Choose Approve and continue.
5. Review and start. Choose Start run. Save and exit keeps the settings without starting a phase.

`--once` runs a single phase and stops, so you can inspect the first commit. Once you trust it, a bare `yokai` reuses the saved settings and runs the remaining phases on its own until a gated phase, a halt, or the end of the board. `yokai --headless` does the same without the cockpit.

```bash
yokai                   # run the remaining phases with saved settings
yokai setup             # reopen the wizard
yokai doctor --probe    # check tools and the agent's login
```

The machine running Yokai does not need the Junji skill. Yokai reads the files Junji wrote.

## What can go wrong

- `plan` keeps asking questions. That is the point: it stops when no open question could change the implementation. Answer them, or say which ones to defer.
- A command in the bar fails during `next`. The phase stays `building` and nothing is committed. Fix the cause in the same chat, or run `next` again. Junji never weakens the bar to pass.
- Setup reports a missing check, such as "no test command". Add the real check to the project, often as its own phase with `/junji next`, then return to setup. Yokai will not invent a passing script.
- Yokai halts at a gated phase. That is the default. Review the phase, then relaunch with `--allow-gated` if you approve it.

## Cards to read next

- [![](/art/verbs/refine-card.webp) refine · Order the phases](/en/docs/junji/refine)
- [![](/art/verbs/next-card.webp) next · Run the first phase](/en/docs/junji/next)
