generated from ellisonleao/nvim-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 98
Open
Description
Bug
On macOS, pgrep -f "opencode .*--port" fails to find the opencode process (exit code 1, no matches), even though the process is running with exactly those arguments. This appears to be a macOS pgrep quirk with certain binaries (possibly Bun-compiled).
This causes two cascading issues:
- Process discovery always fails —
server.get()never finds a running opencode server lsof -p ""returns ALL listening processes — whenpidsis empty,table.concat({}, ",")produces"", andlsof -p ""interprets that as no PID filter, returning every listening process on the system. The plugin then tries to connect to random services (e.g. any HTTPS server on port 443), producing errors like:opencode Response decode error: Client sent an HTTP request to an HTTPS server.
Reproduction
# Start opencode
opencode --port
# In another terminal
ps -p $(pgrep -a opencode) -o pid,args # shows: opencode --port
pgrep -f "opencode .*--port" # exits 1, no outputSuggested fix
Two changes in lua/opencode/cli/process/unix.lua:
1. Guard against empty PIDs (minimal fix):
if #pids == 0 then
return {}
endThis prevents lsof -p "" from returning all system processes.
2. Replace pgrep -f with lsof -c (robust fix):
lsof -c opencode -iTCP -sTCP:LISTEN -a -Fpn -P -n -wThis finds opencode processes by command name AND listening TCP sockets, bypassing pgrep entirely and working reliably on macOS.
Environment
- opencode CLI: v1.2.18
- opencode.nvim: v0.5.1
- Neovim: latest stable
- OS: macOS (Apple Silicon)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels