Welcome to OpenCode
Relevant source files
The following files were used as context for generating this wiki page:- README.md
- CONTRIBUTING.md
- packages/console/app/src/routes/index.tsx
- packages/opencode/src/session/prompt/beast.txt
- packages/opencode/src/session/prompt/gemini.txt
- packages/opencode/src/session/prompt/qwen.txt
- packages/opencode/src/session/prompt/codex.txt
- packages/opencode/src/session/prompt/anthropic.txt
- packages/opencode/src/session/prompt/copilot-gpt-5.txt
- packages/opencode/src/session/prompt/polaris.txt
- packages/opencode/src/session/prompt/anthropic-20250930.txt
- packages/opencode/src/command/template/initialize.txt
- packages/opencode/src/command/template/review.txt
- packages/opencode/src/agent/generate.txt
- packages/opencode/src/session/prompt/plan-reminder-anthropic.txt
OpenCode is an open-source, AI-powered coding agent designed to run directly in the terminal. It assists developers with writing and running code, offering a powerful TUI (Terminal User Interface) and the flexibility to connect with a wide range of LLM providers, including Claude, OpenAI, Google, and local models. Its provider-agnostic nature and client/server architecture are key design principles, allowing it to be driven remotely and ensuring it can adapt as AI models evolve.
The project emphasizes a privacy-first approach, not storing any user code or context data, making it suitable for sensitive environments. It is built by neovim users with a focus on pushing the boundaries of what is possible in a terminal, featuring out-of-the-box LSP support, multi-session capabilities, and the ability to share session links.
Sources: README.md:10, 59-71, 91-101, packages/console/app/src/routes/index.tsx:61-65, 207-209, 310-314
Installation
OpenCode can be installed via several package managers or a direct curl script.
| Method | Command |
|---|---|
| cURL | `curl -fsSL https://opencode.ai/install |
| npm | npm i -g opencode-ai@latest |
| bun | bun add -g opencode-ai |
| brew | brew install opencode |
| paru | paru -S opencode-bin |
| scoop | scoop bucket add extras; scoop install extras/opencode |
| choco | choco install opencode |
| nix | nix run nixpkgs#opencode |
Sources: README.md:21-31, packages/console/app/src/routes/index.tsx:84-180
Installation Directory
The installation script follows a specific priority order to determine the installation path. This allows for user customization while providing sensible defaults.
The following diagram illustrates the directory selection logic.
This logic ensures a predictable and customizable installation experience.
Sources: README.md:36-42
Core Architecture
OpenCode is designed with a client/server architecture, which decouples the user interface from the core agent logic. This allows for multiple clients, such as the primary TUI, to interact with a server that can run locally or remotely.
Sources: README.md:99-101
The codebase is organized into several key packages:
packages/opencode: Contains the core business logic and the agent server.packages/opencode/src/cli/cmd/tui/: The SolidJS-based Terminal UI, which is the primary client.packages/plugin: Source for the@opencode-ai/plugin.
Sources: CONTRIBUTING.md:27-31
This diagram shows the high-level relationship between the main components of OpenCode.
Agents
Agents are the primary mechanism through which OpenCode performs tasks. They are defined by system prompts that give them a persona, a workflow, and a set of rules to follow. OpenCode includes several built-in agents and provides the ability to create new ones.
Sources: README.md:62-64, packages/opencode/src/agent/generate.txt:1-5
Built-in Agents
OpenCode comes with two main agents that can be switched using the Tab key.
| Agent | Description |
|---|---|
build | The default, full-access agent for development work. It has permissions to read and write files and execute commands to complete tasks. |
plan | A read-only agent for analysis and code exploration. It denies file edits by default and asks for permission before running commands. |
A general subagent is also available for complex searches and multi-step tasks, which can be invoked with @general in messages.
Sources: README.md:65-75
Agent Philosophy and Workflow
The behavior of each agent is dictated by a detailed system prompt, tailored for different LLM providers (e.g., Gemini, Anthropic, Codex). These prompts establish core mandates, workflows, and communication styles.
A common workflow pattern emphasized across multiple agent prompts is a multi-step, iterative process.
This diagram illustrates the general workflow promoted in prompts like beast.txt.
Sources: packages/opencode/src/session/prompt/beast.txt:43-56, packages/opencode/src/session/prompt/gemini.txt:42-53, packages/opencode/src/session/prompt/copilot-gpt-5.txt:23-31
Key principles found in the agent prompts include:
- Adherence to Conventions: Agents must rigorously follow the project's existing coding style, libraries, and architectural patterns.
Sources: packages/opencode/src/session/prompt/gemini.txt:6-10 - Incremental Implementation: Agents are instructed to make small, testable changes and track progress through a to-do list.
Sources: packages/opencode/src/session/prompt/beast.txt:101-106, packages/opencode/src/session/prompt/codex.txt:80-87 - Verification: After making changes, agents must run project-specific build, lint, and test commands to ensure correctness and quality.
Sources: packages/opencode/src/session/prompt/gemini.txt:54-58, packages/opencode/src/session/prompt/qwen.txt:107-111 - Concise Communication: Agents should be direct and avoid conversational filler, providing clear and minimal output suitable for a CLI environment.
Sources: packages/opencode/src/session/prompt/gemini.txt:81-87, packages/opencode/src/session/prompt/qwen.txt:44-51
Custom Agents and Commands
OpenCode is extensible, allowing for the creation of custom agents and commands through templates.
initialize Command
This command analyzes the codebase to create an AGENTS.md file. This file serves as a set of instructions for coding agents, containing information like build/lint/test commands and code style guidelines. This helps ensure that any automated changes conform to the repository's standards.
Sources: packages/opencode/src/command/template/initialize.txt:1-6
review Command
The review agent is a specialized command for performing code reviews. It can review uncommitted changes, a specific commit, a branch, or a pull request.
The review process follows a clear decision tree based on the arguments provided.
The agent's primary focus during a review is on identifying bugs, structural inconsistencies, and significant performance issues, while avoiding stylistic nitpicks.
Sources: packages/opencode/src/command/template/review.txt:5-17, 21-30
Agent Generation
A dedicated prompt exists to guide the creation of new agents. This process involves defining a core intent, designing an expert persona, and creating a comprehensive system prompt. The output is a JSON object specifying the agent's identifier, use cases, and system prompt.
Sources: packages/opencode/src/agent/generate.txt:1-20, 52-57
Development and Contribution
The project welcomes contributions, particularly for bug fixes, LSP additions, performance improvements, and documentation.
Local Development Setup
- Requirements: Bun 1.3+
- Setup: Run
bun installand thenbun devfrom the repository root.
Sources: CONTRIBUTING.md:22-25
Style Preferences
While not strictly enforced, the project has several style guidelines to promote consistency:
- Avoid
elsestatements and prefer immutable patterns (avoidlet). - Use
.catch(...)overtry/catchwhere possible. - Use precise types and avoid
any. - Favor concise, single-word identifiers.
- Utilize Bun runtime APIs like
Bun.file()when appropriate.
Sources: CONTRIBUTING.md:73-83
Summary
OpenCode is a robust, terminal-first AI coding agent that prioritizes developer experience, flexibility, and privacy. Its client/server architecture, extensible agent system, and clear contribution guidelines make it a powerful and adaptable tool. The behavior of its agents is meticulously defined through detailed system prompts, ensuring consistent and high-quality assistance across various software engineering tasks.