Skip to content

fix(opencode): fix file reference feature of VS Code extension#27679

Open
Noitidart wants to merge 1 commit into
anomalyco:devfrom
Noitidart:27678-fix-file-ref-ext
Open

fix(opencode): fix file reference feature of VS Code extension#27679
Noitidart wants to merge 1 commit into
anomalyco:devfrom
Noitidart:27678-fix-file-ref-ext

Conversation

@Noitidart
Copy link
Copy Markdown

@Noitidart Noitidart commented May 15, 2026

Issue for this PR

Closes #10993
Closes #27678

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The VS Code extension gates the Cmd+Option+K file reference hotkey on terminal.name === "opencode". When opencode is launched manually in the integrated terminal (typing opencode), the tab stays named "zsh" so the hotkey does nothing.

VS Code names terminal tabs after the foreground process by reading the actual binary filename from the OS process table. The old bin/opencode was a Node.js wrapper using child_process.spawn(), which created zsh → node → opencode. VS Code sees "node" as the direct child and never recurses into grandchildren.

This PR replaces the Node.js wrapper with a POSIX shell script that execs directly into the compiled binary. On Unix, exec replaces the calling process in-place, so the tree becomes zsh → opencode and VS Code correctly names the tab "opencode".

The platform detection logic (AVX2, musl, architecture) moves to bin/opencode-resolve (Node.js script that outputs the binary path to stdout). A bin/opencode.cmd fallback is added for Windows.

How did you verify your code works?

  • Built with bun run build from packages/opencode
  • Ran the compiled binary directly in VS Code integrated terminal → tab renamed to "opencode"
  • Ran through the shell wrapper with OPENCODE_BIN_PATH env var → tab renamed to "opencode"
  • Typecheck passes (bun turbo typecheck)

Screenshots / recordings

N/A — no UI changes, this is a CLI bin wrapper change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The VS Code extension requires the terminal title to be "opencode" in order
for the Cmd+Option+K file reference hotkey to prefill the prompt.

VS Code names terminal tabs after the foreground process detected via the
OS process table (kern_proc on macOS, /proc on Linux). It reads the actual
binary filename — not process.title, argv[0], or ANSI escape sequences.

The old bin/opencode was a Node.js wrapper that used child_process.spawn()
to launch the compiled binary, keeping the node process alive as a signal
forwarder. This created a three-deep process tree:

  zsh → node (wrapper) → opencode (compiled binary)

VS Code sees "node" as the direct child of zsh and never recurses into
grandchildren, so the terminal tab stays "zsh". The VS Code extension
identifies opencode terminals by checking terminal.name === "opencode",
which means Cmd+Option+K (file reference insertion) silently does nothing.

The fix replaces the Node.js wrapper with a POSIX shell script that exec's
directly into the compiled binary. On Unix, exec replaces the calling
process with the target binary in-place, so the OS process table shows
"opencode" as the direct child of zsh. The platform detection logic
(AVX2, musl, architecture) moves to a separate bin/opencode-resolve Node.js
script that outputs the binary path to stdout. A bin/opencode.cmd fallback
is added for Windows.

Fixes anomalyco#10993
Fixes anomalyco#27678
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

Labels

None yet

Projects

None yet

1 participant