Skip to content

Support multiple AI coding agent backends (OpenCode, Aider, etc.) #2

@shahar-billiax

Description

@shahar-billiax

Summary

Refactor remote-coder from a Claude Code-specific wrapper into a generic remote AI coding agent platform that supports multiple backend engines. The session management, API auth, workspace isolation, and UI remain the same — only the execution backend is swappable.

Architecture

HTTP API / UI  →  remote-coder (session manager)  →  backend engine
                                                      ├─ claude-code (SDK or CLI) ← current
                                                      ├─ opencode
                                                      ├─ aider
                                                      ├─ codex
                                                      └─ ...

Interface

Each backend engine implements a common CodingAgent interface:

interface CodingAgent {
  send(message: string): Promise<AgentResponse>;
  compact(): Promise<AgentResponse>;  // optional, not all engines support it
  getSessionId(): string | null;
  getWorkingDir(): string;
  getModel(): string;
}

API Changes

Add an engine field when creating a session:

POST /chat
{
  "message": "create a hello.ts file",
  "workspace": "my-project",
  "model": "sonnet",
  "engine": "claude"  // "claude" | "opencode" | "aider" | ...
}

Default engine configurable via DEFAULT_ENGINE env var (defaults to "claude").

Backend: Claude Code (existing)

  • SDK mode: ANTHROPIC_API_KEY set → uses @anthropic-ai/claude-agent-sdk query() (faster, no process spawn)
  • CLI mode: CLAUDE_CODE_OAUTH_TOKEN set → spawns claude CLI
  • Supports ANTHROPIC_BASE_URL for proxy/gateway routing
  • Session resume via --resume flag / SDK resume option
  • Scoped tools: Read, Write, Edit, Glob, Grep, NotebookEdit (no Bash, no internet)

Backend: OpenCode

  • Repo: https://github.com/anomalyco/opencode
  • Open-source, provider-agnostic AI coding agent (supports Claude, OpenAI, Google, local LLMs)
  • 120k+ GitHub stars, 800+ contributors
  • Client/server architecture — could talk to its server API or spawn CLI
  • Has its own session/conversation persistence
  • Built-in LSP support, 75+ LLM providers
  • Install: curl -fsSL https://opencode.ai/install | bash

Integration approach options:

  1. CLI spawn — similar to current Claude CLI path, spawn opencode with prompt, parse output
  2. Server API — OpenCode has a client/server mode, talk to its API directly (lower latency)
  3. Config file — OpenCode uses ~/.config/opencode/opencode.json for provider config

Needs investigation:

  • OpenCode CLI flags for non-interactive/headless mode
  • JSON output format (if any)
  • Session resume mechanism
  • How to scope file access / tools

Backend: Aider (future)

Backend: Codex CLI (future)

Implementation Plan

  1. Extract CodingAgent interface from current ClaudeSession class
  2. Rename ClaudeSessionClaudeCodeAgent implementing CodingAgent
  3. Create OpenCodeAgent implementing CodingAgent
  4. Add engine registry / factory: createAgent(engine, opts) → CodingAgent
  5. Update /chat endpoint to accept engine parameter
  6. Update UI model/engine selector (new session modal)
  7. Store engine type per session
  8. Update Dockerfile to install additional engines
  9. Document env vars per engine

Environment Variables (per engine)

Engine Required Optional
claude ANTHROPIC_API_KEY or CLAUDE_CODE_OAUTH_TOKEN ANTHROPIC_BASE_URL
opencode Provider-specific (e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY) OPENCODE_CONFIG_PATH
aider Provider-specific AIDER_MODEL

Current State

The current codebase already supports:

  • Dual-mode Claude Code (SDK + CLI)
  • Any model name (aliases + full model IDs)
  • Proxy routing via ANTHROPIC_BASE_URL
  • API key auth on all endpoints
  • AKS deployment with CI/CD

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions