# Branch settings

Each branch of a conversation runs with its own settings and its own state, so two branches can run side by side.

## Where a setting comes from

Every branch keeps its settings on its own record in `branch_refs`; the conversation's top-level fields are the selected branch's projection. `resolve_branch_settings(session, branch)` returns each setting's `values`, `sources` and `inherited` (what it follows when unset). Every entry reads through it: web, channels, scheduled runs, always-on, Goals and `--print`.

| Setting left unset | Falls back to |
| --- | --- |
| Model, Web search, Fast | The branch's Agent as it is now, then the product default |
| Effort | The Agent, then the project, then the product default |
| Permission mode, Sandbox | The project, then the product default |
| Agent | The default Agent |

## Following the Agent

- A new conversation and an Agent switch write no model, so an edit of the Agent's model reaches the next turn.
- Admission records the model in `turn_settings`. When the Agent changed it since the last turn on that line, the user message carries `model_change`, the page shows a one-line note and the cache-break report names `model_switch`.
- A move to a model with a smaller window compacts first, with the old model.
- `scripts/maintenance/migrate_branch_follow_agent.py` clears models and web-search switches that only copied the Agent's. It is a dry run by default and writes a backup before it changes anything.

## Writing a setting

- `POST /api/sessions/{id}/branch_settings` stores only what differs from `inherited`; an equal value is written as unset. `reset_fields` also puts a setting back to inherit.
- `GET` on the same path and the reply to a write return the resolved values.
- A message to an existing conversation sends no settings; a new conversation sends only the controls the person changed.

**Why this design**

| Decision | Follows | Why |
| --- | --- | --- |
| Follow the Agent | Claude Code and Hermes: unset means follow the layer above. Codex: the warning on a model change and the downshift compaction | The Agent is the identity a person maintains; an edit of its model should reach the conversations that use it |
| Order per field | Claude Code: model and effort come with the Agent, permission from the environment | Permission is what this folder may do, a project boundary; model and effort are how the assistant works. Codex's single layer order would let a project override an Agent's model, which projects here do not set |
| Background entries read their own branch | Claude Code delivers a scheduled task to its owner; OpenCode resolves the session's Agent when the check fires | A scheduled command on another branch ran with the selected branch's permission, so loosening the main line loosened it too |
| Retry and edit copy the current settings | Codex, Pi and OpenCode | A snapshot of the old turn would loosen a permission the person tightened since; the current values are on the controls |
| Only differences are written | Claude Code's picker writes nothing for the default | "Set on this branch" then means the person set it |

## Where tool state belongs

| State | Kept per | Turn on another branch |
| --- | --- | --- |
| Todos | Branch (`todos.json` keeps one board per branch); a new branch starts from a copy of its parent's | Its own board |
| Goal | Conversation, bound to the branch it was started on (an older Goal belongs to the branch selected when it is read) | Runs without the Goal; the Goal's own branch runs with it, selected or not |
| Compaction summary | Chain (the summary's `covers_ids`) | Allowed |
| Occupancy (`last_prompt_tokens`) | Branch record; the conversation keeps the selected branch's | Allowed |
| Read-before-edit baselines | Branch history: each read is recorded against its turn in `read_baselines.jsonl` (local and SSH under their own key) | Only reads on its own line count, and none from before the latest compaction on it |
| Plan mode, background shells, permission rules, spilled tool output, memory writes | Not yet established | Not yet established |

A load and `get_run_state` return `running_branches`. `branch_running_task` carries the branch's name and `wait_state` (`approval` or `input`), so a pane can list runs on other branches.

**Why this design**

| Decision | Follows | Why |
| --- | --- | --- |
| Read baselines from history | Claude Code's `extractReadFilesFromMessages` | The same in every process (Worker, CLI, scheduled run); a fork, a rewind and a compaction need no extra bookkeeping |
| Todos per branch | Claude Code: one list per execution context | A side branch writing the conversation's board overwrote the main line's |
| Goal bound to its branch | Codex: a goal per thread | Same reason; only commands that act on the whole conversation stay on the selected branch |
| Operations hold only their branches | Codex: a constraint lands on the thread acted on | Each branch has one foreground operation; a node shared by several branches needs all of them idle |
| Runs on other branches | Claude Code's footer badge per task; the states from Codex `/side` | A run waiting for approval blocks work, so it belongs beside the input. Only the data is sent so far |

What is not yet done: [Activity and control, Implementation status](https://fzkuji.github.io/OpenProgram/docs/reference/design/runtime/execution/control.html#status).
