Git worktrees
A git worktree is a second checkout of the same repository, on another branch, in another folder. cornercase turns each one into a workspace, so every line of work has its own files, its own shells and its own agent, and none of them steps on the others: a build, a half-written change or an agent’s edits stay in their own folder.
When worktrees are available
Section titled “When worktrees are available”Worktrees are offered when the project folder is the root of a git repository, that is, it contains a .git folder. A project that is a subfolder of a repository, or a folder without git, gets plain workspaces instead.
Create a worktree workspace
Section titled “Create a worktree workspace”-
Click
+ Newunder the workspaces, then new workspace. -
Type the branch name. The dialog shows where the checkout will go.
-
Keep with its own worktree ticked (click it or press
Tabto toggle) and click create.
cornercase then, in the background:
- checks out the branch if it already exists, or creates it from the project’s current
HEADif it doesn’t, or, with settings → Worktrees → new branches on, from the project’s default branch, fetched from its remote first (if the fetch fails, the dialog shows why and nothing is made); - runs
git worktree addinto<worktrees folder>/<repository>/<branch>; - copies the files listed in
.worktreeinclude; - opens the new workspace with a shell in the checkout, which first runs the project’s setup if it has one.
If something goes wrong, the reason appears in red in the dialog and no workspace is added: for example when the checkout folder already exists, when git doesn’t accept the branch name, or when the branch is already checked out in another worktree.
Where checkouts go
Section titled “Where checkouts go”By default, checkouts live in ~/.cornercase/worktrees, grouped by repository. The folder name is the branch made safe for a path: lowercase letters and digits are kept, anything else becomes a dash, and repeated or trailing dashes are dropped.
| Repository | Branch | Checkout |
|---|---|---|
~/code/web-shop |
feat/login |
~/.cornercase/worktrees/web-shop/feat-login |
~/code/web-shop |
fix//The Bug! |
~/.cornercase/worktrees/web-shop/fix-the-bug |
~/code/orders-api |
issue-482-returns-page |
~/.cornercase/worktrees/orders-api/issue-482-returns-page |
To keep them somewhere else, change settings → Worktrees → worktrees folder. Use an absolute path or one starting with ~/. The change applies to new worktrees; existing ones stay where they are.
Commits to pull
Section titled “Commits to pull”When a workspace’s branch is behind its upstream, the workspace row ends with the number of commits you don’t have yet, such as ↓3, so you know it’s time to pull. It goes away once you pull.
- It works with any remote, not only GitHub, for branches that have an upstream (
git push -uorgit branch --set-upstream-tosets one). A branch without an upstream, or a folder without git, shows nothing. - cornercase runs
git fetch --allin the background for each project every 5 minutes, and counts the commits every few seconds, so a pull shows right away. The first fetch happens as soon as the project is open. - The fetch never asks for a password or passphrase: if it needs one, or the network is down, it fails silently and the number stays as it was. Use an SSH agent or a credential helper so it can run unattended.
To fetch more or less often, change settings → Worktrees → fetch branches every, in minutes. 0 turns it off: nothing is fetched and no numbers are shown.
Workspaces that change the same files
Section titled “Workspaces that change the same files”Worktrees keep agents from overwriting each other’s files, but two branches that change the same files can still conflict when you merge them. Turn on Settings → Worktrees → shared files (off by default) and, when two workspaces of a project change the same file, each one’s row shows ⇄ and how many files it shares, such as ⇄2, and those files carry a ⇄ in the changes panel. A file counts when both changed it since their branches parted, in a commit, staged, unstaged or as a new file; commits a branch inherited from the other don’t count.
Click ⇄2, or pick merge check in the row’s ⋯ menu (or right-click it), to see which files each other workspace shares with it. It also shows whether its work merges cleanly into its base branch (the one the changes panel compares with, as of the last fetch) and with each of those workspaces, and if not, which files conflict and how (contents, modify/delete, add/add…). The check merges the work as it is now, committed or not, in a scratch copy with git merge-tree. No checkout, index, branch or object of your repository changes, so you can run it while agents work. check again runs it again. It needs git 2.38 or later. New files git doesn’t track yet are included up to 1 MiB each, 8 MiB in all; the dialog says how many were left out.
- The scan runs in the background every few seconds while shared files is on, only in projects with two or more checkouts, with git options that never take the index lock. A plain folder, or a project with one checkout, costs nothing.
- Workspaces that share one folder are one checkout: they never count as sharing files with each other.
- For scripts,
cornercase changes sharedprints the shared files andcornercase changes merge-checkruns the check; see Scripts and agents.
Pull requests and their checks
Section titled “Pull requests and their checks”When a workspace’s branch has a pull request on GitHub, or a merge request on GitLab, its row ends with the pull request’s number, coloured by its checks, or marked when it has merge conflicts, so you see from the sidebar which line of work is green, still running or broken, without opening a browser:
| Mark | Means |
|---|---|
#486! in orange |
it has merge conflicts with its base branch: GitHub runs none of its pull_request workflows until they are resolved |
#485✗ in red |
a check failed |
#483• in yellow |
checks are still running |
#482✓ in green |
every check passed |
#482 in grey |
the pull request has no checks |
#482 in purple |
merged |
#482 crossed out |
closed without merging |
On GitLab the number is the merge request’s own and the colour is its pipeline’s. Elsewhere cornercase writes the merge request as !486, GitLab’s own reference; on the row it stays #486, since ! already means “needs you”. A job allowed to fail counts as skipped, as GitLab’s “passed with warnings”, and a pipeline that failed without any of its jobs failing (a failed child pipeline, an error in .gitlab-ci.yml) counts as one failed check named pipeline.
Click the number on the row, or click the row’s ⋯ (or right-click it) and pick pull request #485 (merge request !485 on GitLab), to see each check, failed ones first, with the workflow it belongs to (the stage, on GitLab):
A flow run shows the same number at the end of its diagram, and a click on it opens the same dialog.
A pull request with merge conflicts says so at the top (open · conflicts with main · 1 passed). GitHub runs no pull_request workflows until the conflict is resolved, so its list of checks may be missing some, often all but an app’s commit status. GitLab runs the pipeline anyway.
- copy link copies the pull request’s address, to open it in your browser.
- ask agent, shown when a check failed or the pull request has merge conflicts, pastes into the workspace’s agent that it has merge conflicts with its base and which checks failed and the links to their logs, so it can read them (with
gh run vieworglab ci trace, for example) and fix them. It is not sent: add what you want and pressEnter. Without an agent in the workspace, the text is copied instead.
With a prefix key, g p opens the dialog for the workspace on screen.
Stacked pull requests
Section titled “Stacked pull requests”On GitHub, stacked pull requests chain pull requests of one repository: the bottom one targets the trunk, each one above the branch of the one below, and they merge from the bottom up. When a workspace’s pull request is in a stack, its row shows its layer after the number, #483• 2/2, counted from the bottom the way GitHub counts (merged layers stay counted). The layer is grey. It turns red when a pull request below failed its checks and orange when one below has merge conflicts, since either keeps this one from merging whatever its own checks say.
Click the layer, or the number, to open the dialog. Between the summary and the checks it lists the whole stack, top first like gh stack view, each layer with its position, number, checks, title and the workspace of this project that holds it. The layer you opened is marked ▸, merged layers are purple and closed ones crossed out, and a click on a layer goes to its workspace. One line says what keeps the merge waiting, only when something does: cannot merge until #485 below passes its checks, cannot merge until #485 below has no merge conflicts or cannot merge until #485 below is approved. When a layer below was merged and your branch is behind its remote, a note says to pull before you push again.
How it works:
- cornercase runs
gh, GitHub’s CLI, in each workspace’s folder:gh pr viewfinds the pull request of the branch checked out there, also one an agent opened withgh pr create.ghmust be installed and logged in (gh auth login); without it nothing shows, and settings → Worktrees → pull requests says why. - A project whose
originremote (else its first) is on GitLab, gitlab.com or your own instance, usesglab, GitLab’s CLI, instead:glab mr viewfinds the merge request of the branch, in any state, andglab apireads the jobs of its latest pipeline. A host counts as GitLab when its name hasgitlabin it or whenglab auth statuslists it (its SSH host too); everything else, GitHub Enterprise included, stays ongh, andgithub.comnever runsglab.glabmust be installed and logged in to that host (glab auth login); without it nothing shows on the rows, and the settings note says why. If several merge requests come from branches of that name, the newest is shown. - Only workspaces on a branch of a repository with a remote are asked, and not the default branch (
origin’sHEAD). A workspace is asked again every 20 seconds while its checks run and for 5 minutes after they finish, when most pull requests get merged, and every minute otherwise; a merged or closed pull request, and a project whereghorglabfailed, every 5 minutes. Coming back to cornercase’s window (in a terminal that reports focus, as most do) asks again at once for every open pull request not read in the last 10 seconds, so one you merged in the browser shows as merged a few seconds later; a project whereghorglabfailed still waits. Opening the dialog, or runningcornercase pull-request, asks at once. - The stack is one more
gh api graphqlcall per stack, made at the pace of its pull requests and shared by every workspace of the project in it. A pull request in no stack is checked for one every 5 minutes. GitHub Enterprise Server has no stacks yet: it is asked once and then left alone. GitLab has none. - GitHub works out whether a pull request can merge in the background, and so does GitLab (
checking,unchecked). Right after a push to the branch or its base it may not know yet, so a new conflict can take up to a minute to show, and until then the row keeps what it showed. - Turn it off in settings → Worktrees → pull requests; nothing is asked then. Scripts and agents find the same in
cornercase status --json, under each workspace’spull_request, withconflicts,base,provider(githuborgitlab) andstack(nulloutside a stack).cornercase pull-requestlists every check with its link: see Scripts and agents.
Worktrees you made elsewhere
Section titled “Worktrees you made elsewhere”Every linked worktree of the repository shows up as a workspace, including the ones you create yourself with git worktree add or that another tool creates. cornercase looks for them about once a second, so they appear shortly after they exist. A worktree workspace with no tabs disappears when its folder is removed.
Bring your ignored files along
Section titled “Bring your ignored files along”A fresh checkout only contains what git tracks. Files that git ignores, such as .env files with local secrets, are missing. List the ones you want in every new worktree in a .worktreeinclude file at the root of the repository, using .gitignore patterns:
.env.envs/.env.localA file is copied into a new worktree only when it matches .worktreeinclude and is ignored by git. Tracked files are already in the checkout, and untracked files that git doesn’t ignore are left out on purpose. The matching is done by git itself, so it follows the same rules as .gitignore.
For example, with this .gitignore:
.env.envs/secret.txt| File | Copied? | Why |
|---|---|---|
.env |
Yes | Listed and ignored. |
.envs/.env.local |
Yes | Listed and ignored. |
secret.txt |
No | Ignored, but not listed. |
notes.md (untracked) |
No | Listed or not, git doesn’t ignore it. |
Files keep their place in the tree. If a file can’t be copied, the worktree is still created and the reason is written to the server log.
Set up each new worktree
Section titled “Set up each new worktree”A fresh checkout has no node_modules, no build and no local configuration. Give a project the commands that fix that and they run in every worktree cornercase creates: click ⋯ (or right-click) on the project and choose project settings. It is offered for projects whose folder is a repository root.
The dialog has two fields, setup and teardown, and a one-line build folders field (see Free build folders); Enter adds a line in the first two and saves from the third, Ctrl+← Ctrl+→ or Option+← Option+→ move by word, Shift or the mouse select (right-click to copy or cut), Tab moves between the three, and save stores them in config.json under projects.
npm cicp "$CORNERCASE_ROOT/.env.local" .env.localThe order in a new worktree is: git worktree add, the .worktreeinclude files, the setup in the workspace’s first tab, then the agent. The setup runs visibly in that tab, so progress bars, colours and prompts work and the output stays in the scrollback; when it ends, the same tab becomes your shell. Commands run with /bin/sh -e (the first failing command stops the script) in the worktree, with three variables set: CORNERCASE_ROOT (the project folder), CORNERCASE_WORKTREE (the new worktree) and CORNERCASE_BRANCH. To use your own shell’s functions, call it: zsh -lic 'nvm use && npm ci'.
On Windows, the setup and the teardown run with the sh that comes with Git for Windows, the same way, with Git’s tools (ls, cp, rm) found first and CORNERCASE_WORKTREE as a Windows path (C:\…). Without Git for Windows they run in PowerShell (PowerShell 7 if it is installed, Windows PowerShell otherwise), so write them for PowerShell: a failing cmdlet stops the script (a failing program only from PowerShell 7.4), and after the setup the tab stays in that PowerShell.
An agent that starts there (from an issue, cornercase start --worktree, the queue, a chat app or a flow) waits for the setup and starts only if it succeeded. If it fails, the tab shows a red !, a message says setup failed in project › workspace, nothing else starts and the output is there to read. Fix the cause and choose run setup in the workspace’s menu to run it again in a new tab; a script or another program does the same with cornercase setup. The setup runs only for worktrees cornercase just created, not for ones made elsewhere, workspaces reused on an existing branch, or after a restart. There is no time limit: press Ctrl+C in the tab to stop it. While it runs the workspace row shows setting up….
teardown runs before a worktree is removed, once its programs have stopped and before git deletes the folder, in the background with the same variables and a limit of five minutes. If it fails, the worktree is removed anyway and the message says removed <workspace>, cleanup failed in part, see server.log (the same when a role’s worktree could not be removed); the reason is in the log (cornercase logs), and cornercase close --remove-worktree prints it as a warning on stderr.
The commands are stored on your computer, not in the repository, so a cloned project cannot run anything until you have written it yourself; to share a setup with your team, commit a script and put one line, ./scripts/setup.sh, in the field. Cornercase’s log records sizes, exit statuses and timings, never the commands or their output; the only exception is a failed teardown, whose last output line (at most 160 characters) is logged at debug level.
Clean up worktrees
Section titled “Clean up worktrees”Worktrees pile up: each one keeps its checkout, with its node_modules or build output, until someone removes it. The Worktrees dialog lists the worktrees of your open projects, and those in the worktrees folder whose project you have closed (a worktree of a closed project made elsewhere is not found), shows what decides whether it can go, and removes several at once after one confirmation that names the risks.
Open it with Worktrees at the bottom of the sidebar (in the icon bar, its slot after TODO; on a small screen, in the projects menu) for every project, or from a project’s ⋯ menu (or right-click) → worktrees for that project only. The title then reads Worktrees › web-shop.
It lists the linked worktrees of your open projects and also those of projects you have closed, found in the worktrees folder, so a repository you no longer have open still shows what it left behind. Folders left in the worktrees folder that git no longer knows about are listed too; folders reached through a symbolic link are skipped, so nothing is ever deleted at a link’s target. The main checkout never is. Type in the field to filter by project or branch.
Each row has a checkbox, the project, the branch, the folder, how long ago it last changed, its size and some marks. Last changed is the newest of the last commit and the newest file git reports as modified or new, so ignored folders are never walked.
| Mark | Means |
|---|---|
●3 |
3 files changed or untracked |
↑2 |
2 commits that no remote branch has, so removing the branch loses them |
merged |
its commits are already in the base branch (the workspace’s base, else the default branch) and it was pushed, or its pull request (or merge request) is merged |
no commits |
it has no commits of its own and was never pushed, such as a worktree just made; it sorts with the rest, not with the merged ones |
upstream gone |
the branch’s remote branch no longer exists, usually deleted after a squash merge. Its commits still count as not pushed (↑n), since no remote branch holds them any more, and with also delete the branch the red line says they would be lost from this machine |
locked |
git worktree lock or Claude Code locked it |
claude, 2 running |
the program running in its workspace, or how many when there are several; shells waiting at their prompt don’t count |
1 outside |
processes working in its folder that its workspace doesn’t run: in another terminal, or in another cornercase tab that cd’d into it |
open |
it is a workspace in cornercase |
prunable |
its folder is gone, git still lists it |
repository gone |
its repository no longer exists, only the folder is left |
unknown to git |
its folder points at a git folder that is not part of any repository, so git no longer knows it |
? |
cornercase could not check it, so it is treated as having changes |
While the checks run the dialog says checking n of m… and keeps a fixed order, then sorts once: first the leftovers (prunable, repository gone and unknown to git), then the merged ones, then the rest, the oldest first within each. Rows never move after that, so the one under your pointer stays put. A worktree of a flow run’s role cannot be ticked, since it goes with the run’s workspace; the run’s own workspace can. changes on a row of an open project closes the dialog and opens that workspace’s changes panel, to look inside before deciding; closed projects have no workspace to open, so their rows have none.
Scripts and agents get the same list, with what makes each one safe to remove, from cornercase worktrees list, and remove what it shows with cornercase worktrees remove, which names the same risks and refuses them until told otherwise.
The size is what removing the worktree would free, with the part in build folders after it: 2.4 GB · 2.1 GB builds. It shows … while it is measured (a big tree takes a moment; the note says measuring n of m…) and ? when it could not be. It counts disk usage, not file lengths, a file with several hard links only when every link is inside the worktree (so pnpm’s store does not inflate it) and never follows symbolic links. Click largest first at the right of the filter to sort by size, safe first for the order above; either sorts once, when every size is known, and rows never move after that. The bottom left sums the space every worktree uses and, when worktrees idle for 7 days have builds, how much freeing those would recover: 12.4 GB in 9 worktrees · 8.1 GB of builds idle 7+ days.
Tick the rows to remove (click the circle, or press Space) and click remove n. Ticks on rows the filter hides stay ticked and are removed too, so the confirmation lists every one of them. Nothing stops and nothing is deleted until you confirm there.
The confirmation checks the ticked worktrees again, so work written since the list was made is named, and shows checking… until it is done. For each worktree it says what it has: files changed, commits not pushed (for a prunable entry, the commits of its branch), a lock with its reason, the shells and agents that stop, whether the project’s teardown runs first, and processes that have its folder open but that its workspace doesn’t run, found by their working directory: outside cornercase, such as a dev server started in another terminal, or in another cornercase tab. A folder git no longer knows says that it is deleted with its files. Worktrees with something to lose are shown in yellow. back (or Esc) returns to the list with your ticks.
also delete the branch is off by default. Ticked, each branch is deleted after its worktree, and those that are neither merged nor pushed are listed in red as losing their commits, as is one whose pull request is merged but that has moved since (commits made after a merge are on no remote). The branch deleted is the one the confirmation names, at the commit it had when it was checked: if the worktree has switched to another branch since, has no branch checked out, or the branch gained a commit, no branch is deleted and the final message says kept the branch …: it changed since the confirmation. The default branch and the main checkout’s branch are never deleted.
remove starts the work in the background, several worktrees at once, as a single removal does: the shells stop, the teardown runs, and git removes the checkout, with --force and unlocking where needed, since you confirmed knowing what each one has. Rows say removing… and disappear when done. A message at the end sums up, such as removed 4 worktrees and 3 branches, and names what failed. Branches are only deleted when you ticked the box.
Free build folders
Section titled “Free build folders”A worktree that has been idle for weeks still holds its node_modules or target/. A flow run started with --close-when-merged --free-builds frees its worktrees’ build folders by itself once its pull request merged and its agents closed (details). free builds, on a row (hover it) or at the bottom for the ticked rows, deletes just those folders and keeps the worktree, its branch, its files and its uncommitted changes. It opens a confirmation that says how much it frees and from which folders:
Only folders git ignores whose names are on the project’s list are deleted, at any depth: node_modules, target, .next, .turbo, dist, build, .venv and __pycache__ unless the project says otherwise. A build/ that holds a file git tracks, or a folder git does not ignore, is never touched, and the list is checked again when you confirm, so a folder you added to git in between is kept and named. A project changes the list in project settings → build folders, names separated by spaces (projects.<folder>.builds in config.json; an empty field means none), and its setup can rebuild what went. The confirmation checks the processes again and warns in yellow when a program runs there (one of the workspace’s tabs, one outside cornercase, one in another tab; shells at a prompt are left out) because it may still use those folders, and when a build folder holds a git checkout of its own (.venv/src/foo), whose changes would go too. It warns and lets you decide. A message at the end says freed 3.4 GB in 2 worktrees and names what could not be deleted. Scripts do the same with cornercase worktrees.
When merged worktrees hold builds, the total at the bottom adds them up (· 6.2 GB of builds in 4 merged worktrees) and a free merged button appears to the left of free builds, when the buttons fit. It opens the same confirmation for every merged worktree with builds, whatever the filter says and without touching the ticks, and lists each with its yellow warnings, so you decide as for any other. For a script or a routine, cornercase worktrees free-builds --merged does the same for every merged worktree without asking, and keeps the builds of any where a program runs (scripts and agents).
Remove a worktree
Section titled “Remove a worktree”Hover the workspace and click its ×. Because removing the workspace also deletes its checkout, cornercase asks first (the message adds Its teardown runs first. when the project has a teardown):
While the dialog is open, cornercase checks the checkout for modified or untracked files, which git would refuse to delete. If it finds some, the dialog says so and the button becomes remove anyway, which runs git worktree remove --force and throws those changes away. Click cancel to keep the worktree and save your work first.
A worktree can also be locked with git worktree lock; Claude Code locks the worktrees it creates while its session runs. The dialog then shows the lock’s reason and, when the reason names a process, whether it still runs: a lock whose process is gone was left behind, for example when a restart ended the session. unlock and remove unlocks it and removes it. If the process still runs, cancel and end it first. From a script, cornercase close --worktree BRANCH --remove-worktree --check shows the same before anything stops, and --unlock does unlock and remove; see Scripts and agents.
remove closes the dialog at once, so you can go on working while the folder is deleted, which takes a while for a checkout with node_modules or build output. The workspace’s programs are ended first, and its row stays, dimmed, with removing… at its end until git has finished; meanwhile it can’t be opened. If it was the workspace on screen, the view moves to the nearest one, above it when there is one. When git is done, the row goes and a message says removed <workspace>. If git refuses after all, for example because a file changed in the meantime, the row comes back without its tabs and a message gives git’s reason; click its × again to remove anyway. You can remove several worktrees at once, with a single confirmation, from the Worktrees dialog.
A run of a flow can give roles worktrees of their own: they go with the run’s workspace, which is checked, torn down and removed together with them (the message names how many), and one cannot be removed alone while its run lives. Their branches are kept, unless you remove the run’s workspace from the Worktrees dialog with also delete the branch ticked.
A workspace of one of your machines has the same × and the same dialog, which names the machine (… on vps) and shows what the machine found. Its programs stop and its folder is deleted on the machine. If the machine can’t check, the dialog closes and nothing is removed.
Worktrees from issues
Section titled “Worktrees from issues”Starting an issue from the issue browser in a repository creates a worktree too, on a branch named after the issue, such as issue-482-returns-page-crashes-on-empty-address, which you can change before it is made, or set once for every issue in settings → Worktrees → issue branches (see Your team’s branch names). Everything on this page applies to it, new branches included: with it on, the issue’s branch starts from the project’s default branch, fetched first, rather than from the commit your own folder is on.