Contributing to OpenCode
Relevant source files
The following files were used as context for generating this wiki page:
Contributing to OpenCode is encouraged, with a focus on making the process as easy as possible. This guide provides a comprehensive overview of the development process, contribution workflows, style guidelines, and pull request expectations to help you get your changes merged. The project welcomes a variety of contributions, from simple bug fixes and documentation improvements to more complex additions like new providers or performance enhancements.
However, it's important to note that any changes to the UI or core product features require a design review with the core team before implementation begins. This ensures that all contributions align with the project's vision and maintain a high standard of quality. For new functionality, it is required to start with a design conversation by opening an issue.
Sources: CONTRIBUTING.md:3-12, CONTRIBUTING.md:100-103
Getting Started
Development Environment
To start developing OpenCode, you'll need to set up your local environment. The primary requirement is Bun 1.3+.
- Install Dependencies: From the root of the repository, run the following command to install all necessary dependencies.
bun install - Start the Dev Server: Once dependencies are installed, start the development server.
bun dev
Sources: CONTRIBUTING.md:20-25
Project Structure
The OpenCode repository is organized into several core packages. Understanding their purpose is key to effective contribution.
| Package | Description |
|---|---|
packages/opencode | Contains the core business logic and server for OpenCode. |
packages/opencode/src/cli/cmd/tui/ | The Terminal User Interface (TUI) code, built with SolidJS and opentui. |
packages/plugin | The source for the @opencode-ai/plugin. |
packages/sdk/js | The JavaScript SDK. Note that after touching packages/opencode/src/server/server.ts, you must run ./packages/sdk/js/script/build.ts to regenerate this SDK. |
packages/sdk/go | The Go SDK. See the dedicated section for contribution details. |
Sources: CONTRIBUTING.md:28-33, CONTRIBUTING.md:36-37, packages/sdk/go/CONTRIBUTING.md
Contribution Workflow
The general workflow for contributing involves finding an issue, implementing a fix, and submitting a pull request.
Finding an Issue
If you are unsure where to start, the project maintains several labels on GitHub issues to guide new and existing contributors.
Before starting work, leave a comment on the issue. A maintainer may assign it to you if it's not already being worked on.
Sources: CONTRIBUTING.md:14-18, CONTRIBUTING.md:20-22
Contribution Process Flow
The following diagram illustrates the standard process for code contributions.
This diagram shows the path from finding a suitable issue to getting your pull request merged.
Sources: CONTRIBUTING.md:14-22, CONTRIBUTING.md:78-84
Feature Requests
For entirely new features, the process is different and requires upfront collaboration.
This diagram shows the required process for proposing new features, which must be approved before implementation.
Sources: CONTRIBUTING.md:100-103
Pull Request Expectations
To ensure a smooth review process, all pull requests should adhere to the following expectations:
- Small and Focused: Keep PRs limited to a single issue or feature.
- Link Issues: Reference the relevant issue(s) in the PR description.
- Clear Explanation: Explain the problem and how your change resolves it.
- Concise Descriptions: Avoid verbose, LLM-generated PR descriptions.
- Check for Existing Code: Before adding new functions, ensure the functionality doesn't already exist elsewhere.
Sources: CONTRIBUTING.md:78-84
Code Review Process
Code reviews are a critical part of the contribution process. The agent-based review system focuses on several key areas.
The review process can be triggered for uncommitted changes, a specific commit, a branch comparison, or a pull request.
This diagram shows how the code review agent processes a pull request diff to provide feedback.
Sources: packages/opencode/src/command/template/review.txt:9-21, packages/opencode/src/command/template/review.txt:27-36
Style and Conventions
The project has a set of style preferences and conventions that contributors should follow.
General Style Preferences
| Guideline | Description |
|---|---|
| Functions | Keep logic within a single function unless breaking it out offers clear reuse. |
| Destructuring | Avoid unnecessary destructuring of variables. |
| Control Flow | Avoid else statements where possible. |
| Error Handling | Prefer .catch(...) over try/catch blocks. |
| Types | Use precise types and avoid any. |
| Variables | Favor immutable patterns and avoid let. |
| Naming | Use concise, single-word identifiers when descriptive. |
| Runtime APIs | Use Bun helpers like Bun.file() when appropriate. |
Sources: CONTRIBUTING.md:88-97
AGENTS.md Specification
A key convention in the repository is the use of AGENTS.md files. These files provide instructions and context to the AI coding agents that operate within the codebase.
- Purpose: To give agents instructions on coding conventions, code organization, or how to run/test code.
- Scope: An
AGENTS.mdfile's scope is the directory it's in and all subdirectories. - Precedence: More deeply nested
AGENTS.mdfiles take precedence over those in parent directories. - Creation: You can ask an agent to create or improve an
AGENTS.mdfile. The agent will analyze the codebase for build/lint/test commands and style guidelines.
Sources: packages/opencode/src/session/prompt/codex.txt:21-32, packages/opencode/src/command/template/initialize.txt:1-6
Debugging
Debugging Bun applications can be challenging. The recommended and most reliable method is to run OpenCode manually in a terminal and attach a debugger.
bun run --inspect=<url> dev ...
Caveats:
- Breakpoints in
*.tsxfiles may not be mapped correctly due to Bun's current limitations with source maps andBunPlugin. Using adebugger;statement is the current workaround. - To debug server code while running the TUI, you might need to use
bun dev spawn, asbun devruns the server in a worker thread where breakpoints may not work.
For VSCode users, example configurations can be found in .vscode/settings.example.json and .vscode/launch.example.json.
Sources: CONTRIBUTING.md:42-65, CONTRIBUTING.md:70-76
Contributing to Specific Areas
Go SDK
The Go SDK has its own contribution guidelines.
- Setup: Run
./scripts/bootstrapand./scripts/build. Requires Go 1.22+. - Code Generation: Most of the SDK is generated. Manual modifications may cause merge conflicts. The
lib/andexamples/directories are never modified by the generator. - Testing: Tests require a mock server running against the OpenAPI spec. Use
npx prism mock path/to/your/openapi.ymlto set it up, then run./scripts/test. - Formatting: The project uses the standard
gofmtformatter, which can be run with./scripts/format.
Sources: packages/sdk/go/CONTRIBUTING.md:3-6, packages/sdk/go/CONTRIBUTING.md:12-15, packages/sdk/go/CONTRIBUTING.md:32-35, packages/sdk/go/CONTRIBUTING.md:40-42
GitHub Action
The project includes a GitHub Action that integrates opencode into GitHub workflows. Development and testing for this action can be done locally.
To test the action, you need to set several environment variables and execute the main script with bun.
MODEL=anthropic/claude-sonnet-4-20250514 \
ANTHROPIC_API_KEY=sk-ant-api03-1234567890 \
GITHUB_RUN_ID=dummy \
MOCK_TOKEN=github_pat_1234567890 \
MOCK_EVENT='{"eventName":"issue_comment",...}' \
bun /path/to/opencode/github/index.ts
The MOCK_EVENT variable should contain a JSON payload mimicking a GitHub event, such as an issue comment or a pull request review comment.
Sources: github/README.md:83-97
Summary
Contributing to OpenCode is a structured process designed to be accessible to everyone. By following the guidelines for development setup, adhering to style conventions, and respecting the pull request and feature request workflows, you can effectively contribute to the project. Whether you're fixing a bug, improving documentation, or adding a new feature, your contributions are valuable. For more information, you can always refer to the official documentation or join the community on Discord.
Sources: README.md:65-66, README.md:86