Skip to content

Opening a second checkout of the same repository redirects to the stored worktree #50821

Closed

Description

@zbh-lzu

Description

The app identifies a project by its git remote, so every local checkout of the same repository maps to one project (by design, see #36219). The project row keeps the worktree of the checkout that was opened first. When a second checkout is opened later, the client resolves it to the same project and navigates to the stored worktree instead of the directory the user picked:

  • projectRoot() in packages/app/src/pages/layout.tsx maps the opened directory to the project's stored worktree
  • navigateToProject() then navigates to that root and restores the most recent session under it
  • rootFor() / projects.open() in packages/app/src/context/layout.tsx collapse the opened directory onto the stored worktree as well

Two visible consequences:

  1. With both checkouts on disk, opening the new one lands in the old one: old path in the URL, old session list, old project name and icon.
  2. After the old checkout is deleted, the stored worktree still points at the missing path, so opening the new checkout keeps targeting it. The persisted project list on the client (opencode.global.dat -> server.projects) also keeps the dead entry in the sidebar.

The server-side stale worktree fallback is handled separately in #47326. This issue is about the client: when the opened directory is itself a registered directory of the project (its worktree or one of its sandboxes), the app should stay on it.

Plugins

None

OpenCode version

1.18.30 (dev)

Steps to reproduce

  1. Clone a repository with a remote to /tmp/repo-a, open it in the app, and create a session there
  2. Copy or re-clone it to /tmp/repo-b (same remote, so both resolve to the same project id)
  3. Open /tmp/repo-b through the project picker
  4. The app navigates to /tmp/repo-a and restores its latest session
  5. Quit, delete /tmp/repo-a, relaunch, and open /tmp/repo-b again
  6. It still resolves to the deleted /tmp/repo-a

Screenshot and/or share link

N/A

Operating System

macOS 15

Terminal

N/A (web app served locally; the same layout code runs in the desktop app)

Activity

  1. github-actions commented on Sep 23, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your report covers a distinct aspect (e.g. the specific client-side navigation path through projectRoot() / navigateToProject() / rootFor(), or the stale dead-path case after deleting the original checkout), it may still warrant its own issue — but please review the above first and add a note here if you believe this is meaningfully different.

  2. Tarquinen commented on Oct 20, 2026

    @Tarquinen
    Member

    Thanks for the report! In OpenCode 2.0 the app keeps the folder you picked instead of redirecting to another checkout of the same repository. If you still see this on the latest OpenCode, please open a new issue with details. Closing as completed.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions