GeezerVison is showing github.com — worktree_list: silent empty outside a repo, and its registry disagrees with git in both directions · Issue #60768 · anomalyco/opencode
worktree_list: silent empty outside a repo, and its registry disagrees with git in both directions #60768DescriptionSummary
worktree_list returns {"worktrees": []} from a session whose working directory is not a git repository, with no error and no argument for naming a repository — indistinguishable from "nothing is in flight". Its backing registry also disagrees with git worktree list in both directions: live git-created worktrees are absent, and a worktree deleted from disk is still recorded.
Environment
- opencode version: v2.0.28
- OS: Darwin 25.5.0 (darwin arm64, MacBook-Air-2.local)
- Terminal: TERM_PROGRAM=herdr, TERM=xterm-256color, COLORTERM=truecolor
- Shell: /bin/zsh
- Install/channel: latest (per built-in report snapshot;
opencode --version reports v2.0.28)
- Active plugins: none found in
~/.config/opencode/opencode.json (the only "plugin" hit is a parked MCP entry note, not a plugin)
Reproduction
- Open a session whose working directory is not a repository:
/Users/Scott.
- In a shell, list worktrees for a repo you know about:
git -C /Users/Scott/fm4sd worktree list → 5 entries (main plus four linked worktrees, one of them created minutes earlier by a parallel session).
- From the session, call
tools.opencode.worktree_list() → {"worktrees": []}.
- Inspect the registry that appears to back the tool:
sqlite3 ~/.local/share/opencode/opencode.db "select directory, strategy from worktree where project_id='1b997e5542a973dcf0878072bec3fc0abdb972d2'"
→ /Users/Scott/fm4sd and /Users/Scott/fm4sd-wt/gap-baselines.
/Users/Scott/fm4sd-wt/gap-baselines no longer exists on disk, and the four live worktrees created with git worktree add are not in the table.
Expected Behavior
worktree_list names a repository's worktrees as its description says. From outside a repository it either accepts a directory argument or fails loudly ("not in a git repository") instead of returning an empty list. The list reflects git worktree list for that repository, so a worktree created by git worktree add appears and a deleted one does not.
Actual Behavior
From a non-repository session the call returns an empty array with no signal, which reads as a confident "no worktrees". Even for the known project, the recorded set is stale in both directions.
Additional Context
Impact. This is a resume/observability call: "is anyone else working in this repo right now?" The empty answer caused an agent to conclude nothing was in flight, and then a worktree it had just read (~/fm4sd-wt/gap-baselines) was deleted by a parallel session mid-read, while two new worktrees appeared. The failure was only found by falling back to git worktree list.
Workaround. git worktree list --porcelain, or a script over it; resume.sh in ~/.config/opencode/scripts/ now does this and prints each worktree's last-commit age.
Possible fixes.
- Take an optional
directory (or repo) argument so a caller can name the repository it knows about.
- Back the result with
git worktree list for the resolved project rather than the worktree table, or reconcile the table against disk on read.
- Return an explicit error when the session location has no repository, so "empty" and "unknown" are distinguishable.
Frequency. Consistent from any non-repository session; the registry/disk divergence is reproducible on this machine (fm4sd). Activityopencodejr commented on Oct 31, 2026 Thanks for the detailed report. I reproduced the stale list on 2.0.28, and it still happens on the latest dev (30a97bc).
Steps, in a session inside a git repo:
worktree_create({ name: "managed" }). worktree_list now shows managed plus the main checkout.
- Using plain git, delete the
managed folder, run git worktree prune, and add a new worktree with git worktree add ../gitmade -b gitmade. git worktree list now shows only main and gitmade.
worktree_list still returns the deleted managed worktree and leaves out gitmade.
The tool reads OpenCode's saved list of worktrees and doesn't check it against git or the disk first. The recording and screenshots below show this, and the script below reproduces it.
I didn't treat the empty result from a session outside a repository as part of this bug. That session's project has no worktrees, so the empty list is how it currently works. An optional directory argument, or an explicit error in that case, would be a feature request. Your git worktree list --porcelain script remains the reliable check for now.
Closely related, most relevant first:
recording.mp4


Reproduction script (drive.ts)
// Repro for anomalyco/opencode#60768: worktree_list returns OpenCode's stored registry, not git's worktrees.
// Run: OPENCODE_DRIVE_MEDIA_DIR=/workspace/media opencode-drive run drive.ts (OC_DEV=<checkout> to run from source)
import { Effect, Stream } from "effect"
import { Llm, OpenCodeDriver } from "opencode-drive"
const call = (id: string, name: string, input: any) => [Llm.toolCall({ index: 0, id, name, input }), Llm.finish("tool-calls")]
// Throwing makes the TUI print the JSON result on screen.
const LIST = `const r = await tools.opencode.worktree_list(); throw new Error("worktree_list => " + JSON.stringify(r))`
// Scripted main-agent responses, in order (title requests are answered separately).
const responses: any[][] = [
call("c1", "execute", { code: `return await tools.opencode.worktree_create({ name: "managed" })` }), [Llm.text("CREATED")],
call("l1", "execute", { code: LIST }), [Llm.text("LISTED-1")],
call("s1", "shell", {
description: "delete the managed worktree and add one with git",
command: `M=$(git worktree list --porcelain | awk '/^worktree /{print $2}' | grep managed); rm -rf "$M"; git worktree prune; git worktree add ../gitmade -b gitmade >/dev/null 2>&1; git worktree list`,
}), [Llm.text("GIT-CHANGED")],
call("l2", "execute", { code: LIST }), [Llm.text("LISTED-2")],
]
export default OpenCodeDriver.use(
{
...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
project: { git: true, files: { "README.md": "hi\n" } },
tui: { recording: true },
},
({ ui, llm }) =>
Effect.gen(function* () {
let next = 0
yield* llm.serve((req: any) => {
const system = JSON.stringify(req?.body ?? "")
if (system.includes("You name conversations")) return Stream.make(Llm.text("Worktree repro"))
return Stream.make(...(responses[next++] ?? [Llm.text("END")]))
})
const step = (prompt: string, marker: string) =>
Effect.gen(function* () {
yield* ui.submit(prompt)
yield* ui.waitFor(marker, { timeout: 90000 })
yield* Effect.sleep(2000)
})
// 1. Create a worktree through OpenCode (it gets registered) and list.
yield* step("create worktree", "CREATED")
yield* step("list", "LISTED-1")
yield* ui.screenshot("1-list-after-create")
// 2. With plain git: delete the managed worktree, add a new one.
yield* step("change with git", "GIT-CHANGED")
// 3. List again: the deleted worktree is still reported, the git-made one is missing.
yield* step("list again", "LISTED-2")
yield* ui.screenshot("2-list-stale")
}),
)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
yangguan-xue commented on Nov 1, 2026 I have a working fix with regression tests ready on yangguan-xue/opencode-1@ece128c38 (fix/worktree-list-reconcile branch):
- Reconciles
worktree_list by invoking ctx.worktree.refresh({ projectID }) before listing, discovering external git worktrees and pruning missing ones.
- Adds optional
directory parameter using FileAccess.resolvePath (supports ~ and session-relative paths) and fails loudly with ToolFailure when outside a git repository.
- Asserts
external_directory permission before project resolution and worktree refresh when querying external directories.
I am currently at the 3-open-PR limit (#60791, #60807, #60838). I will open the PR as soon as one of them gets merged/closed, or feel free to cherry-pick if you need it sooner.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|