Yeachan-Heo/oh-my-codex · error · Error
worktree_status_failed
worktree_status_failed
Error message
worktree_status_failed:${worktreePath} What it means
Thrown when `git status --porcelain` inside an existing worktree exits non-zero (and stderr is empty), meaning the library could not determine whether the worktree has uncommitted changes. isWorktreeDirty is used before reusing an existing worktree; if status can't run, reuse is unsafe so it throws.
Source
Thrown at src/team/worktree.ts:131
}
function branchExists(repoRoot: string, branchName: string): boolean {
const result = spawnSync('git', ['show-ref', '--verify', '--quiet', `refs/heads/${branchName}`], {
cwd: repoRoot,
encoding: 'utf-8',
});
return result.status === 0;
}
export function isWorktreeDirty(worktreePath: string): boolean {
const result = spawnSync('git', ['status', '--porcelain'], {
cwd: worktreePath,
encoding: 'utf-8',
windowsHide: true,
});
if (result.status !== 0) {
const stderr = (result.stderr || '').trim();
throw new Error(stderr || `worktree_status_failed:${worktreePath}`);
}
return (result.stdout || '').trim() !== '';
}
export function readWorkspaceStatusLines(cwd: string): string[] {
const result = spawnSync('git', ['status', '--porcelain', '--untracked-files=all'], {
cwd,
encoding: 'utf-8',
windowsHide: true,
});
if (result.status !== 0) {
const stderr = (result.stderr || '').trim();
throw new Error(stderr || `workspace_status_failed:${cwd}`);
}
return (result.stdout || '')
.split(/\r?\n/)
.map((line) => line.trimEnd())
.filter(Boolean);View on GitHub (pinned to 3ad79a8a6f)
Solutions
- Run `git worktree prune` from the repo root to clear stale worktree metadata, then retry
- If the worktree directory is corrupted, remove it (`git worktree remove --force <path>` or delete the dir) and let the library recreate it
- Verify the worktree's `.git` file points to an existing gitdir; re-create the worktree if not
- Confirm git is installed and accessible from the process environment
Example fix
# before: stale/corrupt worktree causes worktree_status_failed # after: prune and recreate git worktree prune git worktree remove --force .omx/worktrees/<name> || true # then re-run the team command
Defensive patterns
Strategy: try-catch
Validate before calling
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
function worktreeLooksHealthy(p: string): boolean {
if (!existsSync(p)) return false;
const dot = join(p, '.git');
if (!existsSync(dot)) return false;
if (!dot.endsWith('.git')) return true; // real .git dir
const gitdir = readFileSync(dot, 'utf-8').match(/gitdir: (.+)/)?.[1];
return !!gitdir && existsSync(gitdir);
} Try / catch
try { ensureWorktree(plan, {}); } catch (e) { if (String(e?.message).startsWith('worktree_status_failed:')) { spawnSync('git', ['worktree','prune'], { cwd: plan.repoRoot }); /* optionally remove path and retry once */ } else throw e; } Prevention
- Never rm -rf worktree dirs manually; use `git worktree remove` / `git worktree prune`
- Health-check the worktree's .git file before reuse
- Run `git worktree prune` at the start of team runs
When it happens
Trigger: ensureWorktree finds an existing worktree at the planned path and calls isWorktreeDirty, but `git status` fails: worktree directory deleted out from under git, corrupt index (.git file pointing to a missing gitdir), git missing from PATH, or permission issues.
Common situations: A previously created worktree was `rm -rf`'d manually without `git worktree prune`, leaving stale metadata; concurrent processes pruned the worktree; broken `.git` file in the worktree after moving the repo; git not on PATH in GUI/CI environments.
Related errors
- (result.stderr || '').trim() || `git status failed for ${wor
- (result.stderr || '').trim() || `git ${args.join(' ')} faile
- autoresearch_reset_requires_clean_worktree
- worktree_not_planned:${workerName}
- worktree_not_provisioned:${workerName}
AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27).
Data as JSON: /api/errors/2f4bc7e01c721afc.
Report an issue: GitHub.