Skip to content

Snapshot fails when opencode is opened in a git subdirectory (snapshot service cwd mismatch) #27688

@thforme

Description

@thforme

Description

Bug Description

When opening opencode in a git repository subdirectory (e.g., src/), the snapshot service fails to track files with the error:

WARN service=snapshot exitCode=128 stderr=warning: cannot open directory 'src/src/': No such file or directory
fatal error: pathspec 'src/date.txt' did not match any files
failed to add snapshot files

Root Cause

The issue was introduced in packages/opencode/src/snapshot/index.ts.

In the stage, drop, and ignore functions, cwd is set to state.directory (the directory where opencode was launched), but files paths are relative to state.worktree (git repository root).

When --work-tree points to the repository root but cwd points to a subdirectory, git cannot resolve the paths correctly.

Affected Code

In packages/opencode/src/snapshot/index.ts:

  • ignore function: cwd: state.directory should be cwd: state.worktree
  • drop function: cwd: state.directory should be cwd: state.worktree
  • stage function: cwd: state.directory should be cwd: state.worktree

Expected Behavior

Snapshot should work correctly regardless of which directory within a git repository opencode is launched from.

Plugins

No response

OpenCode version

v1.15.0

Steps to reproduce

  1. Initialize a git repository with some files
  2. Open opencode from a subdirectory (e.g., cd src && opencode)
  3. The snapshot service will fail with the error above

Screenshot and/or share link

No response

Operating System

RHEL 8

Terminal

iTerm2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions