Command-Line Interface (CLI) Reference
Relevant source files
The following files were used as context for generating this wiki page:- packages/opencode/src/session/prompt/codex.txt
- packages/opencode/src/session/prompt/gemini.txt
- packages/opencode/src/command/template/review.txt
- packages/opencode/src/command/template/initialize.txt
- packages/opencode/src/tool/bash.txt
- packages/console/app/src/routes/index.tsx
- packages/opencode/src/session/prompt/beast.txt
- CONTRIBUTING.md
The OpenCode Command-Line Interface (CLI) is an interactive tool that provides developers with an AI-powered coding agent directly in their terminal. It is designed to assist with a variety of software engineering tasks, from writing and running code to reviewing changes and managing git workflows. The CLI leverages different AI models and configurable agent personas to provide tailored assistance.
The core of the CLI is its ability to start and manage agent sessions. These sessions are driven by powerful system prompts that define the agent's personality, capabilities, and operational guidelines. The agent can interact with the local filesystem and execute shell commands, enabling it to perform complex tasks autonomously.
Installation
OpenCode can be installed via several package managers. The following table lists the available installation methods.
| Method | Command |
|---|---|
curl | `curl -fsSL https://opencode.ai/install |
npm | npm i -g opencode-ai |
bun | bun add -g opencode-ai |
brew | brew install opencode |
paru | paru -S opencode |
Sources: packages/console/app/src/routes/index.tsx:94-159
Core Commands
The OpenCode CLI is structured around a set of primary commands that serve as entry points for different agent-driven tasks.
Command Overview
The diagram below illustrates the main commands available in the CLI.
This diagram shows the primary subcommands branching from the main opencode executable.
Command Descriptions
| Command | Description | Source File |
|---|---|---|
review | Reviews code changes. Can review uncommitted changes, a specific commit, a branch, or a pull request. | packages/opencode/src/command/template/review.txt |
init | Analyzes the codebase to create or improve an AGENTS.md file with build/lint/test commands and code style guidelines. | packages/opencode/src/command/template/initialize.txt |
dev | Starts the development server for OpenCode itself. | CONTRIBUTING.md:27-28 |
Agent Personas and Prompts
A key feature of the OpenCode CLI is its use of different "personas" or system prompts to configure the AI agent's behavior. These prompts define the agent's personality, workflow, and interaction style. The system can switch between prompts based on the selected model (e.g., Gemini, Claude) or the specific task.
Prompt Processing Flow
The following diagram shows how a user's request is processed with a system prompt to guide the AI agent.
This sequence illustrates the combination of a static system prompt with a dynamic user query to create a complete context for the AI model.
Sources: packages/opencode/src/session/prompt/codex.txt, packages/opencode/src/session/prompt/gemini.txt
Available Personas
The agent's behavior is heavily influenced by the system prompt file used for the session. Different files establish different operational guidelines.
| Persona File | Key Characteristics |
|---|---|
beast.txt | Designed for autonomous, long-running tasks. Emphasizes a "keep going until solved" workflow, extensive planning, and internet research. |
codex.txt | A general-purpose coding agent persona. Focuses on being concise, direct, and friendly. Includes detailed guidelines on planning (todowrite tool), task execution, and presenting work. |
gemini.txt | A persona for Google's Gemini models. Mandates strict adherence to project conventions, style, and structure. Follows a "Understand, Plan, Implement, Verify" workflow. |
anthropic.txt | A persona for Anthropic's Claude models. Emphasizes conciseness, professional objectivity, and frequent use of the TodoWrite tool for task management. |
qwen.txt | A persona for Alibaba's Qwen models. Stresses conciseness ("fewer than 4 lines"), security (refusing malicious requests), and following existing code conventions. |
Sources: packages/opencode/src/session/prompt/beast.txt, packages/opencode/src/session/prompt/codex.txt, packages/opencode/src/session/prompt/gemini.txt, packages/opencode/src/session/prompt/anthropic.txt, packages/opencode/src/session/prompt/qwen.txt
Command Deep Dive
review Command
The review command is a powerful tool for automated code review. It analyzes code changes and provides actionable feedback, focusing on bugs, structural integrity, and performance.
The logic for the review command is outlined in the flowchart below.
This flowchart shows how the review command determines what to review based on the arguments, what it looks for in the code, and how it verifies potential issues before reporting them.
Sources: packages/opencode/src/command/template/review.txt
init Command
The init command is used to bootstrap agent instructions for a repository. It analyzes the codebase to create an AGENTS.md file. This file contains crucial information for the AI agent, such as:
- Build, lint, and test commands.
- Code style guidelines (imports, formatting, naming, error handling).
This process ensures that the agent operates in a way that is consistent with the project's existing conventions.
Sources: packages/opencode/src/command/template/initialize.txt
Tooling and Execution
The agent's ability to interact with the system is managed through a set of tools, with the bash tool being one of the most critical.
Bash Tool
The bash tool allows the agent to execute shell commands. Its usage is governed by strict guidelines to ensure safety and correctness.
Key Guidelines:
- Directory Verification: Before creating files or directories, use the
Listtool to verify the parent directory exists. - Quoting: Always quote file paths that contain spaces.
- Search: Prefer
rg(ripgrep) overgreporfind. - File Reading: Use the dedicated
ReadandListtools instead ofcat,head,tail, orls. - Working Directory: Use the
workdirparameter instead ofcdcommand chains.
Sources: packages/opencode/src/tool/bash.txt:1-25
Git Workflow: Committing Changes
The agent can create git commits when explicitly asked by the user. The process is designed to be safe and to follow repository conventions.
The sequence diagram below details the commit workflow.
This diagram shows the agent's process for creating a git commit, including analyzing changes, drafting a message, and handling pre-commit hooks.
Sources: packages/opencode/src/tool/bash.txt:34-68
Git Workflow: Creating Pull Requests
The agent can also create pull requests using the gh CLI tool. This process involves analyzing all commits on the current branch, drafting a summary, and creating the PR.
Steps:
- Run
git status,git diff, andgit log main...HEADto understand the branch's state. - Analyze all commits to draft a PR summary focusing on the "why" of the changes.
- Execute
gh pr createwith a title and a HEREDOC-formatted body.