GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #60768

New issue
Copy link
New issue
Copy link
Open
Open
worktree_list: silent empty outside a repo, and its registry disagrees with git in both directions#60768
Copy link
Labels
reproduced

Description

@scotthawes
scotthawes
opened on Oct 31, 2026
Issue body actions

Summary

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

  1. Open a session whose working directory is not a repository: /Users/Scott.
  2. 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).
  3. From the session, call tools.opencode.worktree_list() → {"worktrees": []}.
  4. 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).

Activity

  1. opencodejr commented on Oct 31, 2026

    @opencodejr
    opencodejrBot
    on Oct 31, 2026
    Contributor
    More actions

    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:

    1. worktree_create({ name: "managed" }). worktree_list now shows managed plus the main checkout.
    2. 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.
    3. 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:

    • Can't delete a workspace whose folder was removed outside OpenCode (DELETE /api/worktree → 400) #57987: a worktree deleted outside OpenCode stays saved and can't be removed (PR fix(core): remove missing Git worktrees from inventory #58038)
    • server: silent service restarts within seconds of git worktree add — tool responses lost, worktree registry stale #58991: worktrees added with git worktree add don't show up in worktree_list
    • Worktree actions are offered without a repository, and reach an ancestor repository #55776: worktree actions run without a repository, or against a parent repository
    recording.mp4

    Screenshot

    Screenshot

    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.

  2. opencodejr
    added
    reproduced
    on Oct 31, 2026
  3. yangguan-xue commented on Nov 1, 2026

    @yangguan-xue
    yangguan-xue
    on Nov 1, 2026
    Contributor
    More actions

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    reproduced

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.