Skip to content

Conversation

@newlandjia
Copy link

Summary

Add full OpenCode CLI integration using the Agent Client Protocol (ACP), enabling Happy Coder to work with OpenCode as an alternative backend.

Changes

New Files

  • cli/src/opencode/constants.ts - Environment variables and model constants
  • cli/src/opencode/runOpenCode.ts - Main entry point for OpenCode sessions (~730 lines)
  • cli/src/agent/factories/opencode.ts - Backend factory for ACP
  • cli/src/agent/transport/handlers/OpenCodeTransport.ts - Transport handler
  • cli/src/ui/ink/OpenCodeDisplay.tsx - Terminal UI component

Modified Files

  • cli/src/index.ts - Add happy opencode subcommand
  • cli/src/agent/factories/index.ts - Export opencode factory
  • cli/src/agent/transport/handlers/index.ts - Export opencode transport
  • cli/src/agent/transport/index.ts - Export opencode transport
  • cli/src/utils/createSessionMetadata.ts - Add 'opencode' flavor type

Usage

# Start OpenCode mode
happy opencode

# Environment variables
export OPENCODE_API_KEY="your-api-key"   # Or ANTHROPIC_API_KEY
export OPENCODE_MODEL="anthropic/claude-sonnet-4-20250514"  # Optional

Supported Models

  • anthropic/claude-sonnet-4-20250514 (default)
  • anthropic/claude-opus-4-20250514
  • openai/gpt-4o
  • openai/o1
  • google/gemini-2.5-pro

Implementation Details

The implementation follows the same patterns established by the Gemini integration:

  • Uses ACP (Agent Client Protocol) for communication with OpenCode CLI
  • Reuses existing permission handling, reasoning processor, and diff processor
  • Provides dedicated terminal UI with OpenCode branding
  • Supports model switching and permission mode changes during session

Testing

  • Build passes (npm run build)
  • Help shows happy opencode option
  • No hardcoded credentials or privacy issues

Add full OpenCode CLI integration using the Agent Client Protocol (ACP),
enabling Happy Coder to work with OpenCode as an alternative backend.

New files:
- cli/src/opencode/constants.ts - Environment variables and model constants
- cli/src/opencode/runOpenCode.ts - Main entry point for OpenCode sessions
- cli/src/agent/factories/opencode.ts - Backend factory for ACP
- cli/src/agent/transport/handlers/OpenCodeTransport.ts - Transport handler
- cli/src/ui/ink/OpenCodeDisplay.tsx - Terminal UI component

Usage:
  happy opencode          # Start OpenCode mode
  OPENCODE_API_KEY=...    # Or ANTHROPIC_API_KEY
  OPENCODE_MODEL=...      # Optional model override

Supported models:
- anthropic/claude-sonnet-4-20250514 (default)
- anthropic/claude-opus-4-20250514
- openai/gpt-4o
- openai/o1
- google/gemini-2.5-pro
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a11884c075

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +699 to +702
session.sendAgentMessage('opencode', {
type: 'task_complete',
id: randomUUID(),
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reset diff tracking after each turn

The OpenCode loop ends a turn by emitting task_complete, but it never clears the GeminiDiffProcessor state (it is only reset on abort). Because the diff processor caches per-path diffs to suppress duplicates, keeping that cache across turns can suppress legitimate diff updates when a later turn produces the same patch (e.g., retrying or undo/redo), and it can grow unbounded over long sessions. Consider resetting the diff processor at the same point you send task_complete so each turn starts with a clean diff state.

Useful? React with 👍 / 👎.

@GrocerPublishAgent
Copy link
Contributor

Ok, thank you for taking a shot at this and getting it working. I think you and @leeroybrun are doing the same thing with opencode. I don't know enough about the various opencode PRs tonight, but I will tomorrow.

tedin added 2 commits January 27, 2026 21:48
- Increase init timeout from 60s to 120s (OpenCode loads many plugins)
- Filter OpenCode-specific log messages (service=, bun output, plugin loading)
- Prevents JSON-RPC parsing failures from debug output
The cwd is already passed via spawn options, passing it again as an argument
could cause issues with duplicate path handling.
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.

2 participants