Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 17, 2025

This PR adds support for Opencode, an open-source alternative to Claude Code, as a new backend for ai-code-interface.el.

What is Opencode?

Opencode is an open-source AI coding assistant that provides:

  • HTTP server APIs for programmatic control
  • Customization features (LSP integration, custom LLM providers, custom tools)
  • Context command features similar to other AI coding tools

Changes

This PR follows the same pattern established by the GitHub Copilot CLI and Codex CLI integrations:

  1. New file: ai-code-opencode.el

    • Thin wrapper that reuses claude-code infrastructure to run Opencode
    • Implements required backend functions: opencode, opencode-switch-to-buffer, opencode-send-command, and opencode-resume
    • Includes customization variable opencode-program for configuring the executable path
  2. Updated: ai-code-backends.el

    • Registered opencode in the ai-code-backends configuration list
    • Config file location: ~/.opencode/config.json
  3. Updated: ai-code-interface.el

    • Added (require 'ai-code-opencode) to load the new module
  4. Updated: README.org

    • Added Opencode to the list of supported AI coding CLIs
    • Added documentation for the new backend option

Context Features

The issue mentioned context command features like @cursor, @buffer, @selection, and @visible from opencode.nvim. These capabilities are already built into ai-code-interface.el and work automatically with the opencode backend:

  • @buffer - Current buffer context
  • @buffers - All buffers in current window
  • Visible region with line numbers
  • Selected code regions
  • Current function context

Usage

After installing the Opencode CLI:

  1. Select opencode as backend: M-x ai-code-select-backend → select "ai-code-opencode.el"
  2. Start opencode: M-x opencode or via C-c a menu
  3. All existing ai-code-interface features now work with opencode!

Testing

  • ✓ Syntax validation passed for all files
  • ✓ Follows the established backend pattern (github-copilot-cli/codex-cli)
  • ✓ All functions properly defined with autoload cookies
  • ✓ Backend properly registered in the selection system

Fixes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature Request] Add opencode support</issue_title>
<issue_description>I would like to suggest opencode, which is an Open Source alternative to Claude Code.

It provides plenty of customization features(like LSP, custom LLM providers, custom tools) and we can use HTTP server APIs to control opencode.

For emacs interface, I see there is context command feature in neovim plugin NickvanDyke/opencode.nvim which is quite handy for my daily usage.
For example, @cursor in the prompt will be replaced by the file cursor position and then sent to Coding Agent.
Users can also script their own commands to inject specific context into prompt.

Image</issue_description>

Comments on the Issue (you are @copilot in this section)

@tninja Thanks for trying this library. I haven't try opencode yet. But seems it is under active development. [This PR ](https://github.com//pull/2/files) add the github-copilot-cli (require claude-code.el). Maybe adding opencode support is similar to this. Thanks for sharing HTTP server APIs, it could improve integration between emacs to the AI coding tool.

I like idea about providing more context. This tool currently have part of it automatically turned on. Eg. @buffer, @Buffers (all buffers in current window). Visible text might be a good to have. I feel Claude Code and other similar tools understand line numbers, maybe AI can understand things like: the visible region: line x to line y</comment_new>

Fixes #9


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: tninja <714625+tninja@users.noreply.github.com>
Copilot AI changed the title [WIP] Add opencode support for customization features Add Opencode support as a new backend Oct 17, 2025
Copilot AI requested a review from tninja October 17, 2025 00:49
Copilot finished work on behalf of tninja October 17, 2025 00:49
@tninja
Copy link
Owner

tninja commented Oct 31, 2025

@gkzhb do you mind check if this change work for you? You can try it in this branch: copilot/add-opencode-support

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.

[Feature Request] Add opencode support

2 participants