OpenCodeHarness: serve OpenCode's HTTP API with harness.fetch · Issue #2567 · cloudflare/agents · GitHub
Skip to content

OpenCodeHarness: serve OpenCode's HTTP API with harness.fetch #2567

Open

Description

@mattzcarey

Add harness.fetch(request) to OpenCodeHarness. It would serve OpenCode's HTTP API from the Durable Object, so the OpenCode CLI can attach to a hosted session:

npx @opencode/cli@2 --server <origin>/agents/open-code-agent/<name> --session <ses_id>
export class OpenCodeAgent extends DurableObject<Env> {
  async fetch(request: Request) {
    return this.harness.fetch(stripAgentPrefix(request));
  }
}

Blocked on upstream

@opencode/sdk builds the embedded server's handler (host.fetch) but doesn't return it from OpenCodeWorkerd.create. Asked for it in anomalyco/opencode#54803.

#2483 got the handler by redefining OpenCode.make in @opencode/client and catching its fetch option with AsyncLocalStorage. We're not taking that: it's a monkey-patch, and it breaks when the SDK and the app resolve different copies of @opencode/client.

When it ships

  • Bump @opencode/sdk and @opencode/plugin.
  • harness.fetch(request) holds a lease and calls (await this.#open()).fetch(request), so it counts as activity for the idle close.
  • In the example, add a route under /agents/open-code-agent/<name> that strips the agent prefix (src/cli.ts in Harness opencode #2483), plus a README section on attaching the CLI.
  • Test: a GET for a session through harness.fetch returns the same session as harness.sessions.list().

Activity

  1. added
    enhancementNew feature or request
    blockedBlocked on external dependency or upstream work
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedBlocked on external dependency or upstream workenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions