# Work across sessions

Every Koi session starts with an empty context window. It finds the plan, the last result and the next step in .koi/run/, does one unit of work, and writes back what the next session needs. That is what lets a run go on unattended.

## The folder is the memory

Junji's rule is short: the filesystem is the durable memory, and the context window is a disposable cache. A session can be thrown away at any point. The next one rebuilds its picture of the project by reading `.koi/run/`.

This is what lets a run go on without you. Nobody keeps one long chat alive and compacts it. `/junji goal` starts a fresh child for each phase, and Yokai opens a new agent session for each turn. Nothing important lives only in a transcript, so a run can span as many sessions as it needs.

<figure class="diagram" aria-labelledby="dg-handoff-caption">
<figcaption id="dg-handoff-caption">Sessions never talk to each other</figcaption>
<div class="diagram-frame" tabindex="0" role="region" aria-labelledby="dg-handoff-caption">
<svg viewBox="0 0 560 280" width="560" height="280" role="img" aria-labelledby="dg-handoff-title dg-handoff-desc">
<title id="dg-handoff-title">Three sessions hand work over through the repository</title>
<desc id="dg-handoff-desc">Session 1 runs in Claude Code and writes its outcome to the repository. Its context is then discarded. Session 2 runs in Codex: it reads the repository, continues, and writes back. Session 3 is Yokai, which does the same. The sessions have no direct connection; each one reads from and writes to the repository's .koi/run/ folder and Git history.</desc>
<defs><marker id="dg-handoff-head" viewBox="0 0 8 8" refX="7" refY="4" markerWidth="8" markerHeight="8" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path class="dg-head" d="M0 0 8 4 0 8z"/></marker></defs>
<rect class="dg-box" x="0" y="24" width="200" height="48" rx="4"/>
<text class="dg-label" x="100" y="48">Session 1 · Claude Code</text>
<rect class="dg-box" x="0" y="120" width="200" height="48" rx="4"/>
<text class="dg-label" x="100" y="144">Session 2 · Codex</text>
<rect class="dg-box" x="0" y="216" width="200" height="48" rx="4"/>
<text class="dg-label" x="100" y="240">Session 3 · Yokai</text>
<path class="dg-line is-dashed" d="M100 76V116" marker-end="url(#dg-handoff-head)"/>
<text class="dg-note is-start" x="116" y="96">context discarded</text>
<path class="dg-line is-dashed" d="M100 172V212" marker-end="url(#dg-handoff-head)"/>
<text class="dg-note is-start" x="116" y="192">context discarded</text>
<path class="dg-line" d="M204 48H356" marker-end="url(#dg-handoff-head)"/>
<text class="dg-note" x="280" y="32">writes outcome</text>
<path class="dg-line" d="M204 144H356" marker-start="url(#dg-handoff-head)" marker-end="url(#dg-handoff-head)"/>
<text class="dg-note" x="280" y="128">reads, then writes</text>
<path class="dg-line" d="M204 240H356" marker-start="url(#dg-handoff-head)" marker-end="url(#dg-handoff-head)"/>
<text class="dg-note" x="280" y="224">reads, then writes</text>
<rect class="dg-box is-solid" x="360" y="24" width="200" height="240" rx="4"/>
<text class="dg-label is-reverse" x="460" y="132">Repository</text>
<text class="dg-label is-reverse" x="460" y="156">.koi/run/ and Git</text>
</svg>
</div>
</figure>

## What a new session reads

A fresh session reads these files, in this order, before it touches code:

1. `.koi/run/BOARD.json`. The `nextAction` field holds the command to run next, such as `/junji next`. The `tasks` array lists the phases in order, each with a `status`.
2. `.koi/run/NOTES.md`. Carry-forward decisions: facts a later phase depends on, like "the date column is stored as text, parse it in the mapper".
3. `.koi/run/CONTEXT.md`. The binding facts: what the project is, locked decisions, standing overrides such as "commit locally, never push", and the verification bar, which lists the exact commands that must pass.
4. `.koi/run/phases/phase-NN-<slug>.md` for the phase in progress. Its Outcome section records what the last session verified.
5. `.koi/run/METHOD.md`. The per-phase protocol, copied byte for byte from the Junji templates by `begin`.

A session running a phase does not need `PLAN.md`. The plan explains why. `CONTEXT.md` says what is binding, and it wins when the two disagree.

## A card's life on the board

Each phase is one card in `BOARD.json`:

```json
{
  "id": "P2",
  "title": "Persist tasks in localStorage",
  "status": "todo",
  "description": "Save tasks on change, load on start, recover from invalid stored data. depends_on: P1.",
  "gated": false
}
```

The `status` field moves through five values. Junji's `next` and Yokai write the same values, so either tool can pick up a phase the other started. Junji's `next` and Yokai's Seal turn move the card with `koi board move`, the same board code Yokai uses; when `koi` is missing, Junji asks you to install it, and an unattended Yokai turn (for example in the sandbox) edits the same fields directly.

