Worktrees
A worktree lets a session work in a folder of its own, on your checkout’s commit or on a branch you name, so several agents can work in one repository at once without touching each other’s files or yours.
Running a session in a worktree
Section titled “Running a session in a worktree”When the folder you pick in Create session is in a git repository, Run in a new worktree is offered, a switch, off by default. Its ⓘ says what the session will run in, or, in the warning’s colour, why git can’t make a worktree of this folder now, which holds the switch off. With it on, Moontors:
- makes the worktree from your checkout’s current commit, with no branch of its own unless you name one (below);
- puts the worktree in
~/.moontors/worktrees/, in a folder named for the repository and the title, or the branch when you name one, so your own folders and.gitignorestay as they are; - copies in the files your project lists (below);
- starts the session there, in the same place inside the repository as the folder you picked.
Once it’s on, the worktree’s details open under it, among them Branch, a branch for the
worktree, empty at first, its ⓘ saying how a name is taken. Leave it empty and the worktree has no
branch: it’s on your checkout’s current commit, as git calls detached, and the switch’s ⓘ names
your checkout’s branch, as it is now. Type a name, such as fix-the-login or al/fix-the-login,
and the worktree gets a new branch of exactly that name, which the ⓘ then says is made from your
checkout’s branch. A name git won’t take, or one already used, is said under the field, and
Create waits until it changes.
The field leaves out what git never takes in a branch’s name, such as a space or ~ ^ : ? * [ \, as
you type. A name git still won’t take, such as one starting with -, holding .. or ending in
.lock, or one a branch already has, is said under the field, and Create waits until you
change it.
The folder is named for the repository and the title, or the branch when you name one, in lowercase
letters, digits and dashes. With no branch, Fix the login gives the folder
~/.moontors/worktrees/web-fix-the-login for a repository named web; the branch
al/fix-the-login gives web-al-fix-the-login. The repository’s name is cut to 24 characters, and
the title or the branch to 40. Without a title, or with one that has no Latin letters or digits, a
short id names the folder. If a folder of that name is already in ~/.moontors/worktrees/ (another
repository of the same name puts its worktrees there too), the folder gets -2, -3 and so on at
its end.
The card and the panel’s header show the repository and the branch, or for a worktree with no
branch, the commit it started from, such as web · commit 3f2a9c1. A worktree session stays in its
worktree: /cd can’t move it, and no other session can /cd into it.
Your checkout’s uncommitted changes stay where they are: the worktree starts from the last commit. Create session says so once Run in a new worktree is on: Uncommitted changes, in the warning’s colour, with an ⓘ saying they stay. The new session says so too.
A project’s create menu makes a worktree too: New worktree at the default branch or at your folder’s branch, New worktree with my changes, which copies your uncommitted changes into it, New branch in worktree…, and a branch picked under Branch. Each goes in the same folder, named the same way, with your project’s files copied in (see Starting a session in a project).
If the checkbox can’t be checked, it says why: git isn’t installed, git is older than 2.23, git didn’t answer in time, or the repository has no commits yet.
If your repository has a post-checkout hook that fails or takes too long, the session still starts, with a note.
A worktree’s folder is trusted as the same folder in your main checkout is, for every agent. See a folder’s trust.
Copying files into a worktree
Section titled “Copying files into a worktree”Files that git doesn’t track, such as .env, aren’t in a new worktree. List them on the project,
one pattern per line, from the project folder. The ⓘ beside Files to copy into new worktrees
says so, and shows examples:
**/.env*copies.env,.env.localandapps/web/.env.production. It catches.envrctoo; to leave that out, write two lines instead,**/.envand**/.env.*.config/*.local.jsoncopiesconfig/db.local.json.
Claude Code needs none of its own .claude folders copied: in a worktree with no
.claude/commands, skills, agents or output-styles of its own, it reads your main
checkout’s, tracked or not, and Moontors lists them as it does (see
Conversation commands).
Where you edit the list, and how it’s applied:
- Edit them in Create session once Run in a new worktree is on, where the list is saved to the project when you create the session. Or set them as you add a project with Add project, or later with Edit project… in a project’s right-click menu in the header (see Projects).
- A project holds up to 50 patterns, of up to 200 characters each. A pattern must stay inside the
project folder, so an absolute path or
..is refused. **skips hidden folders (names starting with a dot, like.github). To copy from one, write its name:.github/.env*. Nothing inside a.gitornode_modulesfolder is copied.- Files are copied, never linked, and never replace a file that’s already there.
- A pattern that matches nothing, or more than 200 files or 64 MiB, is skipped with a note and copies nothing. The session still starts.
Several sessions in one worktree
Section titled “Several sessions in one worktree”A fork of a worktree session shares its worktree. So does a session you start in a folder of another
session’s worktree, from Create session with Run in a new worktree off, with
Start a session here on that worktree in the Git view (see
Worktrees and sessions), or from a project’s create
menu, by Branch on a branch another worktree has checked out, or Start in its worktree. Each
works in that worktree as the first session does: its card names the same repository and branch or
commit, /cd can’t move it, and they share the worktree’s terminals and its Git view. The worktree
stays until the last of them is archived or deleted. A session started there while the last one is
being archived waits for the archive, then joins the worktree if it’s still held, or starts in the
folder as in any other, if the folder is still there.
Archiving
Section titled “Archiving”Archiving a session stops its agent and removes it from the board, once you confirm, keeping its conversation; deleting it does the same in one dialog, and its conversation goes too (see Archiving and deleting). For a session with a worktree of its own, that dialog asks what goes with the worktree, under its path and branch, or its commit for one with no branch. Only what applies shows, and nothing that loses work is ticked for you:
- What else may be using it comes first. Another open session working in it, or a project you added whose folder is the worktree or one inside it, keeps it: Remove the worktree is greyed, naming them, and it’s kept for them. Programs with a folder inside it open, such as an editor or a dev server, and other sessions that mentioned its path or branch in the last day are named too, and leave Remove unticked, though you can tick it. On Windows the dialog says other apps can’t be checked there.
- Discard its uncommitted changes, with their count and the first files’ names, comes next where it has any. Until you tick it, the worktree stays, and nothing that goes with it shows, though the branch on its remote still can.
- Remove the worktree is ticked where nothing uses it and removing it loses nothing. Unticked, nothing is discarded and the worktree stays at its path.
- Under it, Delete the branch, ticked only for a branch Moontors made for the session that holds nothing beyond the commit it started from; a branch that was already yours shows too, unticked. Its line says how many commits on it no other branch or remote has, which deleting it loses, or the branch everything on it is on. It’s greyed while the branch is checked out in another worktree or your main checkout.
- A worktree with no branch whose commits no branch, tag or remote branch holds offers Make a
branch there in place of the branch’s box, with their count: name a branch to keep them, as
without one they’d be left only in git’s reflog. Characters git never takes in a name, such as a
space,
~or:, are dropped as you type them; any other name git won’t take, or one a branch already has, is said under the field before anything stops. - Beside Remove, Delete the branch on its remote, where it’s there: its upstream, or a branch of its name on a remote the repository knows, never the remote’s default branch or the upstream of a branch checked out in another worktree. It’s never ticked for you. Its line says how many commits on it no other branch of that remote has, which deleting it loses for everyone, or that nothing is lost. It’s deleted last, with your own git credentials, as a push is; if git can’t, as offline or for a protected branch, the archive still completes, and Archived says why on its row, with Retry.
- The button names each loss it takes, such as discarding 3 changes.
- If the agent left more changes or commits than the dialog showed as it stopped, the dialog shows again with the new counts, though the agent and the terminals have stopped by then. If git can’t remove the worktree, the session stays and says why, and its terminal tabs come back as fresh shells.
- A worktree you keep stays on the archived session: Archived says “Worktree kept at” its path, Reopen uses it as it is, and deleting the session later offers to remove it then. A delete that keeps the worktree says that Moontors no longer tracks it: add it as a project, or start a session there, to use it. One that keeps the branch alone says the branch stays.
- If the repository itself is gone, the worktree folder is left where it is, with a note naming it, for you to delete.
An archived session comes back with Reopen, from the Archived view. A worktree its archive kept is used as it is. Otherwise its worktree is made again from its branch, or, with no branch, at the commit it was on when the last session working in it left it, and the project’s files are copied in again. If another session still works in it, the session rejoins it as it is. A branch the archive deleted is gone, so its session reopens in the same folder of your main checkout, without a worktree of its own, and says so: see Archiving and deleting.