Skip to content

git.worktree_remove

git.worktree_remove deletes a linked git worktree that a session made: its directory, then its registration. For a named branch, the branch step runs last. The daemon runs no git worktree remove and no git worktree prune.

Treat worktreePath as a path to delete, not a filter. Without worktreeRoot, a plain directory inside the repository is deleted too, and the reply is success.

An untagged rule on this page matches the reference as measured on 5fd08069 or on an earlier build.

Request

{"baseRepo": "/repo", "worktreePath": "/repo/.claude/worktrees/w1", "branchName": "w1"}
Parameter Required Meaning
baseRepo yes The repository.
worktreePath yes The worktree to delete. See Paths.
branchName no The branch that the branch step deletes after the worktree.
worktreeRoot no A location outside the repository, as on git.worktree_create.
shadowDirOff no true turns off, for this request, the daemon's own read of the repository's git config and the settings copy. A git request that starts while such a request runs gets the same.

Response

Success:

{"success": true}

If the branch step keeps the branch, the reply is {"success":true,"branchKept":true}. It keeps the branch too if it cannot read the branches, for example for a baseRepo that holds no repository or does not exist. Then branchKept comes even for a missing branch. The member is always true. A deleted branch, a branch that does not exist, an empty branchName, and a name that starts with - or + give a plain success.

Failure:

{"success": false, "error": "<text>"}

A failure has no errorCode. Unless a section below says otherwise, a failure deletes nothing. Most texts start with one of these phrases:

Start of the text Meaning
refusing to remove worktree: The daemon refuses this path or this worktree.
failed to remove worktree: could not check whether <p> is locked The daemon could not read the repository safely. A text in brackets ends with ; retry. Only a passing cause, such as a file that changed during the request, gives a second try a chance. A repository that git cannot use fails again in the same way. A text after a colon has no ; retry.
failed to remove worktree: with another text A check or a delete step failed.

In the texts, <p> is worktreePath as sent, except one Windows home refusal (Platform notes). Three texts start in another way: the home refusal worktreePath must not be or contain the home directory: "<p>", the managed-worktrees refusal baseRepo is inside a managed worktrees directory …, and the registration text of step 3 below.

Error texts

The shared texts are in the error-string catalogue. A row with no mark holds a text of the reference, measured on Linux. A mark such as "measured on macOS" limits its sentence to that system. A sentence that names systems without "measured" holds on each one. <repo> is baseRepo as sent in every row. A row in the first two groups below deletes nothing unless it says so.

Path and location

