This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
OpenCode is an open-source AI coding agent (TUI + web + desktop). It's a Bun-based TypeScript monorepo using workspaces and Turborepo.
# Install dependencies
bun install
# Run dev (TUI mode, against packages/opencode dir by default)
bun dev
bun dev <directory> # run against a different directory
bun dev . # run against repo root
# Headless API server
bun dev serve # port 4096 by default
bun dev serve --port 8080
# Web UI dev (requires server running separately)
bun run --cwd packages/app dev
# Desktop app (requires Tauri/Rust)
bun run --cwd packages/desktop tauri dev
# Typecheck
bun turbo typecheck
# Tests — MUST run from packages/opencode, NOT repo root
cd packages/opencode && bun test --timeout 30000
cd packages/opencode && bun test --timeout 30000 test/tool/bash.test.ts # single test
# Build standalone executable
./packages/opencode/script/build.ts --single
# Regenerate SDK after API/server changes
./script/generate.tspackages/opencode/— Core business logic, CLI, server, and AI agent loopsrc/provider/— AI provider integrations (Anthropic, OpenAI, Bedrock, Vertex, Databricks, etc.) via Vercel AI SDKsrc/session/— Session management, LLM orchestration (llm.ts), message handling, compaction, system promptssrc/tool/— Built-in tools (bash, read, edit, write, grep, glob, webfetch, etc.) with.txtprompt filessrc/server/— Hono-based HTTP API server with SSE eventssrc/cli/— CLI entry point and TUI (SolidJS with opentui)src/config/— Configuration parsing and pathssrc/agent/— Agent definitions and orchestrationsrc/mcp/— MCP (Model Context Protocol) clientsrc/plugin/— Plugin systemtest/— Tests (bun test), organized mirroringsrc/
packages/app/— Shared web UI components (SolidJS)packages/desktop/— Native desktop app (Tauri wrappingpackages/app)packages/sdk/— Generated JS SDK for the APIpackages/plugin/—@opencode-ai/pluginpackagepackages/web/— Landing page / websitepackages/ui/— Shared UI primitives
The core loop: session/ manages conversations, llm.ts calls AI providers via the Vercel AI SDK (ai package), tool calls are routed through tool/registry.ts, and results stream back via server/ (Hono + SSE). Provider configuration comes from provider/provider.ts which pulls model definitions from models.dev. The TUI is SolidJS rendered to terminal via opentui. Configuration is in opencode.json at project root.
The default branch is dev, not main. Use dev or origin/dev for diffs and PR base.
- No semicolons (prettier:
semi: false,printWidth: 120) - Prefer
const, ternaries, early returns overlet/else - Avoid
try/catch, unnecessary destructuring, andany - Use Bun APIs (
Bun.file(), etc.) when possible - Prefer single-word variable/function names; inline values used only once
- Drizzle schemas: use snake_case field names (no string column name args)
- Functional array methods (flatMap, filter, map) over for loops
- Rely on type inference; avoid explicit type annotations unless needed for exports
- Use
@/path alias for imports withinpackages/opencode/src/
- Tests use
bun test— run frompackages/opencode/, never from repo root - Avoid mocks; test actual implementations
- Test files live in
packages/opencode/test/mirroringsrc/structure
New providers generally don't require code changes — add them to models.dev. The provider system in provider/provider.ts dynamically creates AI SDK instances based on provider type. Provider-specific transforms live in provider/transform.ts.