Skip to content

feat(opencode): add ACP stdio server for Zed + CLI switch - #2422

Closed
josephschmitt wants to merge 7 commits into
anomalyco:devfrom
josephschmitt:acp
Closed

josephschmitt wants to merge 7 commits into
anomalyco:devfrom
josephschmitt:acp

Conversation

@josephschmitt

@josephschmitt josephschmitt commented Sep 4, 2025 •

Copy link
Copy Markdown
Contributor

Better, more modern implementation available at: #2947

Outdated implementation summary

Summary

  • Adds an ACP-compliant JSON-RPC server over stdio so Zed can use opencode as a headless agent.
  • Reuses existing session and tool pipelines; minimal-first implementation, ready to iterate on streaming.

What Changed

  • New packages/opencode/src/acp/server.ts: stdio JSON-RPC 2.0 server for ACP.
  • CLI: --acp flag and ZED_ACP env switch in packages/opencode/src/index.ts.
  • Tests: packages/opencode/test/acp.test.ts covers initialize → complete → shutdown.
  • Docs: packages/opencode/README.md updated with ACP usage and methods.

ACP Methods

  • initialize, shutdown
  • text/complete (non-streaming for now)
  • tool/list, tool/run
  • files/read, files/write
  • fs/glob
  • session/start, session/stop
  • diagnostics/log

Tooling Surface

  • Exposes a basic set via ToolRegistry: read, write, glob, bash, webfetch.

Usage

  • Run from repo: bun run packages/opencode/src/index.ts --acp
  • Or install and run: set ZED_ACP=1 and invoke opencode
  • Zed settings: add an ACP provider that runs ["opencode", "--acp"] (or the bun dev command).

Testing

  • E2E: bun test packages/opencode/test/acp.test.ts
  • Manual: pipe JSON-RPC lines to bun run packages/opencode/src/index.ts --acp and observe responses.

Notes

  • Headless; respects project cwd provided by Zed.
  • No streaming yet (planned follow-up).
  • No breaking changes to existing HTTP server or CLI.

@seflless

Copy link
Copy Markdown

@josephschmitt Lazy question. Do you know if ADP supports running over http(s)/websockets?

@josephschmitt

josephschmitt commented Sep 12, 2025 •

Copy link
Copy Markdown
Contributor Author

@josephschmitt Lazy question. Do you know if ADP supports running over http(s)/websockets?

The spec says it only communicates via stdio:

Agents run as sub-processes of the code editor, and communicate using JSON-RPC over stdio

I guess in theory you could add a wrapper that used something like curl, and then you converted the http respones into json rpc and output to stdout it would work.

@seflless

Copy link
Copy Markdown

Ah too bad. Thanks for the details!

@jpchauvel

jpchauvel commented Sep 21, 2025 •

Copy link
Copy Markdown

@josephschmitt It has been approved!

@thomasmol

Copy link
Copy Markdown

@jpchauvel i don't think it has been approved by anybody at the opencode team (anybody can approve PRs on this repo). @kmk142789 seems like a crypto bot btw

@igorgue

igorgue commented Sep 22, 2025

Copy link
Copy Markdown

Would love to use this on Neovim with CodeCompanion

@josephschmitt

Copy link
Copy Markdown
Contributor Author

Welp it's been a month and no action. I’m going to try to rebase and see if this implementation is even still relevant. If it breaks too much I might abandon it. Hopefully the core team gets to it eventually

@josephschmitt

Copy link
Copy Markdown
Contributor Author

@thdxr @adamdotdevin this branch is rebased and tests are passing. Typecheck is failing but that seems unrelated to my changes.

Let me know what you want me to do with this PR. If you don't want to accept it that's fine, I'll abandon it and pursue an external wrapper that adds ACP support for OpenCode.

@josephschmitt

Copy link
Copy Markdown
Contributor Author

@thdxr @adamdotdevin I created an alternate implementation that uses Zed’s official TypeScript sdk for ACP, this might be a better PR to merge. LMK what you think: #2947

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.

5 participants