Skip to content

bug: opencode working directory doesn't sync with Neovim's actual CWD #104

@horaoen

Description

@horaoen

Did you check docs and existing issues?

  • I have read all the plugin docs
  • I have searched the existing issues
  • I have searched the existing opencode issues

Operating system/version

Macos

:checkhealth opencode output

opencode.nvim ~ - ✅ OK nvim version: 0.11.5. - ✅ OK opencode.nvim git commit hash: dfca5bb214d78a600781d50da350238b3e6e2621. - ✅ OK vim.g.opencode_opts: {} opencode.nvim [binaries] ~ - ✅ OK opencode available with version 1.0.202. - ✅ OK curl available. - ✅ OK pgrep available: it will be used to auto-find opencode if vim.g.opencode_opts.port is not set. - ✅ OK lsof available: it will be used to auto-find opencode if vim.g.opencode_opts.port is not set. opencode.nvim [snacks] ~ - ✅ OK snacks.input is enabled: ask() will be enhanced. - ✅ OK blink.cmp is available: opts.ask.blink_cmp_sources will be registered in ask(). - ✅ OK snacks.picker is enabled: select() will be enhanced. opencode.nvim [providers] ~ - ✅ OK Configured opencode provider: snacks. - ✅ OK The snacks provider is available. - ⚠️ WARNING The kitty provider is not available — KITTY_LISTEN_ON environment variable is not set. - ADVICE: - Enable remote control in kitty. - ⚠️ WARNING The wezterm provider is not available — wezterm executable not found in $PATH. - ADVICE: - Install wezterm and ensure it's in your $PATH. - ⚠️ WARNING The tmux provider is not available — Not running inside a tmux session. - ADVICE: - Launch Neovim inside a tmux session. - ✅ OK The terminal provider is available.

Describe the bug

When opencode is launched, it uses the working directory from the moment Neovim starts (where the nvim command was executed), rather than tracking Neovim's actual current working directory. This causes a mismatch when:

  1. Using nvim <folder> to open a different directory
  2. Navigating to a project via a dashboard plugin (like alpha-nvim, dashboard-nvim, etc.)
  3. Changing directories within Neovim using :cd, :tcd, or :lcd

Steps To Reproduce

Steps to Reproduce

Scenario 1: Using dashboard

  1. Run nvim from ~/ (home directory)
  2. Use a dashboard plugin to open a project at ~/projects/my-app
  3. Trigger opencode (e.g., :lua require("opencode").toggle())
  4. Expected: opencode opens in ~/projects/my-app
  5. Actual: opencode opens in ~/

Scenario 2: Using nvim <folder>

  1. From ~/, run nvim ~/projects/my-app
  2. Trigger opencode
  3. Expected: opencode opens in ~/projects/my-app
  4. Actual: opencode may open in ~/ (depends on timing)

Scenario 3: Changing directory after opencode starts

  1. Start Neovim in ~/project-a
  2. Trigger opencode (it correctly opens in ~/project-a)
  3. Use :cd ~/project-b to change Neovim's working directory
  4. Try to interact with opencode
  5. Expected: opencode should work in ~/project-b or at least detect the mismatch
  6. Actual: opencode continues working in ~/project-a

Expected Behavior

expected as 'Reproduce' expected

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions