|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +OpenCode is an open-source AI-powered coding agent, similar to Claude Code but provider-agnostic. It supports multiple LLM providers (Anthropic, OpenAI, Google, Azure, local models) and features a TUI built with SolidJS, LSP support, and client/server architecture. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Install and run development server |
| 13 | +bun install |
| 14 | +bun dev # Run in packages/opencode directory |
| 15 | +bun dev <directory> # Run against a specific directory |
| 16 | +bun dev . # Run against repo root |
| 17 | + |
| 18 | +# Type checking |
| 19 | +bun run typecheck # Single package |
| 20 | +bun turbo typecheck # All packages |
| 21 | + |
| 22 | +# Testing (per-package, not from root) |
| 23 | +cd packages/opencode && bun test |
| 24 | + |
| 25 | +# Build standalone executable |
| 26 | +./packages/opencode/script/build.ts --single |
| 27 | +# Output: ./packages/opencode/dist/opencode-<platform>/bin/opencode |
| 28 | + |
| 29 | +# Regenerate SDK after API changes |
| 30 | +./script/generate.ts |
| 31 | +# Or for JS SDK specifically: |
| 32 | +./packages/sdk/js/script/build.ts |
| 33 | + |
| 34 | +# Web app development |
| 35 | +bun run --cwd packages/app dev # http://localhost:5173 |
| 36 | + |
| 37 | +# Desktop app (requires Tauri/Rust) |
| 38 | +bun run --cwd packages/desktop tauri dev # Native + web server |
| 39 | +bun run --cwd packages/desktop dev # Web only (port 1420) |
| 40 | +bun run --cwd packages/desktop tauri build # Production build |
| 41 | +``` |
| 42 | + |
| 43 | +## Architecture |
| 44 | + |
| 45 | +**Monorepo Structure** (Bun workspaces + Turbo): |
| 46 | + |
| 47 | +| Package | Purpose | |
| 48 | +|---------|---------| |
| 49 | +| `packages/opencode` | Core CLI, server, business logic | |
| 50 | +| `packages/app` | Shared web UI components (SolidJS + Vite) | |
| 51 | +| `packages/desktop` | Native desktop app (Tauri wrapper) | |
| 52 | +| `packages/ui` | Shared component library (Kobalte + Tailwind) | |
| 53 | +| `packages/console/app` | Console dashboard (Solid Start) | |
| 54 | +| `packages/console/core` | Backend services (Hono + DrizzleORM) | |
| 55 | +| `packages/sdk/js` | JavaScript SDK | |
| 56 | +| `packages/plugin` | Plugin system API | |
| 57 | + |
| 58 | +**Key Directories in `packages/opencode/src`**: |
| 59 | +- `cli/cmd/tui/` - Terminal UI (SolidJS + opentui) |
| 60 | +- `agent/` - Agent logic and state |
| 61 | +- `provider/` - AI provider implementations |
| 62 | +- `server/` - Server mode |
| 63 | +- `mcp/` - Model Context Protocol integration |
| 64 | +- `lsp/` - Language Server Protocol support |
| 65 | + |
| 66 | +**Default branch**: `dev` |
| 67 | + |
| 68 | +## Code Style |
| 69 | + |
| 70 | +- Keep logic in single functions unless reusable |
| 71 | +- Avoid destructuring: use `obj.a` instead of `const { a } = obj` |
| 72 | +- Avoid `try/catch` - prefer `.catch()` |
| 73 | +- Avoid `else` statements |
| 74 | +- Avoid `any` type |
| 75 | +- Avoid `let` - use immutable patterns |
| 76 | +- Prefer single-word variable names when descriptive |
| 77 | +- Use Bun APIs (e.g., `Bun.file()`) when applicable |
| 78 | + |
| 79 | +## Built-in Agents |
| 80 | + |
| 81 | +- **build** - Default agent with full access for development |
| 82 | +- **plan** - Read-only agent for analysis (denies edits, asks before bash) |
| 83 | +- **general** - Subagent for complex tasks, invoked with `@general` |
| 84 | + |
| 85 | +Switch agents with `Tab` key in TUI. |
| 86 | + |
| 87 | +## Debugging |
| 88 | + |
| 89 | +```bash |
| 90 | +# Debug with inspector |
| 91 | +bun run --inspect=ws://localhost:6499/ dev |
| 92 | + |
| 93 | +# Debug server separately |
| 94 | +bun run --inspect=ws://localhost:6499/ ./src/index.ts serve --port 4096 |
| 95 | +opencode attach http://localhost:4096 |
| 96 | + |
| 97 | +# Debug TUI |
| 98 | +bun run --inspect=ws://localhost:6499/ --conditions=browser ./src/index.ts |
| 99 | + |
| 100 | +# Use spawn for breakpoints in server code |
| 101 | +bun dev spawn |
| 102 | +``` |
| 103 | + |
| 104 | +Use `--inspect-wait` or `--inspect-brk` for different breakpoint behaviors. |
| 105 | + |
| 106 | +## PR Guidelines |
| 107 | + |
| 108 | +- All PRs must reference an existing issue (`Fixes #123`) |
| 109 | +- UI/core feature changes require design review with core team |
| 110 | +- PR titles follow conventional commits: `feat:`, `fix:`, `docs:`, `chore:`, `refactor:`, `test:` |
| 111 | +- Optional scope: `feat(app):`, `fix(desktop):` |
| 112 | +- Include screenshots/videos for UI changes |
| 113 | +- Explain verification steps for logic changes |
0 commit comments