<figure class="diagram" aria-labelledby="dg-card-caption">
<figcaption id="dg-card-caption">A card moves through five states</figcaption>
<div class="diagram-frame" tabindex="0" role="region" aria-labelledby="dg-card-caption">
<svg viewBox="0 0 560 168" width="560" height="168" role="img" aria-labelledby="dg-card-title dg-card-desc">
<title id="dg-card-title">Card status from todo to done</title>
<desc id="dg-card-desc">A card starts as todo. It becomes planning during the Plan act, building during the Build act and sealing during the Seal act, then done. If the gate fails after Seal, the card goes back to todo so the next launch runs the phase again.</desc>
<defs><marker id="dg-card-head" viewBox="0 0 8 8" refX="7" refY="4" markerWidth="8" markerHeight="8" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path class="dg-head" d="M0 0 8 4 0 8z"/></marker></defs>
<rect class="dg-box" x="0" y="24" width="80" height="48" rx="4"/>
<text class="dg-label" x="40" y="48">todo</text>
<path class="dg-line" d="M84 48H116" marker-end="url(#dg-card-head)"/>
<rect class="dg-box" x="120" y="24" width="80" height="48" rx="4"/>
<text class="dg-label" x="160" y="48">planning</text>
<path class="dg-line" d="M204 48H236" marker-end="url(#dg-card-head)"/>
<rect class="dg-box" x="240" y="24" width="80" height="48" rx="4"/>
<text class="dg-label" x="280" y="48">building</text>
<path class="dg-line" d="M324 48H356" marker-end="url(#dg-card-head)"/>
<rect class="dg-box" x="360" y="24" width="80" height="48" rx="4"/>
<text class="dg-label" x="400" y="48">sealing</text>
<path class="dg-line" d="M444 48H476" marker-end="url(#dg-card-head)"/>
<rect class="dg-box" x="480" y="24" width="80" height="48" rx="4"/>
<text class="dg-label" x="520" y="48">done</text>
<text class="dg-note" x="160" y="96">Plan</text>
<text class="dg-note" x="280" y="96">Build</text>
<text class="dg-note" x="400" y="96">Seal</text>
<path class="dg-line is-dashed" d="M520 76V136H40V80" marker-end="url(#dg-card-head)"/>
<text class="dg-note" x="280" y="152">gate red after Seal reopens the card</text>
</svg>
</div>
</figure>

A phase that must not run without a human decision has `"gated": true`. Junji's `next` stops and asks you. Yokai halts at it unless you launch with `--allow-gated`. Configuring Yokai or importing a plan never counts as that approval.

When a phase finishes, Seal replaces the card's `description` with a one or two line verified outcome and moves the long detail into the phase file's Outcome section. The board stays short enough to read at a glance. One consequence: if a card is reopened later, its description holds the outcome, not the original scope. The scope is still in the phase file.

Older runs keep progress in `.koi/run/BACKLOG.md` with headings like `### [todo] P2 - Persist tasks`. Junji and Yokai still read that format. A run uses one or the other; if both files exist, both tools stop and ask you to choose.

## The next action pointer

`nextAction` moves along a fixed path: `begin`, `plan`, `refine`, then `next` once per phase, then `consolidate`. Some verbs never move it: `research`, `design`, `grill`, `brief` and `goal`. `iterate` moves it from `consolidate` back to `next` after adding phases. `review` sets it to `/junji next` only when it schedules fixes.

If you type `/junji` with no verb, Junji reads `nextAction` and runs or offers that command.

## Example: an unattended run

You start `yokai --headless --max-cost 25` after planning four phases. P1 runs in one set of sessions, commits, and is verified on disk. P2 starts in brand new sessions. It knows what P1 did only from the board, the Outcome section in P1's phase file, and a carry-forward note such as "dates are stored as text". It never reads P1's transcript.

P3 is gated, so the run halts there with the reason. You read the phase, approve it, and launch again with `--allow-gated`. The new process reads the same card statuses and starts at P3.

Because the state is in the repository, the agent and the machine do not matter. The same branch can continue in Codex instead of Claude Code, or on a CI runner instead of your laptop.

## What can go wrong

- The board says P1 is done but the code does not match. Ask the agent to run the verification commands from `CONTEXT.md` and inspect the last commit before continuing. Do not trust the board over a failing test.
- Two cards are in flight (two non-`todo`, non-`done` statuses). `next` stops and asks you to leave only one.
- The board is gone. Check that you are on the right branch and in the repository root. If the run was consolidated, the result is in your spec folder and the phase history is in Git.
- You kept one chat open for several phases. It works, but every later session will only know what was written to disk. Make sure carry-forward notes and Outcome sections are complete.

## Read next

- [What lives in .koi/](/en/docs/architecture/files)
- [Run on its own](/en/docs/koi/autonomous): `/junji goal` and `yokai --headless` side by side.
- [When a run stops](/en/docs/koi/resume): the short how-to.
