Skip to content

Conversation

@horaoen
Copy link

@horaoen horaoen commented Dec 26, 2025

fix bug #104

Summary

Fix opencode working directory mismatch when Neovim's actual project directory differs from where nvim was launched.

Problem

When using nvim or navigating to a project via a dashboard plugin, opencode would start in the wrong directory because all providers were inheriting the shell's working directory rather than detecting the actual project root.

Scenarios affected:

  • nvim ~/projects/my-app from ~/ → opencode opened in ~/ instead of ~/projects/my-app
  • Using dashboard plugins (alpha-nvim, dashboard-nvim) to open projects
  • Changing directories with :cd after Neovim starts

Solution

Added get_project_root() function with smart detection priority:

  1. Neovim directory argument (nvim )
  2. Git root (for git repositories)
  3. Current buffer directory (fallback for non-git projects)
  4. LSP workspace root (if available)
  5. vim.fn.getcwd() (final fallback)

All 5 providers now use this function:

  • terminal.lua - Added cwd option to jobstart()
  • snacks.lua - Pass cwd to snacks.terminal options
  • tmux.lua - Added -c flag to split-window
  • wezterm.lua - Added --cwd flag to split-pane
  • kitty.lua - Changed from --cwd=current to explicit path

@horaoen horaoen force-pushed the fix-rootdir-detection branch from 29e90c3 to 2df3b0f Compare December 26, 2025 06:57
@horaoen
Copy link
Author

horaoen commented Dec 26, 2025

I have tested it in my environment, and scenarios 1, 2, and 3 all work so far. The implementation for scenario 3 is to close the existing OpenCode workspace and create a new one.

Scene 3

图片 图片 图片 then toggle again 图片

scene 1、2

图片 图片 图片 图片 图片

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant