npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

opencode-claude-code-plugin

v0.1.2

Published

Claude Code CLI provider plugin for opencode

Readme

opencode-claude-code

A standalone opencode provider plugin that uses Claude Code CLI as a backend. It spawns claude as a subprocess with --output-format stream-json --input-format stream-json, implements the AI SDK LanguageModelV2 interface, and streams responses back to opencode.

This is a standalone npm package that opencode loads dynamically via its external provider system -- no modifications to opencode's source code required.

Prerequisites

Installation

Local development

git clone <this-repo>
cd opencode-claude-code
bun install
bun run build

Then reference it via file:// in your opencode.json.

Configuration

Add this to your project's opencode.json:

{
  "provider": {
    "claude-code": {
      "npm": "opencode-claude-code-plugin@latest",
      "models": {
        "haiku": {
          "name": "Claude Code Haiku",
          "attachment": false,
          "limit": { "context": 200000, "output": 8192 },
          "capabilities": { "reasoning": false, "toolcall": true }
        },
        "sonnet": {
          "name": "Claude Code Sonnet",
          "attachment": false,
          "limit": { "context": 1000000, "output": 16384 },
          "capabilities": { "reasoning": true, "toolcall": true }
        },
        "opus": {
          "name": "Claude Code Opus",
          "attachment": false,
          "limit": { "context": 1000000, "output": 16384 },
          "capabilities": { "reasoning": true, "toolcall": true }
        }
      },
      "options": {
        "cliPath": "claude"
      }
    }
  }
}

Replace "opencode-claude-code-plugin" with a file:// path if you're using a local build.

The model IDs (haiku, sonnet, opus) are passed directly to claude --model, which accepts these aliases natively.

How it works

Architecture

opencode  -->  streamText()  -->  ClaudeCodeLanguageModel.doStream()
                                        |
                                        v
                                  claude CLI subprocess
                                  (stream-json mode)
                                        |
                                        v
                                  ReadableStream<LanguageModelV2StreamPart>
                                        |
                                        v
                                  opencode processor (UI)

Session management

Sessions are managed per working directory + model. One active Claude CLI process is kept alive per (cwd, model) pair and reused across conversation turns. This means:

  • Same session, multiple turns: The CLI process stays alive between messages. Claude retains full native context.
  • New session: When opencode starts a new session (first message with no history), any existing process for that (cwd, model) is killed and a fresh one is spawned.
  • Resumed session after restart: If opencode restarts, the in-memory session state is lost. A new CLI process is spawned, and the conversation history is summarized and prepended as context.
  • Abort (Ctrl+C): The stream closes but the CLI process stays alive for the next message.

Tool handling

Claude CLI executes all tools internally (Read, Write, Edit, Bash, Glob, Grep, etc.). Tool calls and results are streamed to opencode for UI display with providerExecuted: true.

Tool name mapping:

  • Built-in tools: Edit -> edit, Write -> write, Bash -> bash, etc. (lowercased)
  • MCP tools: mcp__server__tool -> server_tool (Claude CLI format to opencode format)
  • Claude CLI internal tools: ToolSearch, Agent, AskFollowupQuestion are silently skipped
  • Questions: AskUserQuestion is rendered as text in the stream

Permissions

The plugin runs with --dangerously-skip-permissions by default. Claude CLI handles all tool execution internally. Users control permissions via Claude Code's own .claude/settings.json allow/deny lists.

Stream sequencing

The plugin ensures proper event ordering for opencode's processor:

  • text-start -> text-delta* -> text-end
  • reasoning-start -> reasoning-delta* -> reasoning-end
  • tool-input-start -> tool-input-delta* -> tool-call -> tool-result

Package structure

src/
  index.ts                        # Factory: createClaudeCode()
  claude-code-language-model.ts   # LanguageModelV2 impl (doGenerate + doStream)
  types.ts                        # Type definitions
  tool-mapping.ts                 # Tool name/input conversion
  message-builder.ts              # AI SDK prompt -> Claude CLI JSON messages
  session-manager.ts              # CLI process lifecycle (spawn, reuse, cleanup)
  logger.ts                       # Debug logging

Development

bun install
bun run build        # Build with tsup
bun run dev          # Build in watch mode
bun run typecheck    # Type check without emitting

Debug logging

Set DEBUG=opencode-claude-code to enable verbose logging to stderr:

DEBUG=opencode-claude-code opencode

Running tests

bun run test.ts

Requires the claude CLI to be installed and authenticated.

Known limitations

  • One session per directory per model: If you run two opencode instances in the same directory with the same model simultaneously, they will share a CLI process and interfere with each other. This is because opencode doesn't expose its session ID to external providers.
  • MCP servers are separate: Claude CLI uses its own MCP servers (configured in ~/.claude/settings.json), not the ones configured in opencode. If you need a specific MCP server (e.g., GitHub), add it to your Claude Code settings.
  • No opencode permission UI integration: Permission prompts go through Claude CLI's own system, not opencode's permission dialog.

Publishing

To publish a new version to npm, bump the version in package.json and push a tag:

git tag v0.1.1
git push origin v0.1.1

The GitHub Actions workflow will automatically build and publish to npm on any v* tag.

License

MIT