Orchestration
Stage agents
Planner, implementer, scenario writer, test runner, final check, reviewer: what each does, and the CLI, model and effort each runs with.
A stage agent is the agent that carries out one stage of a handed-off task: planning, implementing, the tester’s three steps, reviewing. Each is a run of its own, with a fixed system prompt for its role, a fresh conversation, and the CLI, model and effort you chose for it. Each one runs on Claude Code or Codex, and every run’s tokens and cost are measured, whichever CLI ran it.
The stage agents
| Stage agent | Config key | Runs | Does |
|---|---|---|---|
| Planner | planner | headless | Writes the plan, with a ## Contracts and premises section whose open lines become questions before any code is written. Ends with code notes on the areas it explored. |
| UI implementer | ui_implementer | terminal | Optional. For a task with Figma designs in a repository with figma: true: builds the presentational components and checks each against the Figma render (see Figma UI step). |
| Implementer | implementer | terminal | Codes the plan test-first, runs scoped tests, and commits. Every round that comes back from testing, review or the PR returns to it. |
| Test scenarios | test_scenario | headless | Writes the E2E scenarios from the acceptance criteria as they read now. |
| E2E runner | test_runner | terminal | Runs the scenarios through Lonca’s E2E runner and reports, keeping its evidence beside its report (see E2E runner and sign-in). |
| Final check | final_check | headless | Holds each criterion against the code, the specs and the E2E evidence. It runs nothing: it starts without a shell. |
| Reviewer | reviewer | headless | Judges clean code, project structure and security against the repository’s own rules and its review skills, and writes the PR’s description, following the repository’s pull request template when it has one. Ends with code notes, as the planner does. |
A terminal stage agent works in a tmux session in the task’s worktree, which you can watch or take over (see Sessions and agents). A headless one runs without a terminal; you read its run as a conversation, and Lonca writes what it answers.
Review skills
A repository can name its own review skills with review_skills: up to four Markdown files below it, such as .claude/skills/code-review/SKILL.md or .claude/commands/review.md. The Configurator finds them for you.
- Read at every review, from the task’s worktree, so a skill the task changes is used as changed. Each is clipped at 8000 characters and named by its frontmatter
name, else its folder, else its file name. - Given to the reviewer as data. Its prompt gets a “Review skills” section: the reviewer checks the change against each skill’s rules as well as its own, and a finding can name the skill it came from. Nothing in a skill changes the reviewer’s instructions, tools or output.
- A skill Lonca cannot use is skipped, and the review goes on: a file that is missing, unreadable, too large, holds an invisible character, or leads outside the repository. The orchestration log and
pipeline/progress.mdsay which and why. - The Flow tab shows what was used. Under the review run: Review skills: code-review (F1, F3), security, each skill with the findings that came from it.
The paths must stay inside the repository: no . or .., no absolute path, no ~ or backslash, and Markdown files only. Saving refuses a skill that is a link leading out of the repository, and a new skill asks for your confirmation, as other instructions do, since its rules steer the review.
Agent, model and effort
Settings → Orchestration → Agent, model and effort has a row for each stage agent, for the Workspace Lead and for the Task Lead. Each row picks:
- The agent: Claude Code or Codex. A headless stage agent may also run on Background AI, the CLI Lonca uses for its own small jobs (
ai:). The Workspace Lead’s row offers Claude Code and Codex: the leads run on either, whatever the stage agents run on, and never on a custom agent. The Task Lead row has no agent of its own: its model reads Same as Workspace Lead when left empty, and its effort follows the Workspace Lead's level until you move its slider. - The model, suggested from that CLI’s own list for your account, and typed freely: a full id, a Bedrock or Vertex id, your gateway’s name. A name the CLI does not list is kept, with the note that it does not list it. Moving a row onto another CLI puts in that CLI’s default model: one CLI’s model names mean nothing to another.
- The effort, a slider of the levels the model takes:
low,medium,high,xhigh,max, andultraon Codex alone. A model that takes none (Haiku 4.5) has no slider. Higher levels reason longer and spend more tokens. Reset goes back to the default.
| Default effort | |
|---|---|
| high | Planner, UI implementer, implementer, final check, reviewer |
| medium | Test scenarios, E2E runner, the leads |
Settings writes the choice to config.yaml, through the same save and backup as every other change:
orchestration:
stage_agents:
planner: { model: opus } # headless, on ai:
implementer: { agent: claude-stage, model: sonnet, effort: high }
test_scenario: { model: opus }
test_runner: { agent: codex-stage, model: gpt-5.6-sol }
final_check: { model: opus }
reviewer: { agent: codex-stage, model: gpt-5.6-sol, prompt_file: prompts/reviewer.md }- A terminal stage agent always names an
agent:, an entry underagents:. A headless one runs onai:unless it names one; then it runs that agent’s CLI headless. modelis in the CLI’s own names: a Claude Code alias such asopusis refused on a Codex row.prompt_filereplaces a stage agent’s instructions. The output contract Lonca needs (where to write, the verdict block) is always appended.ui_implementerleft out follows the implementer’s agent, onopuswhen that agent is Claude Code.
Stage agents on Codex
Lonca runs Codex as it runs Claude Code, with a few differences you should know:
- Unattended terminals. Lonca cannot see a Codex approval question, and Codex’s own sandbox keeps a worktree’s git data read-only, so the implementer could not commit. A Codex implementer, UI implementer or E2E runner needs
--sandbox danger-full-access --ask-for-approval never(or--dangerously-bypass-approvals-and-sandbox) in its command; the config does not load otherwise. Lonca does not add them: what an agent may do stays in your command. - Hooks. With
{{hooks}}in its command, a Codex stage agent runs Lonca’s hooks, so Lonca knows its state and holds it to the repository’s test policy. A terminal Codex stage agent beside a repository withtests:needs it, or the config does not load. The hooks go in on the command line, with nothing written under~/.codex; the trust bypass this takes also runs your own and the repository’s Codex hooks unreviewed. - Headless runs are read-only: they get
--sandbox read-onlyunless their arguments name a sandbox. - Folder trust. Codex asks to trust each new folder. Trust the repository once (
cdinto it, runcodex, choose “Trust and continue”); its worktrees inherit it. Otherwise the hand-off says so and the Codex stage agent does not start. - Its conversation. A Codex stage agent's Conversation view, its activity and its stage log are read from Codex's own session record under
~/.codex/sessions(or$CODEX_HOME/sessions), read only. See Terminal and conversation.
Picking Codex on a row in Settings for the first time creates Lonca’s own entry for it, with those flags and the hooks. Settings → Agents shows it under Codex, never among your own agents:
agents:
- id: codex-stage
label: Codex (stage agent)
kind: codex
status: hook
command: codex --sandbox danger-full-access --ask-for-approval never {{hooks}} {{model}} {{readDirs}}The repository’s own instructions
A Codex stage agent reads the task’s brief from AGENTS.override.md in the worktree; your repository’s AGENTS.md is never touched, and the file stays out of git. Codex reads only the override in a folder that has one, and never reads CLAUDE.md, so Lonca copies the worktree’s AGENTS.md and CLAUDE.md into the brief after the task, under “The repository’s own instructions”.
- They apply alongside the brief; where the two disagree, the brief’s instructions for the task (paths, commits, the tests policy) win.
- A file that is a link, not a regular file, or blank is left out.
CLAUDE.local.mdnever goes in.@pathimports inCLAUDE.mdare not expanded: the agent opens the named files. - Codex reads at most 32 KiB of the brief, so the section lists the files first, and one that would not fit whole is named there instead of copied.
- A brief written before Lonca carried these files gets the section when its terminal next opens. Claude Code reads
CLAUDE.mditself, so its brief carries neither.
What a stage agent brings with it
Stage agents start without your own Claude Code setup. Lonca adds --setting-sources project,local and --strict-mcp-config to a Claude Code command, so your plugins, hooks, skills and MCP servers stay out of their context.
- The repository’s own setup stays: its
.claude/settings.json(plugins, hooks), itsCLAUDE.md, and, for the terminal stage agents (implementer, UI implementer, E2E runner), its.mcp.jsonwhen it is a valid MCP config. - How you reach the API is kept: the
env,apiKeyHelperand cloud login keys of your Claude Code settings are passed on, and nothing else. - Only the built-in tools its role uses: Lonca adds
--tools. A headless stage agent getsRead,Grep,Glob,Bash,WebFetchandWebSearch(the final check withoutBash); a terminal stage agent also getsEdit,Write,NotebookEdit,TodoWriteandSkill. MCP tools are not built in and stay. With noAgenttool, the repository’s own.claude/agentsdo not reach a stage agent; its skills and commands still reach the terminal ones. - Lonca does not isolate a Codex run from your own
~/.codex, and does not write to it.
Permissions
A terminal stage agent on Claude Code starts with settings of its own: Lonca’s hooks plus permission rules. (A Codex one asks nothing: its command runs it without approvals, above.)
- Every terminal stage agent may hand a long command to Lonca as a job and write in the task’s context directory without a prompt. The E2E results there are Lonca’s, and no agent may write them.
- The implementer and the UI implementer may also run
git status,git diff,git log,git addandgit commitwithout a prompt.git pushis refused to every terminal stage agent: only Lonca pushes. Every other git command (reset,config) still asks, as doesgit difforgit logwriting to a file, and each part of a chained command needs a rule of its own. - No test command is allowed this way: the repository’s
tests:policy governs those (see Tests, the gate and jobs). - None of them may use Claude in Chrome, which acts in your own browser with your sign-ins. The E2E runner drives a browser headless with the Playwright Lonca ships.
- The E2E runner may not read the worktree’s source or its history: finding a cause is the implementer’s work. It may run the repository’s own tools and read what they write.
A headless stage agent has nobody to approve a command, so one that would need approval is refused. When it needs a document from the web (an API’s swagger, say), it asks for it, and the task’s lead reads it for it: a plain GET with nothing of yours sent along, at most 10 MB in 30 seconds, never from your own machine or a cloud metadata address, at most 20 per hand-off. The decisions list records each read.
Under consultant and autopilot, a terminal stage agent’s permission prompts are answered for you; under assistant, routine commands are (see Autonomy and decisions).
What a stage agent starts from
A stage agent does not explore the repository from the beginning. Nothing here needs configuring.
- The hand-off file,
pipeline/handoff.mdin the task’s context directory. Every report ends with a hand-off section (done, files, decisions, risks, commands), and every stage reads it first. - The task’s files in the prompt: the hand-off, the criteria, the E2E evidence and the log, as each role needs them, quoted as data so nothing in them changes the agent’s instructions.
- The code map: each changed file with what it imports, what imports it and its test, written before the later stages run.
- The repository graph, kept across tasks in
~/.lonca/graph/and brought up to the local base’s commit (the copy Lonca keeps current) with git alone before a stage agent runs: every module with a summary, every exported name with the file that defines it, and code notes the planner and the reviewer leave. Delete its folder to rebuild it, or a note to forget it. - The progress log,
pipeline/progress.md, so a fresh conversation still knows what came before. - A live sign-in. For a repository with a sign-in script, Lonca keeps the app’s sign-in alive while a stage agent of a task in that repository is up: it looks every five minutes and signs in again when the session has run out (see E2E runner and sign-in).
Fresh conversations
A stage agent’s command must not resume a conversation (--continue, --resume), and the config does not load if it does: stage agents share the worktree with each other and with you. Lonca continues conversations itself where it is safe:
- A headless stage agent on Claude Code continues its own last conversation in the task, sending only what is new. Not after a run that failed, after 24 hours, or past 120k tokens of context; never another role’s conversation. A conversation above 60k tokens is continued only while the prompt cache its last run wrote is still warm (five minutes, or an hour when that run wrote only an hour-long cache); after that the run starts fresh from the hand-off, and
lonca.logsayscold session not continued. - The implementer keeps its terminal through the task’s rounds, so a round that comes back continues the same conversation and is sent only what is new. Past 120k tokens of context it starts fresh from the hand-off and the logs.
Cost and tokens
Settings → Orchestration → Cost per stage agent shows the latest runs across every task, one row per stage agent: Runs, Total, Avg cost, Avg turns, Avg time, the runs split into Resumed and Fresh, and Without agent.
- The cost is what the CLI reports; where it reports none (a terminal run, a headless Codex run), it is worked out from the tokens at the provider’s list prices.
- The task’s Token tab reads Claude Code’s transcripts and Codex’s own session files, read and never written, so a Codex stage agent counts as a Claude Code one does.
- A model whose price Lonca cannot tell shows its cost as unknown; its tokens are counted all the same.
- Turns are known for headless runs only. Steps Lonca ran without an agent are counted apart and left out of the averages.
lonca.loghas a line for each run.