Skip to content

Trunk-based area work

Trunk mode lets several areas share the configured project trunk instead of binding separate feature branches. Under the default workspace.branching = "on-request" preference, creating an area on the checked-out trunk uses trunk mode automatically (except for pull-request records, which always use isolated branches). This reference covers trunk records, branch checks, and transitions between trunk and isolated modes.

area.toml accepts an optional mode field:

mode = "isolated" # or "trunk"

The parser rejects unknown fields. The mode-dependent schema is:

Mode Stored branch parent base_commit
field absent, or mode = "isolated" required optional optional
mode = "trunk" forbidden forbidden forbidden

An absent mode means isolated. Writers omit mode for isolated areas and emit mode = "trunk" for trunk areas. A trunk area’s operating branch is always resolved dynamically from project.trunk rather than copied into the area record.

schema_version is 1. Adding the optional mode field preserves the meaning of older v1 area records without migration, while older binaries with strict parsers fail closed on mode = "trunk" instead of mismanaging a trunk area as isolated.

Examples:

# Isolated form (omitting mode)
schema_version = 1
tag = "payments"
title = "Payments"
objective = "Improve payment handling."
branch = "payments"
base_commit = "0123456789abcdef0123456789abcdef01234567"
# Explicit trunk form
schema_version = 1
tag = "docs"
title = "Documentation"
objective = "Keep the documentation accurate."
mode = "trunk"

zdev check, every area loader, and every write path enforce this conditional schema. A trunk record containing branch, parent, or base_commit, or an isolated record missing branch, fails validation without automatic repair.

Any area record without mode stays isolated, even if its stored branch equals the current or a former trunk. It keeps its same-branch shortcut, anchor behavior, and stored branch; reconfiguring project.trunk never adds mode, clears its branch, or moves it. Once project.trunk changes, an isolated area on the old trunk is evaluated as an ordinary isolated area against the new base (fresh, stale-but-safe, or unsafe from its stored facts).

The commands are:

zdev area create <tag> --title <title> --objective <objective> [--branch <branch> | --trunk]
zdev area bind <area> [<branch> | --trunk]

--trunk conflicts with --branch on create and with the positional branch on bind; repeating the flag or passing an extra positional argument is a CLI error.

Without either mode option, zdev area create follows workspace.branching. Under the default on-request, it creates a trunk area whenever the checked-out branch is the configured, locally existing trunk and the record policy supports trunk mode. Otherwise (and always under isolated), it creates an isolated area bound to the checked-out branch. Passing --branch always creates an isolated area on that canonical branch, while --trunk creates a trunk area following project.trunk (requiring a configured, locally existing trunk, a trunk-capable record policy, and no active Git operation). Neither flag creates or checks out a branch. Like explicit --branch, --trunk can record the target while HEAD is detached or on another branch; task work then stays blocked until trunk is checked out. Inferring an isolated branch on detached HEAD fails with No branch is checked out; pass an explicit branch name.

zdev area bind without a target binds the area as isolated to the checked-out branch. A positional branch binds as isolated to that canonical branch, and --trunk switches the area to trunk mode. All bind forms take the state lock, reread config and area records under the lock, validate the full candidate area graph, and atomically replace only that area’s area.toml.

Mode transitions enforce these extra checks:

  • Isolated to trunk: requires a configured, locally existing trunk, no active Git operation, no parent, and a trunk-capable record policy. The old isolated branch must exist and its tip must be an ancestor of the trunk tip, proving that the switch does not strand unintegrated commits. On success, the write publishes the trunk form without branch or base_commit.
  • Trunk to isolated: requires the named or inferred target branch to exist, no active Git operation, and its tip to contain the current trunk tip. On success, the write removes mode, stores the target branch, leaves parent absent, and sets base_commit to the current trunk tip.
  • Isolated to isolated: uses standard anchor-containment and anchor computation without requiring a clean worktree.
  • Repeating the current binding returns unchanged without writing, and any failure leaves the prior bytes and mode untouched.

Explicit --branch works on detached HEAD, whereas an omitted branch fails there. Because --trunk does not infer from HEAD, detached HEAD is not a configuration error; status reports it and task work stays blocked. No transition switches, creates, renames, deletes, merges, rebases, or pushes a branch.

