This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a forked repository that periodically merges upstream changes. All development must follow merge-friendly practices.
- MINIMIZE existing code modifications - Avoid changing upstream files whenever possible
- CREATE NEW FILES - Write new functionality in separate files rather than modifying existing ones
- USE EXTENSION PATTERNS - Extend existing functionality through imports, plugins, or composition
- AVOID CORE FILE CHANGES - Never modify core architecture files unless absolutely necessary
# Create new tools
packages/opencode/src/tool/my-custom-tool.ts
packages/opencode/src/tool/my-custom-tool.txt
# Create new CLI commands
packages/opencode/src/cli/cmd/my-command.ts
# Add new utilities
packages/opencode/src/util/my-utility.ts
# Create custom configurations
config/my-custom-config.ts
scripts/my-custom-script.ts// Extend existing registries by importing and adding to arrays
import { MyCustomTool } from "./my-custom-tool.js"
// In registry files, prefer appending to arrays rather than modifying existing entries# These files should rarely be modified to avoid merge conflicts:
packages/opencode/src/tool/registry.ts # Only add new tools to arrays
packages/opencode/src/cli/cmd/cmd.ts # Only add new commands
packages/opencode/src/server/server.ts # Avoid unless critical
packages/opencode/src/agent/agent.ts # Avoid unless critical# ALLOWED: Additive package changes (new dependencies, scripts)
package.json (root) # ✅ Add new dependencies/scripts
packages/*/package.json # ✅ Add new dependencies/scripts
# AVOID: Structural changes that conflict with upstream
bun.lock # ⚠️ Will be regenerated, conflicts expected
sst.config.ts # ⚠️ Avoid unless critical
infra/ # ⚠️ Avoid unless critical
cloud/core/ # ⚠️ Avoid unless critical- Plugin Pattern: Create plugins in
packages/plugin/src/ - Tool Extensions: Add new tools without modifying existing tool registry logic
- Command Extensions: Add new CLI commands in separate files
- Configuration Overlays: Create custom config files that extend base configurations
- Utility Modules: Write reusable utilities in new files under
src/util/
Before merging upstream changes:
- ✅ Most changes are in new files
- ✅ Existing file modifications are minimal and well-documented
- ✅ Package.json changes are additive only (new deps/scripts)
- ✅ Custom functionality is easily separable from upstream code
- ✅ All custom code follows existing patterns and conventions
- ✅ Lock files can be regenerated if conflicts occur
# Start development server (main entry point)
bun dev
# Type checking across all packages
bun run typecheck
# Install dependencies
bun install
# Generate SDK clients (after API changes)
bun run generate
# Run tests
bun test
# Run specific package in development
bun run --filter=opencode dev# Navigate to TUI package
cd packages/tui
# Build Go components
go build ./cmd/opencode
# Run Go tests
go test ./...# Deploy to development stage
bun run sst deploy --stage dev
# Deploy to production
bun run sst deploy --stage productionOpenCode is a client/server AI coding agent with the following key components:
packages/opencode/- Main CLI application and serversrc/cli/cmd/- CLI command definitionssrc/tool/- Development tools (bash, edit, grep, etc.)src/agent/- AI agent engine and context managementsrc/server/- HTTP server and API endpointssrc/session/- Session management and message handling
packages/tui/- Terminal UI components (Go)cloud/- Cloud infrastructure and servicessdks/- Platform-specific SDKs (Go, JavaScript, VS Code)
The tool registry (packages/opencode/src/tool/registry.ts) manages available development tools:
- File Operations: read, write, edit, multiedit, ls, glob, grep
- Execution: bash, task
- Utilities: todo (read/write), webfetch, patch
- Tools are provider-specific (OpenAI, Google, etc.) with parameter sanitization
- Sessions managed in
packages/opencode/src/session/ - AI providers supported: Anthropic, OpenAI, Google, local models
- Context management with conversation memory
- Tool integration with dynamic selection and execution
- Server Layer: Hono-based HTTP server with WebSocket support
- Client Layer: TUI (primary), VS Code extension, future mobile apps
- Cloud Layer: Authentication, billing, user management via SST/Cloudflare
- Create command file in
packages/opencode/src/cli/cmd/ - Use yargs
CommandModuleinterface withcmd()helper - Register in main command router
- Follow existing patterns for error handling and validation
- Implement tool in
packages/opencode/src/tool/ - Define Zod schema for parameters
- Add to
ALLarray inregistry.ts - Include provider-specific parameter transformations
- Add permission checks in
enabled()function
- Themes located in
packages/tui/internal/theme/themes/ - JSON format with color definitions
- Auto-discovered, no manual registration needed
- Support for 25+ existing themes
- Define schema in
cloud/core/src/schema/ - Use Drizzle ORM with SQLite
- Generate migrations:
cd cloud/core && bun run drizzle-kit generate
- Multi-provider: Anthropic (recommended), OpenAI, Google, local models
- Parameter handling: Provider-specific sanitization (see
registry.ts:sanitizeGeminiParameters) - Model restrictions: Some tools disabled for specific models (e.g., Qwen)
- File edit permissions: edit, write, patch tools
- Bash execution permissions: granular command control
- WebFetch permissions: external HTTP access
- Permission checks in
ToolRegistry.enabled()
- Runtime: Bun (primary), Go (TUI), Node.js (compatibility)
- Web Framework: Hono with Zod validation
- Database: Drizzle ORM with SQL
- Infrastructure: SST v3 on Cloudflare Workers
- Authentication: OpenAuth with GitHub Copilot integration
- Monorepo: Bun workspaces with dependency catalog
- TypeScript: Strict settings across packages
- Package Manager: Bun 1.2.19+ required
- Build System: No transpilation, direct TypeScript execution
- Unit tests:
packages/opencode/test/ - Fixtures:
packages/opencode/test/fixtures/ - Go tests:
packages/tui/(standard Go testing)
# All tests
bun test
# Specific test file
bun test packages/opencode/test/tool/tool.test.ts
# With coverage
bun test --coverage- Strict TypeScript settings enforced
- Catalog-based dependency management
- Relative imports within packages, absolute for cross-package
- Prettier: Code formatting (semi: false, printWidth: 120)
- ESLint: Linting (where configured)
- Type checking:
bun run typecheckacross all packages
After making changes to packages/opencode/src/server/server.ts:
- Contact OpenCode team for Stainless SDK generation
- Run
bun run generateto update clients
- Ensure Bun and Go 1.24.x installed
- Run
bun installfrom repository root - Start development with
bun dev - TUI will be available for testing
# Debug with logging
DEBUG=* bun dev
# Component-specific debugging
DEBUG=opencode:agent bun dev
DEBUG=opencode:tools bun dev
# Debug tools
bun dev debug tool --name my-tool --params '{"input": "test"}'
bun dev debug lsp --language typescript
bun dev debug file --path /path/to/fileThis codebase emphasizes terminal-first development, provider-agnostic AI integration, and a plugin-extensible architecture suitable for rapid AI coding agent development.