> ## Documentation Index
> Fetch the complete documentation index at: https://psychiatrist.sudo.la/llms.txt
> Use this file to discover all available pages before exploring further.

# Branches and worktrees

> Where a session works: a worktree on its own branch, or the checkout as it is. Nothing is merged back.

With no `branch`, a session works in a worktree on a new branch of its own, `psychiatrist/<8 hex digits>`, from `cwd`'s HEAD. `branch: { name }` names the branch: a new one from `from` (a commit, `cwd`'s HEAD by default), or the branch itself when it exists; git's rules for branch names apply, and a name it refuses stops `start()`. The worktree goes in `~/.psychiatrist/worktrees/library/<checkout>-<hash>/<branch>-<hash>` (`PSYCHIATRIST_HOME` moves it), keyed on the checkout's whole path and the branch's whole name, so two checkouts with one folder name, or `a/b` and `a-b`, never share one; `path` puts it elsewhere (relative to the checkout). A worktree already there is reused, so a resumed session finds its work, but only when it is this checkout's worktree on this branch: anything else at that path stops `start()`. `"head"` works in `cwd` itself, on whatever is checked out. Nothing is ever merged back, and closing a session leaves its worktree.

Every session in a worktree is recorded by its id (`~/.psychiatrist/library/sessions.json`): `start({ resume: id })` with no `branch` continues in that worktree, on that branch, so its work is never left behind in a new one. A session with no record (one that worked in `"head"`, say) needs `branch` to say where it works, and `start()` rejects without it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.