Stable mode-transition failures:

Condition Error
Trunk is unconfigured Project trunk is not configured; set it with `zdev config trunk <branch>`
Configured trunk is missing Cannot use trunk mode because configured trunk <branch> is missing locally
Inferred branch on detached HEAD No branch is checked out; pass an explicit branch name
Isolated source has commits outside trunk Cannot bind area <tag> to trunk: branch <branch> has commits not contained in <trunk>
Isolated target does not contain trunk Cannot bind trunk area <tag> to <branch>: the branch does not contain configured trunk <trunk>
Parent remains Cannot bind area <tag> to trunk while it has parent <parent>; remove the parent first
Pull-request record Trunk areas are not supported with pull-request records; use an isolated area branch

CLI argument conflicts produce Clap errors, and active-operation errors use the while a <operation> is in progress format while preserving Git state.

Human results look like:

Created trunk area docs on configured trunk main
Bound area docs to configured trunk main
Bound area docs to branch docs-work
Area docs is already bound to configured trunk main

The JSON objects include schema_version, status, area, and path (for create), plus these mode fields:

{"mode":"trunk","branch":"main","base_commit":null}

or:

{"mode":"isolated","branch":"docs-work","base_commit":"<40-hex-commit>"}

In a trunk result, branch is the resolved configured trunk and base_commit is null. Creation returns status: "created", a changed bind returns "updated", and an exact repeat returns "unchanged".

Several areas can share one branch in isolated mode, trunk mode, or a mix of both. Each area keeps its own mode and base relationship; zdev never reclassifies a record just because its branch name matches project.trunk.

On checked-out trunk, every structurally safe trunk area has branch_matches = true. zdev next --any ranks matching candidates first, then sorts by lexical area tag, picking each area’s ready task by AFK suitability, priority, and numeric task ID. For example, with ready docs-002 and quality-001 on trunk, docs-002 wins. When an isolated branch is checked out, matching isolated candidates win ahead of off-branch trunk candidates. No area is hidden and no branch is switched.

Both trunk-setting forms share one resolver and writer:

zdev config trunk [<branch>] [--allow-divergent]
zdev config set [--local] [--allow-divergent] project.trunk <branch>

Omitting <branch> in zdev config trunk uses the checked-out branch. --allow-divergent is accepted only on these two local trunk writes when explicit trunk areas exist; zdev config set rejects it for any other key, and both commands reject it with --global.

When at least one explicit trunk area exists, the command:

  1. acquires the zdev state lock and rereads config and all areas;
  2. rejects any active Git operation;
  3. canonicalizes the requested branch and verifies that it exists locally and is inspectable;
  4. validates the full area graph against the candidate branch, including parent relationships and record policy;
  5. resolves both tips when changing an existing configured trunk and requires the old tip to be an ancestor of the candidate tip; and
  6. atomically replaces .zdev/config.toml.

The ancestry check allows the same tip, a second branch pointing to that tip, or a fast-forward descendant. If the old configured branch is missing or its tip or ancestry cannot be inspected, reconfiguration fails even with --allow-divergent. A candidate on divergent or older history fails by default. Both failures list every affected trunk area in lexical order and leave config untouched:

Cannot reconfigure trunk from main to stable for trunk areas docs, quality: main is not an ancestor of stable. Re-run with --allow-divergent only after deciding to move these areas without ancestry continuity
Cannot reconfigure trunk from main to stable for trunk areas docs, quality: previous trunk main is missing or cannot be inspected. Restore it before reconfiguring trunk

Because an external git branch -m removes the old ref, the second error fires even if you know both names pointed to the same commit; automatic same-tip reconfiguration requires both refs to exist while the command runs.

--allow-divergent waives only a confirmed ancestry mismatch. Both tips must still be inspectable, and candidate existence, record policy, active-operation, schema, and locking checks still apply. The command performs no Git operation and reports the override explicitly:

Configured project trunk stable (previous: main; affected trunk areas: docs, quality)
Ancestry override: previous trunk main is not contained in stable

JSON output (modulo commit hashes):

