Skip to content

Comments

feat: implement project root detection for terminal providers#105

Open
horaoen wants to merge 3 commits intonickjvandyke:mainfrom
horaoen:fix-rootdir-detection
Open

feat: implement project root detection for terminal providers#105
horaoen wants to merge 3 commits intonickjvandyke:mainfrom
horaoen:fix-rootdir-detection

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

图片 图片 图片 图片 图片

@nickjvandyke nickjvandyke force-pushed the main branch 6 times, most recently from de5f1cc to 5de2380 Compare February 2, 2026 16:31
nickjvandyke added a commit that referenced this pull request Feb 23, 2026
…e server option

The plugin's purpose is _interfacing_ with `opencode` - running it is
just a neat convenience. But as the plugin has grown (yay!), that "neat
convenience" has become endless quirks and the majority of maintenance
work. Unfortunately, I'm forced to make the difficult call to remove
providers to make time for more useful work.

I retained the embedded terminal (and instructions to integrate e.g.
`snacks.terminal`) because it's useful to have _some_ way to get
started. But beyond that, it's not practical to service every user's
preferences. And anyway, it's bad UX to ask them to understand a new way
of using/configuring their terminal environment. It may make sense as
its own plugin (and feel free to extract the code for that!), but as far
as `opencode.nvim` goes, it is far, far out of scope.

Thank you for understanding! I look forward to bringing you more cool
features :D

#118
#180
#166
#104
#150
#119
#105
@nickjvandyke nickjvandyke force-pushed the main branch 2 times, most recently from 66f04d7 to a4dff90 Compare February 24, 2026 19:20
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