Skip to content

Workspace created from Git subdirectory opens at repository root #26002

Description

@jmeder0s

Description

When creating a new workspace from a project opened inside a subdirectory of a Git repository, the workspace is created successfully, but its associated directory points to the root of the new worktree instead of the equivalent subdirectory inside that worktree.

For example, if opencode is opened at:

/repo/apps/web

and /repo is the Git repository root, creating a new workspace currently targets something like:

~/.local/share/opencode/worktree/<project>/<workspace>

I would expect it to target:

~/.local/share/opencode/worktree/<project>/<workspace>/apps/web

This causes the new workspace to lose the original project context when working in monorepos or repositories with nested projects.

From a quick look at the implementation, opencode already distinguishes the opened directory from the Git worktree root. Project.fromDirectory() discovers both the Git root/worktree and the sandbox/opened directory, but workspace creation appears to only carry the project ID forward. The worktree adapter then uses the new worktree root as the workspace target directory.

Plugins

None

OpenCode version

1.14.39

Steps to reproduce

  1. Create or use a Git repository with a nested project, for example /repo/apps/web.
  2. Open opencode from the nested directory: /repo/apps/web.
  3. Create a new workspace.
  4. Inspect or switch into the new workspace.
  5. Observe that the workspace directory is the new worktree root instead of the corresponding nested directory.

Screenshot and/or share link

N/A

Operating System

macOS

Terminal

OpenCode Desktop

Activity

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