Executing run command in worktree reports 'file already exists' error #3066

Open
opened 2026-02-16 17:38:26 -05:00 by yindo · 2 comments
Owner

Originally created by @negokaz on GitHub (Nov 23, 2025).

Description

When I run the run command, opencode tries to create a .git/opencode directory, but inside a worktree the .git entry is just a regular file.

❯ opencode --print-logs --log-level DEBUG --model vscode-lm-proxy/gpt-5-mini run "test"
INFO  2025-11-23T12:52:07 +367ms service=default version=1.0.105 args=["--print-logs","--log-level","DEBUG","--model","vscode-lm-proxy/gpt-5-mini","run","test"] opencode
INFO  2025-11-23T12:52:07 +2ms service=default directory=C:\Users\negokaz\workspace\opencode.worktree creating instance
INFO  2025-11-23T12:52:07 +0ms service=project directory=C:\Users\negokaz\workspace\opencode.worktree fromDirectory
INFO  2025-11-23T12:52:07 +2ms service=project status=started git.rev-parse
INFO  2025-11-23T12:52:07 +141ms service=project status=completed duration=141 git.rev-parse
ERROR 2025-11-23T12:52:07 +7ms service=acp-command promise={} reason=EEXIST: file already exists, mkdir 'C:\Users\negokaz\workspace\opencode.worktree\.git\opencode' Unhandled rejection
ERROR 2025-11-23T12:52:07 +0ms service=default e=EEXIST: file already exists, mkdir 'C:\Users\negokaz\workspace\opencode.worktree\.git\opencode' rejection
INFO  2025-11-23T12:52:07 +50ms service=default directory=C:\Users\negokaz\workspace\opencode.worktree bootstrapping
INFO  2025-11-23T12:52:07 +6ms service=config path=C:\Users\negokaz\.config\opencode\config.json loading
INFO  2025-11-23T12:52:07 +1ms service=config path=C:\Users\negokaz\.config\opencode\opencode.json loading
INFO  2025-11-23T12:52:07 +0ms service=config path=C:\Users\negokaz\.config\opencode\opencode.jsonc loading
❯ pwd
/c/Users/negokaz/workspace/opencode.worktree
❯ cat .git
gitdir: C:/Users/negokaz/workspace/opencode/.git/worktrees/opencode.worktree

OpenCode version

1.0.105

Steps to reproduce

  1. add worktree directory
  2. run opencode --print-logs --log-level DEBUG --model <model name> run "test" in the worktree directory

Screenshot and/or share link

No response

Operating System

Windows 11

Terminal

Windows Terminal

Originally created by @negokaz on GitHub (Nov 23, 2025). ### Description When I run the run command, opencode tries to create a `.git/opencode` directory, but inside a worktree the `.git` entry is just a regular file. ``` ❯ opencode --print-logs --log-level DEBUG --model vscode-lm-proxy/gpt-5-mini run "test" INFO 2025-11-23T12:52:07 +367ms service=default version=1.0.105 args=["--print-logs","--log-level","DEBUG","--model","vscode-lm-proxy/gpt-5-mini","run","test"] opencode INFO 2025-11-23T12:52:07 +2ms service=default directory=C:\Users\negokaz\workspace\opencode.worktree creating instance INFO 2025-11-23T12:52:07 +0ms service=project directory=C:\Users\negokaz\workspace\opencode.worktree fromDirectory INFO 2025-11-23T12:52:07 +2ms service=project status=started git.rev-parse INFO 2025-11-23T12:52:07 +141ms service=project status=completed duration=141 git.rev-parse ERROR 2025-11-23T12:52:07 +7ms service=acp-command promise={} reason=EEXIST: file already exists, mkdir 'C:\Users\negokaz\workspace\opencode.worktree\.git\opencode' Unhandled rejection ERROR 2025-11-23T12:52:07 +0ms service=default e=EEXIST: file already exists, mkdir 'C:\Users\negokaz\workspace\opencode.worktree\.git\opencode' rejection INFO 2025-11-23T12:52:07 +50ms service=default directory=C:\Users\negokaz\workspace\opencode.worktree bootstrapping INFO 2025-11-23T12:52:07 +6ms service=config path=C:\Users\negokaz\.config\opencode\config.json loading INFO 2025-11-23T12:52:07 +1ms service=config path=C:\Users\negokaz\.config\opencode\opencode.json loading INFO 2025-11-23T12:52:07 +0ms service=config path=C:\Users\negokaz\.config\opencode\opencode.jsonc loading ``` ``` ❯ pwd /c/Users/negokaz/workspace/opencode.worktree ❯ cat .git gitdir: C:/Users/negokaz/workspace/opencode/.git/worktrees/opencode.worktree ``` ### OpenCode version 1.0.105 ### Steps to reproduce 1. add worktree directory 2. run `opencode --print-logs --log-level DEBUG --model <model name> run "test"` in the worktree directory ### Screenshot and/or share link _No response_ ### Operating System Windows 11 ### Terminal Windows Terminal
yindo added the opentuibug labels 2026-02-16 17:38:26 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Nov 23, 2025):

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

  • #2445: git worktrees and root-directory - Similar issue where OpenCode has trouble identifying the correct working directory when using git worktrees, often falling back to the git root directory
  • #802: Stuck in a bad state after deleting the directory it's running from - Related to directory handling issues when working in worktrees

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Nov 23, 2025): This issue might be a duplicate of existing issues. Please check: - #2445: git worktrees and root-directory - Similar issue where OpenCode has trouble identifying the correct working directory when using git worktrees, often falling back to the git root directory - #802: Stuck in a bad state after deleting the directory it's running from - Related to directory handling issues when working in worktrees Feel free to ignore if none of these address your specific case.
Author
Owner

@veracioux commented on GitHub (Nov 23, 2025):

I'm working on a fix.

@veracioux commented on GitHub (Nov 23, 2025): I'm working on a fix.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3066