{
"schema_version": 1,
"status": "updated",
"previous_trunk": "main",
"trunk": "stable",
"affected_areas": ["docs", "quality"],
"ancestry": {
"old_tip": "<40-hex-commit-or-null>",
"new_tip": "<40-hex-commit>",
"old_is_ancestor": false,
"override": true
}
}

A successful reconfiguration always reports resolved old and new tips. A normal ancestor move emits override = false and old_is_ancestor = true and omits the ancestry-override line from human output. Repeating the current trunk returns status = "unchanged", matching old/new branches and tips, and old_is_ancestor = true without writing.

Because trunk areas store no copy of the branch name, updating .zdev/config.toml moves every open and closed trunk area’s operating branch atomically. Any filesystem or validation failure leaves config and area records intact with no multi-file partial state to roll back.

Reconfiguration does not require the new trunk to be checked out. If the old trunk is still checked out, open trunk areas immediately report branch_matches = false and task_work.safe = false, blocking named task work until you switch to the new trunk. zdev next --any can still surface a structurally safe off-branch candidate while reporting the required new branch and branch_matches = false. Any live harness prompt or goal must re-orient against fresh status; the command never switches branches.

zdev config unset project.trunk fails while any trunk area exists:

Cannot unset project.trunk while trunk areas exist: docs, quality

Convert those areas to isolated mode first. When no trunk areas exist, set, unset, and config trunk allow naming a branch that is not present locally.

If someone renames or deletes the configured trunk directly in Git, trunk records stay untouched, status turns unsafe and names the missing branch, and you either restore the branch or reconfigure project.trunk to an existing branch. Zdev never guesses renames or edits Git refs.

Area status includes mode on both area and branch_status. For an isolated area, area.branch is the stored branch; for a trunk area, area.branch is the resolved project.trunk (or null when unconfigured), projected without writing to area.toml. parent is omitted and base_commit is null.

A healthy trunk area on checked-out main reports these mode-sensitive fields:

{
"mode": "trunk",
"branch": "main",
"checked_out_branch": "main",
"branch_matches": true,
"parent_area": null,
"base_commit": null,
"effective_base": {"kind": "trunk", "area": null, "branch": "main"},
"fresh": true,
"anchor_valid": null,
"finalized": null,
"linear_history": null,
"task_work": {
"safe": true,
"structurally_safe": true,
"stale_advisory": false,
"git_operation": null
},
"diagnostics": ["fresh"]
}

effective_base.kind stays "trunk", with its branch equal to the operating branch. fresh = true reflects that the branch is always current with itself. anchor_valid, finalized, and linear_history are null (not true) because trunk mode has no child/base boundary, and stale_advisory is always false.

Other trunk states:

Condition branch_matches fresh structural / task safe Added diagnostics
Another attached branch is checked out false true true / false wrong-branch
Detached HEAD null true true / false detached-head
Configured trunk absent null null false / false project-trunk-unbound
Configured branch missing locally comparison with attached HEAD, normally false null false / false trunk-branch-missing
Active named Git operation normal comparison true when branch exists false / false git-operation-in-progress; task_work.git_operation is its name
Git operation cannot be inspected normal comparison true when branch exists false / false git-state-unavailable

Diagnostics are ordered as Git inspection/operation, checkout mismatch, configuration or missing-branch error, then fresh when applicable. zdev status is read-only and succeeds even for unsafe states, while task-work commands return the same branch_status in structured error details.

The human branch line reads:

docs: trunk mode on main [fresh]

or, off-branch:

docs: trunk mode on main [wrong-branch, fresh]

Title, lifecycle, queue, counts, slices, advisory placement, and project-wide summary keep their standard layout, and trunk mode never prints a rebase advisory. Selected next JSON includes the resolved branch, mode = "trunk", branch_matches, and complete branch_status; off-branch human output prints Required branch: main (not checked out; current branch: <branch>).

zdev goal <area> is branch-independent: its human and JSON output project only area lifecycle, queue, and task context without mode, branch, or branch_status. Harness workflows get branch facts from the nested status projection in zdev work-context <area> --format json.

base_commit has no meaning in trunk mode: create omits it, isolated-to-trunk bind removes it, status reports null, and trunk writers reject any stored value. Trunk-to-isolated bind sets base_commit to the current configured trunk tip.

Parent relationships:

Child Parent Result
isolated isolated Supported.
isolated trunk Rejected: bind the child directly to configured trunk instead of naming one of several equivalent trunk areas.
trunk isolated Rejected: trunk mode cannot have a parent.
trunk trunk Rejected: trunk mode cannot have a parent.

zdev area parent reports mode conflicts before writing, and an isolated area must remove its parent before running zdev area bind --trunk.

zdev area rebase <trunk-area> rejects active Git operations, an unconfigured or missing trunk, detached HEAD, or a wrong checked-out branch. On healthy checked-out trunk, it succeeds without requiring a clean worktree, invoking Git, or writing metadata:

Area docs runs on configured trunk main; no rebase is needed
{"schema_version":1,"status":"unchanged","area":"docs","mode":"trunk","branch":"main","effective_base":"main","base_commit":null,"fresh":true}

--continue and --abort reject trunk mode because zdev never starts a managed rebase for a trunk area, leaving any unrelated Git recovery operation untouched so its owning workflow can finish or abort it.

Task and area lifecycle formats, task ordering, slices, and bundle approvals work identically in trunk mode; only the branch checks change:

Operation in trunk mode Rule
Ordinary import Standard transactional import (valid open area, approved bundle when supplied, slices and full graph, state lock). Allowed off-branch and makes no commit.
Committed import Requires configured trunk checked out, local, and inspectable, with no active Git operation. A tracked, valid worktree-modified owning brief.md may join the new task files and TASKS.md; staged, deleted, untracked, symlinked, conflicted, or partially staged brief state is rejected.
Named selection and completion Requires trunk task_work.safe (configured trunk exists, is checked out, Git state is inspectable, and no Git operation is active). Completion atomically writes only the task file and TASKS.md.
Task reopen Branch-independent with atomic task/index write; a closed area or completed dependents still block it.
Area close/reopen Requires task_work.safe, evaluated in trunk mode.
Final commit Standard zdev commit: commits exactly the caller-prepared index and adds Zdev-Change-Id where the record policy uses one. Trunk mode never claims unrelated changes on trunk.

Non-overlapping unrelated staged, unstaged, and untracked changes on trunk stay untouched. The coordinator captures all three baseline parts, attributes every delta, stops for unexplained or overlapping paths, and stages only the accepted task’s source, test, and durable task paths. Pre-existing unrelated staged changes are never unstaged automatically; they block a task-specific commit until you resolve ownership. Unrelated worktree or untracked files may remain when their ownership is clear and paths do not overlap.

Committed import stays tightly scoped: it commits only new task files, the regenerated index, and an eligible owning brief with git commit --only, leaving unrelated index and worktree bytes alone. Changes under another trunk area’s .zdev directory are unrelated and excluded. Any failure restores the owning brief’s prior index and worktree state, deletes the new task files, restores the prior index file, and leaves unrelated state intact. Success leaves only managed paths clean and reports paths in deterministic order: eligible brief first, numeric task files, then TASKS.md.

Any overlap with the selected task’s claimed source or test paths, its task file, an included owning brief, TASKS.md, or the area/config file being updated is not “unrelated”; the command or coordinator stops before overwriting or committing. There is no workspace-wide lock, active-area pointer, or blanket clean-worktree requirement.

Record policy Trunk mode
personal Supported. Clone-local .git/info/exclude behavior is unchanged.
project Supported. Trunk area records remain shared project history.
shadow Supported. Trunk area records live in .zdev/.git following the trunk branch.
pull-request Unsupported. Create, bind-to-trunk, relationship checks, and trunk-aware config validation reject it.

Pull-request records live on a review branch and are removed by zdev cleanup squash before squash merge. Because a trunk area has neither a feature-branch boundary nor a safe place for a cleanup commit (cleanup refuses configured trunk), rejecting the combination keeps the record policy coherent.

zdev cleanup squash remains pull-request-only: it requires a clean, attached non-trunk branch and no active Git operation, removes tracked .zdev paths, and makes one plain commit. personal, project, and shadow repositories reject cleanup, as do legacy isolated areas stored on trunk.

