coleam00/Archon · error
Cannot verify worktree ownership at ${worktreePath}: ${(erro
Error message
Cannot verify worktree ownership at ${worktreePath}: ${(error as Error).message} What it means
verifyWorktreeOwnership proves a directory at worktreePath is a linked worktree belonging to expectedRepo by comparing Git checkout identities of both. If either `git` identity query fails (not a git dir, corrupt .git pointer, git binary error), it throws wrapping the underlying message with `cause` preserved. Adoption is refused because ownership cannot be proven.
Source
Thrown at packages/git/src/worktree.ts:469
// a TOCTOU race or filesystem corruption. Fail fast.
// EACCES/EIO/etc.: cannot verify ownership — fail fast rather than
// defaulting to permissive adoption.
throw wrap(`Cannot verify worktree ownership at ${worktreePath}: ${err.message}`);
}
if (!gitContent.startsWith('gitdir:')) {
throw new Error(`Cannot adopt ${worktreePath}: .git pointer is not a git-worktree reference.`);
}
let worktreeIdentity: GitCheckoutIdentity;
let expectedIdentity: GitCheckoutIdentity;
try {
[worktreeIdentity, expectedIdentity] = await Promise.all([
getGitCheckoutIdentity(worktreePath),
getGitCheckoutIdentity(expectedRepo),
]);
} catch (error) {
throw new Error(
`Cannot verify worktree ownership at ${worktreePath}: ${(error as Error).message}`,
{
cause: error,
}
);
}
if (!worktreeIdentity.linkedWorktree) {
// Not a git-worktree pointer (e.g., submodule pointer, or malformed).
// We cannot confirm this is our worktree, so refuse adoption.
throw new Error(`Cannot adopt ${worktreePath}: .git pointer is not a git-worktree reference.`);
}
// Compare resolved common-directory paths: the primary checkout and every
// linked worktree share this Git identity, while separate clones differ.
if (resolve(worktreeIdentity.commonGitDir) !== resolve(expectedIdentity.commonGitDir)) {
throw new Error(
`Worktree at ${worktreePath} belongs to a different clone (${worktreeIdentity.commonGitDir}). ` +
'Remove it from that clone or use a different codebase registration.'View on GitHub (pinned to 0773b97458)
Solutions
- Run `git worktree list` in the expected repo and `git rev-parse --git-common-dir` in worktreePath to see which side failed.
- Recreate the worktree with `git worktree add <path> <branch>` if it is corrupted or was never a real worktree.
- Fix the expectedRepo registration/path so it points at an existing git clone.
- Remove the orphaned directory and let isolation provisioning create a fresh worktree.
Example fix
// before: adopting a directory that is not a worktree
await assertWorktreeOwnership('/srv/app', '/srv/clone');
// after: recreate it as a linked worktree of the expected repo
cd /srv/clone && git worktree add /srv/app feat-branch
await assertWorktreeOwnership('/srv/app', '/srv/clone'); Defensive patterns
Strategy: try-catch
Validate before calling
import { existsSync } from 'node:fs';
if (!existsSync(expectedRepo) || !existsSync(`${expectedRepo}/.git`)) {
throw new Error(`expected repo ${expectedRepo} is not an existing git checkout`);
}
if (!existsSync(`${worktreePath}/.git`)) {
throw new Error(`${worktreePath} has no .git entry; not a worktree candidate`);
} Type guard
function looksLikeWorktree(p: string): boolean {
try { return readFileSync(`${p}/.git`, 'utf8').startsWith('gitdir:'); } catch { return false; }
} Try / catch
try {
await assertWorktreeOwnership(worktreePath, expectedRepo);
} catch (e) {
if (e.message.startsWith('Cannot verify worktree ownership')) {
console.error('Recreate the worktree:', e.cause);
} else throw e;
} Prevention
- Create directories only via `git worktree add`, never by hand-copying.
- Verify `git worktree list` shows the path before attempting adoption.
- Keep the parent clone present and readable; don't delete it while worktrees exist.
When it happens
Trigger: Calling assertWorktreeOwnership or findExisting against a path where getGitCheckoutIdentity fails — the path is not a git worktree/checkout, the .git file is malformed, the expected repo path is missing or not a git repo, or git itself errors (permissions, broken install).
Common situations: Reusing a directory that was never a worktree (plain folder with a leftover .git file); the expected repo was moved/deleted so its identity can't be read; a partially-deleted or corrupted worktree; running as a user without read access to the git metadata.
Related errors
- Cannot adopt ${worktreePath}: .git pointer is not a git-work
- Worktree at ${worktreePath} belongs to a different clone (${
- Worktree at ${worktreePath} was reported removed but is stil
- Cannot adopt worktree at '${worktreePath}': expected branch
- Cannot determine git remote for ${repoPath}: no git remote i
AI-assisted analysis of coleam00/Archon@0773b97458 (2026-09-01).
Data as JSON: /api/errors/af40d459d43ea943.
Report an issue: GitHub.