Text Cause
refusing to remove worktree: <p> {is a relative path / contains a ".." component / has a component Windows reads as a different name (trailing dot or space, or a colon) [Windows] / is not inside the repository <repo>; …} The spelling refusal is Windows only and comes before containment. Without worktreeRoot the relative-path text puts <p> in backticks (4c111e86 and c9125eb8, measured on Linux, claustrum's own on macOS and Windows). In the is not inside text <p> is in backticks and <repo> is as sent (be1c1ca5, measured on Linux and macOS). A path with a backtick is quoted as in Go, and a path over 300 bytes is cut (from the code, not measured). An absent or empty baseRepo gives the empty string for <repo>. With worktreeRoot, the first two texts also refuse a relative, absent or .. baseRepo, and <p> is then baseRepo as sent. An empty worktreePath gets the first text there
failed to remove worktree: "" does not name a directory (empty worktreePath, without worktreeRoot)
refusing to remove worktree: <root> is a filesystem root; choose the worktree location by its absolute path, without "..", beneath the filesystem root Linux and macOS, with worktreeRoot. The rules of the create row hold. claustrum tests a relative worktreePath first, as on create (not measured on remove). No git call runs
refusing to remove worktree: `<root>` is the repository <repo> or inside it; a worktree location must be outside the repository With worktreeRoot, Linux and macOS. It cleans both paths and compares whole components. A root that is baseRepo or lies beneath it is refused, and <B>/Tx beside <B>/T passes. <root> is worktreeRoot as sent, in backticks (b3081b51, measured on Linux and macOS). <repo> keeps <T>/ and <T>/.. No git call runs
refusing to remove worktree: <root> leads into the repository <repo> (at <at>); a worktree location must be outside the repository With worktreeRoot, Linux and macOS. The daemon resolves the symlinks of the longest existing part of the root and appends the missing rest. <at> is the outermost path from there up to / that is the same file as the git top level of baseRepo, the main checkout or the git directory, also a separate one. The main checkout is the first entry of worktree list. For a linked baseRepo that is the checkout, also with core.bare=true, the <P> of a bare <P>/.git, or a bare R.git (create and remove, 87375cc7 and edb2ad3a, measured on Linux and macOS). In shadow the daemon takes the path, also resolved, of the git directory with no final /.git (from the code). A root in the settings copy gets this text too (claustrum's own, not measured). A separate git directory is its own entry. A remove then deletes a worktree in the main checkout (same builds and systems, measured). So <at> is a prefix of the resolved root, as /private/tmp/… for /tmp/… on macOS. A bind mount (Linux), a firmlink spelling and a case variant (macOS) match too, and <at> keeps their spelling, also for the main checkout of a linked baseRepo. If both checkouts hold the root, the main checkout is named. A folder nearer to / that the row below matches gives that text (from the code)
refusing to remove worktree: <root> leads into <wt>, a worktree of the repository <repo> (at <wt>); a worktree location must be outside the repository's checkouts With worktreeRoot, Linux and macOS. <wt> is a linked worktree in worktree list that is the resolved root or a parent of it by whole components. The test compares <wt> as listed, as a string: no symlink resolve, no case fold, no file identity. It skips a listed worktree whose path does not exist, also a locked one. Another lstat error keeps the entry (not measured). Of two nested worktrees, the outer one is named. A root that holds a linked worktree passes
failed to remove worktree: the worktree location <root> is not reachable (<reason>); nothing was removed — retry once it is available, or remove the worktree by hand With worktreeRoot, Linux and macOS. The root passes the three tests above but does not exist or does not resolve. <root> is worktreeRoot as sent. For a root that does not exist, <reason> is <path> does not exist, with the links of its existing part followed and a final slash dropped. A root below a regular file gets <file>: not a directory. For a symlink that does not resolve, <reason> is the error of the resolve, for example lstat <target>: no such file or directory. For permission denied the text is failed to remove worktree: lstat <root>: permission denied (Linux)
refusing to remove worktree: <c> is a symbolic link; a symlinked .claude or .claude/worktrees … It keeps the delete off a planted link (not measured on be1c1ca5)
refusing to remove worktree: {`<t>` is a symbolic link, not a worktree directory / <t> is not a directory} A leaf that is a symbolic link or not a directory. Nothing is deleted (measured on macOS). On Windows a junction leaf gets `<t>` is not a directory (4c111e86, measured on Windows). Another reparse point leaf that is no link, folder, socket or dedup file gets the same text (claustrum's own, not measured)
refusing to remove worktree: <t> changed while the removal was checking it claustrum's own text for a leaf that another directory replaced between the open of the leaf and its identity check, before the git calls. On Linux and macOS, with worktreeRoot, a <directory> that turns into a symlink out of the root between two looks answers failed to remove worktree: openat <directory>: path escapes from parent (claustrum's own)
failed to remove worktree: `<leaf name>` was replaced while the daemon was using it A leaf that another folder or a link replaced between the open of the leaf in the delete step and its identity check. Nothing is deleted (4c111e86, measured on Linux). macOS and Windows are claustrum's own, not measured
failed to remove worktree: openat <path from baseRepo>: path escapes from parent Windows, when a folder between baseRepo and the leaf is a reparse point that os.Root refuses and no junction. <path from baseRepo> is the folder that holds the leaf, relative to baseRepo. claustrum's own text, not measured
worktreePath must not be or contain the home directory: … D2. Without worktreeRoot the containment answers first. Then it fires for a repo that is an ancestor of home, or on Windows behind a junction (Platform notes). A leaf folder that is home or holds it by identity gets it too

Locks and the repository

Text Cause
refusing to remove worktree: `<p>` is locked (git worktree lock); unlock it to remove it For a LOCKED worktree (success:false). Measured for a lock with no reason and the reason x. On Linux and macOS claustrum also refuses some locks where the reference deletes the folder or answers success (D22)
refusing to remove worktree: `<p>` is gone but its registration is locked (git worktree lock); unlock it to remove the registration and branch For a gone worktree with a locked registration. Nothing is deleted (measured on macOS). On Linux and macOS a gone worktree whose locked entry sits behind a linked <git dir>/worktrees gets success, and its branch goes
refusing to remove worktree: `<p>` was left locked by a create that did not finish; unlock it first (git worktree unlock '<p>', then remove it again) The lock reason is initializing. Windows quotes the hint path with double quotes. Build be1c1ca5, measured on Linux, macOS and Windows
refusing to remove worktree: `<p>` is gone but a create that did not finish left its registration locked; unlock it first (git worktree unlock '<p>', then remove it again) to drop the registration and branch The same for a gone worktree. The registration stays. Build be1c1ca5, measured on Linux, macOS and Windows
failed to remove worktree: could not check whether <p> is locked (<reason>); retry For a gone worktree. Without worktreeRoot, <reason> is the hooks refusal (measured on macOS). The trust refusal and the git cannot run text follow is locked: instead, with no retry (b3081b51 for git cannot run, 4c111e86 and c9125eb8 for the trust refusal, measured on Linux, claustrum's own on macOS and Windows). So does the refusal of the daemon's GIT_CONFIG_COUNT (measured on Linux, macOS and Windows). An older macOS row put the trust refusal in parentheses, and the newer Linux row wins. claustrum puts a limit refusal of the listing there too, not measured on remove. With worktreeRoot and a missing absolute baseRepo without a .. component, <reason> is the refusal of the daemon's GIT_CONFIG_COUNT (Linux and macOS)
failed to remove worktree: could not check whether <p> is locked: <text> Without worktreeRoot. <text> is the text of the refused step
failed to remove worktree: could not check whether <p> is locked (its registrations could not be examined); retry The lock-check refusal, for a worktree directory that exists. Without worktreeRoot: the listing of baseRepo cannot be used, baseRepo holds no repository, or the trust check refuses its git directory, except for some stray commondir refusals (Repository checks). A refused GIT_CONFIG_COUNT of the daemon gets it too, also for a baseRepo such as <T>/missing/... In both modes: the worktree registry exists but cannot be read, or, on Linux and macOS, is a symbolic link. On Windows a remove without worktreeRoot and with no git gets it (87375cc7 and 13047a51, measured on Windows, rule)
failed to remove worktree: could not check whether <p> is locked (the repository at <baseRepo> could not be read); retry With worktreeRoot. An absolute baseRepo without a .. component is missing, and the worktree directory exists. The daemon's GIT_CONFIG_COUNT is refused (Linux and macOS). With no git on PATH (Linux), it answers a worktree directory that holds a file, is empty, or has a .git file naming its entry
failed to remove worktree: cannot determine the repository's work tree: <reason> With worktreeRoot only. <reason> is a trust refusal text, exit status 128, the hooks refusal, the refusal of the daemon's GIT_CONFIG_COUNT or a failed start test. It is also git finds no repository here: <git text>, on Linux and macOS also with git 2.56.1 (4c111e86, measured on Linux and macOS). With no git on PATH it is the exec error alone, where baseRepo exists. claustrum also puts the git cannot run text and a limit refusal of the listing there (not measured with worktreeRoot)
failed to remove worktree: cannot determine the repository's git directory: <reason> With worktreeRoot only. The listing before git rev-parse --absolute-git-dir fails. <reason> is the hooks refusal. If git version fails too, it is the git cannot run text. Nothing is deleted (be1c1ca5 and b3081b51, measured on Linux and macOS). A listing whose folder went and one that says git finds no repository go on to the rev-parse (claustrum's own, not measured). Two answers of that rev-parse that name another git directory give the disagree text as <reason> (c9125eb8, macOS, claustrum's own on Linux)
failed to remove worktree: cannot list the repository's worktrees: <exec error> With worktreeRoot only. git worktree list --porcelain -z and then git worktree list --porcelain both fail in baseRepo, for example with exit status 128
failed to remove worktree: statat .claude: permission denied / failed to remove worktree: open <baseRepo>: <error> Without worktreeRoot only. baseRepo cannot be searched (mode 0600), or cannot be opened (mode 0000, or on Windows a regular file). On Linux and macOS the first text names the first component of worktreePath below baseRepo, for example statat wt
failed to remove worktree: open <root>: permission denied / failed to remove worktree: openat <name>: permission denied / failed to remove worktree: statat .: permission denied Linux and macOS, for a folder that the daemon cannot read or search. See Platform notes

These rules are of build be1c1ca5. In the four lock texts that start with refusing, <p> is worktreePath in backticks (measured on Linux, macOS and Windows). In the plain lock text a path over 300 bytes shows its first 300 bytes, with no ellipsis (measured on Linux). The other texts cut it the same way (not measured). A path with a backtick is quoted as in Go (from the code). A locked file of 1048577 bytes gives the plain text (measured on Linux). The hint path is whole, and a $ keeps the quoted hint (from the code).

Delete failures

Text Cause
failed to remove worktree: RemoveAll <entry>: <errno text> When the delete of the worktree fails part-way. If an entry other than .git fails, .git stays. The registration of the worktree and the branch stay in every case (measured on macOS)
removed the worktree but could not drop its registration (RemoveAll <name>: <errno text>) success:false, from step 3

Where the paths can be

Without worktreeRoot:

  • worktreePath must be absolute, carry no .. component, and sit strictly under baseRepo. Otherwise the text is refusing to remove worktree: <p> …, with the same reasons as on git.worktree_create.
  • A symbolic link at any directory between baseRepo and the worktree, such as .claude, is refused.

With worktreeRoot:

  • worktreePath must be <worktreeRoot>/<directory>/<name>.
  • A symbolic link at the <directory> level gives refusing to remove worktree: <dir> is a symbolic link; the directory under the worktree location must be a real directory. With a root in the main checkout of a linked baseRepo that text differs: 87375cc7 and edb2ad3a send leads into (remove, measured on Linux and macOS).
  • A <directory> level that is or holds the main checkout or a bare R.git, by file identity, gets the would place worktrees in <dir> text, also below a linked root. <dir> is resolved (create and remove, 87375cc7 and edb2ad3a, measured on Linux and macOS). Claustrum's own, not measured: the create with core.bare=true, or of the main checkout below an unlinked root, below a linked root a level that holds it and a bare repository, a bare <P>/.bare and the <P> of a bare <P>/.git with a baseRepo outside the level, a separate or linked git directory, a bind mount, a case variant, shadowDirOff, the <dir> of a linked root with the main checkout as baseRepo.
  • The location refusals include reserved names (.git and .claude-managed-worktrees, in any letter case) and link loops. The remove runs no ancestor test.
  • The containment in the repository does not apply here. So the home guard refuses a worktreePath that is the home directory or holds it, with the home refusal above (D2).

On both:

  • The home guard (D2) runs before the delete.
  • A baseRepo inside a directory of managed worktrees (marker rule) is refused with the managed-worktrees text. So is a baseRepo that is not missing and does not resolve, for example <T>/a.txt/... On Windows .. drops the name before it untested, so <T>\t.txt\.., <T>\missing\.. and a junction before .. pass (b3081b51, measured on Windows). The same walk serves git.worktree_create and git.list_branches. A folder on the real path that denies List to the daemon fails it (87375cc7, measured on Windows).
  • The backticks of the symbolic link text of row 65 follow 4c111e86 (measured on Linux, claustrum's own on macOS and Windows). <t> is the path with the symbolic links of baseRepo, or of the root, resolved. On macOS a path under /tmp therefore reads /private/tmp/….
  • On Windows, a junction between baseRepo and the worktree gets {"success":true}. The branch ref goes, and the folder behind the junction stays. A registration whose record names the real path stays (4c111e86, 87375cc7, measured on Windows). One whose record names the leaf as the caller spelled it goes (4c111e86, 87375cc7, measured on Windows).

The repository checks

Before any delete, the daemon checks the repository.

  • The trust check runs on baseRepo. Without worktreeRoot, if it refuses the git directory, a worktree directory that exists gets the lock-check refusal, and a gone one gets … is locked: <trust refusal text> (row 78). An existing one gets that text too for these kinds of stray commondir. Its git directory fails the git-directory test (b3081b51, measured on Linux and macOS, claustrum's own on Windows). Its content is not . or ./, with any HEAD (measured on Linux, macOS and Windows). On Windows it is not a small plain file (4c111e86 and c9125eb8, measured for a dangling junction). With a daemon GIT_DIR or GIT_COMMON_DIR this is not measured.
  • Without worktreeRoot, a git config of baseRepo that the daemon does not accept gives … is locked: <text> (the texts). "shadowDirOff":true turns this check off. A remove that starts while a "shadowDirOff":true request runs gets no such refusal either. It then deletes on a config that only the daemon refuses.
  • Without worktreeRoot, a failure of the settings copy gives the same form. A failed start test of the settings copy refuses the remove. So do a bad answer of git about the repository and a copy folder that cannot be made. A missing daemon GIT_DIR differs (below). A baseRepo that does not exist runs no start test and no git version (4c111e86, measured on Windows for a local baseRepo). Below a repository on a share the start test still runs, and so it does with a daemon GIT_DIR (claustrum's own). The next request that needs the test runs it. For a share host that does not resolve the calls are measured: none, and the test later. Linux and macOS, and a baseRepo below a local repository, are claustrum's own, not measured.
  • Without worktreeRoot, for a worktree directory that exists, a failed listing of the configuration runs once more. If the second try fails too, the text is … is locked: <text of the failed listing>. For a gone worktree directory there is no second try, and the text is … is locked (<text>); retry. The git cannot run text follows is locked: there instead, with no retry (row 78).
  • Without worktreeRoot, in the state shadow, an answer of git rev-parse --absolute-git-dir that names another git directory gets one more call. A right second answer goes on. A wrong one gives … is locked: <text> after 4 calls, with the disagree text, and nothing is deleted (c9125eb8, measured on Linux and Windows). 87375cc7 asks so under a relative daemon GIT_DIR that it ignores (measured on Windows). These parts are claustrum's own, not measured:
    • macOS, and the content of calls 3 and 4.
    • The ask runs only in the state shadow. It needs a trusted verdict that pins a git directory, and no daemon GIT_DIR or GIT_COMMON_DIR that the request keeps (the Windows rule). An empty answer counts as before.
    • The text comes from the second call.
    • A failed second call gives the lock-check refusal after the repeated check. A copy that went on the second call gets it too.
    • For a linked worktree as baseRepo, the text names the entry of that worktree.
    • A call 3 with a right answer still refuses, after 3 calls.
  • With worktreeRoot, the daemon must find the work tree of the repository. If it cannot, the cannot determine the repository's work tree text answers. The reason: git cannot start, the trust check refuses or finds no repository, or the git config or the settings copy is refused. Or the configuration listing fails, baseRepo is itself a git directory, or git rev-parse fails. A failed listing before git rev-parse --absolute-git-dir gives the cannot determine the repository's git directory text instead (be1c1ca5 and b3081b51, measured on Linux and macOS). A listing that says git finds no repository, or whose folder went, goes on to the rev-parse (claustrum's own, not measured). A baseRepo that does not exist skips this check.
  • With worktreeRoot, in the state shadow, an answer of git rev-parse --absolute-git-dir that names another git directory gets one more call, with its listing. A wrong second answer gives the cannot determine the repository's git directory text after 6 calls, and nothing is deleted (c9125eb8, measured on macOS). Linux is claustrum's own, not measured. So are a right second answer, which goes on, and a failed second call, which gives the work-tree text.
  • A worktree that is locked (git worktree lock) is refused. A lock in the .git folder of baseRepo is refused too (D22). With no daemon GIT_DIR and no worktreeRoot, a lock counts only on an entry whose gitdir record names the worktree. If the leaf's .git file names such an entry, only its lock counts. A lock that does not count stays, and the leaf and the branch go (b3081b51, measured on Linux).

Without worktreeRoot, a baseRepo whose refs has mode 0600 holds no repository (build 52d82f0a, Linux and macOS), and so does one with no refs (c8e2f083 and 52d82f0a, Linux). Blanks, a tab, CR LF or a NUL after ../.. in the registration's commondir refuse nothing (52d82f0a, Linux, macOS and Windows). If the listing fails in a plain folder, the text is … is locked: <text of the failed listing>. If the listing passes there and git rev-parse --absolute-git-dir fails, the two calls run once more (89cb6289, measured on Linux and macOS). On Windows in the state shadow they run one time (87375cc7, measured on Windows). That holds with no daemon GIT_DIR or an absolute one of a folder that the trust check trusts, and no daemon GIT_COMMON_DIR that the request keeps (the Windows rule). The row measured the .git folder of a plain repository. Other folders, as a bare repository, a linked-worktree entry or a folder with no repository, are claustrum's own, not measured. With another daemon GIT_DIR that the request keeps they run once more (claustrum's own, not measured). In the other states, shadowDirOff included, the same rule holds (claustrum's own, not measured). The reply is the lock-check refusal, and the worktree stays. A gone worktree directory whose listing passes gets success, and no registration goes. With worktreeRoot, no repository gives the work-tree refusal, also for a gone worktree.

If <git dir>/worktrees exists but cannot be read, a worktree that exists gets the lock-check refusal. A gone one gets success, and its registration stays.

On Linux and macOS without worktreeRoot, a gone worktree gets {"success":true,"branchKept":true} for a named branch in four states, with no delete (b3081b51, measured on Linux and macOS, the last on Linux):

  • baseRepo is a regular file. A failed git version gives the git cannot run lock text.
  • The .git file of baseRepo names a regular file, and the daemon has an incomplete GIT_CONFIG pair.
  • The daemon's GIT_DIR names a missing path. An existing worktree folder goes with its files, with the same reply (measured on Linux and macOS). So does one with an unlocked .git folder in baseRepo (b3081b51, measured on Linux, macOS not measured). A lock there that names it keeps the D22 refusal. A .git link or file keeps the copy refusal (claustrum's own, not measured). With a worktreeRoot outside the repository the reason is class 2 with open <GIT_DIR>: no such file or directory (measured on Linux).
  • With git 2.56, the .git file of baseRepo names a path that does not exist and is no entry under worktrees, in both modes. 4c111e86 gives that reply on Linux, macOS and Windows (measured with git 2.56.1). As the first git request of a daemon, the reply is claustrum's own, not measured.

On Windows without worktreeRoot, a gone worktree gets that reply where git finds no repository in a folder the trust check accepted. A baseRepo on a share with a .git folder gets it, and its lock, registration and branch stay (4c111e86, measured on Windows). A baseRepo one folder below it gets the reply too (4c111e86, measured on Windows). A baseRepo deeper than one folder, a .git file or link above it, and a .git on the way that the daemon cannot look at are claustrum's own, not measured. The text of git and an unreadable registrations folder are claustrum's own. Elsewhere the first call exits 128 with fatal: not a git repository or fatal: error reading '<git dir>', the second run exits 0, and <baseRepo>\.git\config has 262, 267 or 269 characters (b3081b51, measured on Windows). 120, 250 and 259 gave another reply (measured), and the other lengths from 262 to 269 get success (claustrum's own). A worktree that exists, another text of git and another length keep the lock-check refusal (claustrum's own, not measured). A daemon GIT_ALTERNATE_OBJECT_DIRECTORIES refuses before the replies of a gone folder, and the place of that refusal is claustrum's own.

What the delete removes

The registration is the folder <git dir>/worktrees/<name> that git keeps for each linked worktree. <git dir> is the git directory of the main repository, also for a linked worktree as baseRepo. A daemon that sets GIT_DIR and GIT_COMMON_DIR that the request keeps (the Windows rule) uses the repository that GIT_DIR names.

The daemon finds the registration from the .git file of the worktree. The registration must name the worktree back. Without such a registration, it deletes the one registration whose record names worktreePath. If two match, it deletes none. If a registration that matches is locked, the request is refused first. Without worktreeRoot, if the path compare misses the registration (another letter case on macOS, an 8.3 short name on Windows), the worktree directory still goes and its registration stays.

The steps:

Step Deletes If it fails
1 The files of the worktree directory, except .git, in the order of the directory read. The delete stops at the first failure with the RemoveAll <entry> text. That entry, the entries after it and .git stay.
2 .git and the worktree directory. If the directory itself cannot be deleted, it stays empty.
3 The registration. If a verified registration cannot be deleted, the reply has success:false and the text removed the worktree but could not drop its registration (RemoveAll <name>: <error>). The branch step still runs. If a registration found by its record cannot be deleted, the reply is success all the same.
4 If branchName names a branch, the branch step. After the failure text of step 3, a kept branch adds "branchKept":true after error.

No delete follows a symbolic link out of the worktree directory or out of its parent.

On Linux and macOS without worktreeRoot, a baseRepo that does not exist, such as <T>/missing/.., still lets the worktree directory go. Its registration stays. With no git on PATH, a worktree directory that exists gets the lock-check refusal. A gone one gets success, with branchKept when the request names a branch, and its registration stays.

With worktreeRoot, a directory without a verified registration goes in two cases only: it is empty, or it is a stale worktree of baseRepo whose registration is gone. Any other directory is refused and stays: refusing to remove worktree: <p> is not a worktree of <repo> (<reason>), so it is left in place; remove it by hand if it is a leftover. For a missing baseRepo, the reason `<p>` has no .git file puts the path in backticks (b3081b51, measured on Linux and macOS). Windows is claustrum's own, not measured. For a baseRepo that exists the path stays plain (claustrum's own, not measured). A read error there gives failed to remove worktree: could not verify that <p> is a worktree of <repo> (<detail>); retry, with the cleaned path as <p>. A baseRepo that does not exist with no git on PATH gives the the repository at <repo> could not be read text.

For a gone worktree directory, the daemon looks up the registration by path after the repository checks. If no lock refuses it, the one registration that names the worktree goes, the branch step runs, and the reply is success. The trust check rules read a .git file of baseRepo. A NUL after the path, or a second blank after gitdir:, names the repository whose registration and branch go. Without worktreeRoot, a blank after the path: only the branch goes (build c8e2f083, measured on Linux).

Platform notes

  • worktreeRoot is allowed.
  • The path compare of a registration is exact. On macOS a path in another letter case does not match.
  • If <git dir>/worktrees is a symbolic link, a worktree that exists gets the lock-check refusal, and nothing is deleted. A gone worktree gets success, and the branch step runs. Its registration stays.
  • A folder that the daemon cannot read or search is refused. Without worktreeRoot that holds for the folders between baseRepo and the worktree. With it, it holds from the root down. Each text follows failed to remove worktree::
The folder Text
The root, with no read bit (mode 0300, 0100, 0000 or 0200) open <root>: permission denied
A folder below the root or below baseRepo, with no read bit openat <name>: permission denied
A folder below the root or below baseRepo, or the root, with the read bit and no execute bit (mode 0600 or 0400) statat .: permission denied
The folder above the root, with mode 0600 lstat <root>: permission denied
baseRepo itself, without worktreeRoot, mode 0600 statat <first component>: permission denied
baseRepo itself, without worktreeRoot, mode 0000 open <baseRepo>: permission denied

<root> is the root with its symbolic links resolved. <name> is one path component. If two levels are restricted, the higher one gives the text. A gone worktree under such a folder gets the text of that folder. A daemon that runs as root deletes the worktree under a root of mode 0300.

  • worktreeRoot gets refusing to remove worktree: `<root>` cannot be used: a custom worktree location is not supported on Windows hosts yet (b3081b51, measured on Windows).
  • An unreadable folder is not measured.
  • If <git dir>\worktrees is a junction or a directory symbolic link, a worktree that exists gets the lock-check refusal. The leaf, the registration behind the link and the branch stay (b3081b51, measured on Windows). With "shadowDirOff":true the refusal holds too (claustrum's own, not measured). A gone worktree whose entry is not locked gets success, and its branch goes. The registration behind the link stays (b3081b51, measured on Windows). A gone worktree with a locked entry behind the link gets the locked refusal, and nothing is deleted (claustrum's own, not measured).
  • The path compare of a registration ignores letter case and slash direction. An 8.3 short name does not match a worktree that exists. A baseRepo through a subst drive or a junction to the repository matches, and the registration goes.
  • A baseRepo with a junction before its last name, such as <out>\JP\repo, finds a worktree that exists. The leaf, the registration and the branch go (measured on Windows). A folder on the real path of baseRepo that denies List gets the managed-worktrees refusal, and nothing is deleted (87375cc7, measured on Windows). If the path behind the junction is home or holds home, the reply is worktreePath must not be or contain the home directory: "<path behind the junction>", and nothing is deleted (D2, claustrum's own, not measured).
  • A junction in baseRepo that moves to a second repository during the remove: the leaf and registration of the first repository go, and its branch stays. In the second repository the ref of the same name goes (4c111e86, 87375cc7, measured on Windows). A request with no hold deletes the entry as the entry delete bullet below says. A second repository that the daemon's read refuses keeps its ref, and the reply has "branchKept":true (claustrum's own, not measured). The daemon pins the identity of the baseRepo folder and holds one handle of its real git directory before it locates the worktree. A locate that opened another folder, also after a move and a move back, gets the lock-check refusal and deletes nothing (claustrum's own, not measured). On a later move of a live leaf the locks are read in the pinned git directory, or the remove refuses when that pin no longer stands (claustrum's own, not measured).
  • A gone leaf whose baseRepo moves to a second repository right after rev-parse --absolute-git-dir answers success. Only the ref of the same name goes in the second repository, and the entry of each repository stays (87375cc7, measured on Windows). claustrum's first move test sees that move (removeGoneAfterMove, from the code). A locked entry of the leaf in either repository or a gate that refuses keeps everything (claustrum's own, not measured). With no pinned git directory, a move that the move test sees keeps everything (claustrum's own, not measured).
  • Take a gone leaf with no .claude folder, and a plain folder above baseRepo that moves to a second repository after rev-parse --show-toplevel. In most runs that repository keeps its ref of the same name, and the reply is {"success":true,"branchKept":true}. 13047a51 does so in 41 of 60 runs, deletes the ref with {"success":true} in 15 and gives an error in 4. 87375cc7 gives 14, 4 and 2 of 20 (measured on Windows). claustrum keeps the ref with "branchKept":true in 15 of 20 runs and deletes it with {"success":true} in 5 (measured on Windows). On claustrum only that ref of the second repository goes then. A lock on the worktree of that branch in the second repository does not always keep the ref. It still goes in 10 of 30 runs on 13047a51, 2 of 10 on 87375cc7 and 3 of 10 on claustrum (measured on Windows). claustrum closes its handle of the git directory after the entry step. Its Windows test shows that the open handle blocks the rename (measured on Windows). A move that its last move test sees gets "branchKept":true. A later one reaches the branch step by path (from the code).
  • If .git of baseRepo becomes a junction to a second repository during the tree delete, the leaf goes and the reply is removed the worktree but could not drop its registration (".git" is a link or a file where Claude needs a real directory; put the directory itself in its place) with "branchKept":true. Each registration and branch stays. Before that reply one more rev-parse --git-dir call runs (87375cc7, measured on Windows).
  • With "shadowDirOff":true the same swap gives the same text with no branchKept. The branch step runs by the path, and the ref of the same name goes in the second repository, also for a locked worktree there. Its entry, leaf and lock stay (87375cc7, measured on Windows).
  • With a .git file, with or without a daemon GIT_COMMON_DIR, the same swap removes the leaf and the entry in the git directory of that file. The reply is removed the worktree, but left its branch "<branch>" in place: this repository's git config cannot be used: "<baseRepo>\\.git\\config": is, or is reached through, a link that Claude does not follow here; replace the link with what it points to with "branchKept":true. Before that reply 87375cc7 and claustrum make two rev-parse --git-dir calls, with and without the variable (measured on Windows). The second repository stays whole (87375cc7, measured on Windows, with and without the variable). With no such variable and "shadowDirOff":true the reply is success. The branch step runs through the link, and the ref of the same name goes in the second repository (87375cc7, measured on Windows). With the variable and "shadowDirOff":true, claustrum refuses too. With no "shadowDirOff":true, a gone leaf there loses its entry in the git directory of that file and keeps its branch, and the second repository stays whole. These two rules are claustrum's own, not measured.
  • The entry delete goes through the held handle. A request with no hold still deletes by path. That is a link at the git directory at the pin, a daemon GIT_COMMON_DIR that the request keeps and that names another folder, a baseRepo that gives no handle, or a git directory that the pin does not trust or cannot open as the same folder. So is a pin that is not the git directory of the open folder (claustrum's own, not measured). A late swap can then reach another registration (from the code, not measured). A junction that moves twice during the pin can still reach an entry of the second repository (from the code, not measured). Take a live leaf with no hold and a git directory spelled below baseRepo. After the open of <git dir>\worktrees, its entry delete tests whether the baseRepo folder changed since the pin. Any folder that replaced it counts, also through a moved junction in its path. A move keeps both entries (claustrum's own, not measured). A verified entry then gets removed the worktree but could not drop its registration (baseRepo leads to another folder now). An entry that goes by its record stays with no such text. The branch step still takes the ref of the same name in the second repository (from the code, not measured). A move away before that open and back before the test can still reach an entry of the second repository. For a verified entry that includes a locked one (from the code, not measured). A git directory at another path, such as a pin at the real path or a daemon GIT_COMMON_DIR that the request keeps, gets no such test. The read of <repo>\.git\worktrees by path can only refuse. A move inside the branch step still reaches the ref of the same name by path with no gate.
  • An alternates file with Windows line endings, .. after a junction (4c111e86) or too many object directories gets … is locked: <text>, and nothing is deleted, also for a gone worktree folder (measured on Windows). Object sources. A daemon GIT_ALTERNATE_OBJECT_DIRECTORIES, also for a gone folder but not with worktreeRoot: Object sources.
  • An IO_REPARSE_TAG_WIM .git gets … is locked: <text> (4c111e86, measured on Windows). Reparse tags.
  • A baseRepo through a junction to a volume GUID path gets the device link refusal, and nothing is deleted (4c111e86, measured on Windows).
  • A .git file through a link to a UNC path gets … is locked: <text>, and nothing is deleted (87375cc7, measured on Windows). That holds without "shadowDirOff":true, and with it through a junction. The rule.
  • A \\?\UNC\ baseRepo or a refused share gets "success":false. UNC refusals.

Rare states

No git directory is held

On Linux and macOS the remove holds no git directory (from the code). There a swap of .git during a remove leads the delete of the registration into the folder at the path.

Differences from the reference

Catalog entries:

  • D2: the home guard.
  • D22 (Linux and macOS): a lock in the .git folder of baseRepo.

The config refusals, the settings copy and the second listing are measured on 5fd08069, the branch step and the refusal of a root that leads into a checkout on 89cb6289, and most other rules on f6010b97.