“No mutation” means no Git ref, index, or record change. Each row follows the human line and JSON fields defined under Status and task-work projection, with the listed condition supplying its diagnostics and null/boolean fields; mode-transition errors use the messages above.

Case Metadata and status Command result Mutation boundary
Default isolated create on feature no mode; branch = "feature"; normal anchor fields Isolated create and status New area directory only
One explicit trunk area on checked-out main mode = "trunk"; no branch/parent/base; healthy projection above Named next/completion allowed Task-specific files only
Two ready trunk areas both store only trunk mode; both match main next --any chooses lexical area tag, then AFK suitability, priority, and numeric task ID within that area Read-only
Checked-out isolated area plus ready trunk areas mixed records; isolated matches, trunk areas are structurally safe but off-branch next --any chooses matching isolated candidate first Read-only
Legacy area stored on current trunk no mode; stored branch stays fixed; same-branch shortcut Trunk areas may share the branch Only the requested area record changes
Legacy area on former trunk stored old branch; effective base is newly configured trunk Standard isolated fresh/stale/unsafe result Reconfiguration changes config only
Reconfigure main to descendant stable with open/closed trunk areas old tip is ancestor; area files unchanged; all resolve stable; old checkout makes open work unsafe Config command succeeds with old/new branches, tips, lexical areas, and no override; named work waits for checkout; next --any may report required stable Atomic config write only
Reconfigure main to divergent stable by default ancestry is false; all areas still resolve main Reject with lexical affected areas and --allow-divergent recovery No mutation
Reconfigure divergent history with --allow-divergent area files unchanged; all open/closed areas resolve stable; old checkout is off-branch Success records old_is_ancestor = false, override = true, old/new branches and lexical affected areas Atomic config write only; no Git ref operation
Previous configured trunk is missing old tip/ancestry are null; areas still resolve the old name Reject even with --allow-divergent; restore the old branch first No mutation
Reconfigure to missing branch while trunk areas exist candidate cannot produce inspectable operating branch Reject configured trunk <name> is missing locally No mutation
Reconfigure onto a branch used by isolated areas candidate graph permits shared branches Accept when normal ancestry checks pass Atomic config write only
Unset trunk while trunk areas exist trunk projections would become unbound Reject with lexical area list No mutation
Configured trunk deleted outside zdev trunk records unchanged; fresh null; structural/task safe false; missing diagnostic Status succeeds; task work fails with details Read-only
Wrong branch or detached HEAD fresh true if trunk exists; branch match false/null; task safe false Status succeeds; named work fails; next --any may project off-branch work Read-only
Goal on wrong branch, detached HEAD, or unsafe trunk facts task graph and lifecycle remain valid zdev goal returns its branch-independent task projection; workflow work-context still blocks execution Read-only
Active rebase/merge/cherry-pick operation diagnostic; both safety flags false Create/bind mode change, reconfigure, committed import, selection, completion, lifecycle change, and managed rebase fail No zdev mutation; Git recovery state preserved
Ordinary import off trunk branch status need not be safe Transactional import succeeds if area/bundle/graph are valid New tasks and owning index only
Committed import with eligible brief and unrelated changes trunk checked out; exact owning brief state valid Import commits brief, new tasks, index; preserves unrelated state Managed paths and one commit only
Committed import with staged/overlapping owning path ownership is ambiguous Precise error and rollback Prior bytes/index restored
Completion with attributed unrelated worktree files trunk safe; baseline separates paths Completion succeeds; later exact staging excludes unrelated files Task and index only
Final commit with unexplained or unrelated staged path mode grants no ownership Coordinator stops before zdev commit No mutation
Trunk area given any parent invalid conditional schema/relationship Parent/bind/check rejects No mutation
Rebase healthy trunk area with dirty unrelated files no anchor/history relationship Successful unchanged result; no cleanliness requirement Read-only
Pull-request project requests trunk mode unsupported record/mode pair Create/bind/check rejects and points to isolated work No mutation
Cleanup on configured trunk or legacy isolated-on-trunk cleanup guard Reject No mutation