Getting Started with OpenCode
Official Website: opencode.ai — Open-source AI coding agent built for the terminal.
What is OpenCode?
Section titled “What is OpenCode?”OpenCode is an open-source AI coding agent that lives in your terminal (or desktop/IDE). It’s basically an AI buddy that sits next to you and can:
- Read and understand your entire codebase
- Answer questions about how things work
- Write new features based on your instructions
- Refactor and fix bugs
- Undo changes if you don’t like what it did
The best part? It’s designed to run locally. You can hook it up to any provider you like (OpenAI, Anthropic, Google, etc.), keeping you perfectly in control of your codebase’s privacy.
Installation
Section titled “Installation”The fastest way to get started:
curl -fsSL https://opencode.ai/install | bashAlternative Installation Methods
Section titled “Alternative Installation Methods”| Method | Command |
|---|---|
| npm | npm install -g opencode-ai |
| Bun | bun install -g opencode-ai |
| pnpm | pnpm install -g opencode-ai |
| Yarn | yarn global add opencode-ai |
| Homebrew | brew install anomalyco/tap/opencode |
| Arch Linux | sudo pacman -S opencode |
| Chocolatey (Windows) | choco install opencode |
| Scoop (Windows) | scoop install opencode |
| Docker | docker run -it --rm ghcr.io/anomalyco/opencode |
Prerequisites
Section titled “Prerequisites”You’ll need:
- A modern terminal emulator: WezTerm, Alacritty, Ghostty, or Kitty
- API keys for the LLM provider(s) you want to use
Configuration
Section titled “Configuration”Quick Start with OpenCode Zen
Section titled “Quick Start with OpenCode Zen”If you’re new to LLM providers, the easiest path is OpenCode Zen — a curated set of pre-tested models:
- Launch OpenCode and type
/connect - Select opencode from the list
- Visit opencode.ai/auth, sign in, and copy your API key
- Paste your API key when prompted
Using Other Providers
Section titled “Using Other Providers”You can also connect to any supported provider (Anthropic, OpenAI, Google, etc.). Check the full Providers Directory for setup instructions.
Your First Session
Section titled “Your First Session”1. Navigate to Your Project
Section titled “1. Navigate to Your Project”cd /path/to/your/project2. Launch OpenCode
Section titled “2. Launch OpenCode”opencode3. Initialize the Project
Section titled “3. Initialize the Project”Run the /init command inside OpenCode:
/initThis creates an AGENTS.md file in your project root that helps OpenCode understand your project structure, coding patterns, and conventions.
Core Workflows
Section titled “Core Workflows”Asking Questions
Section titled “Asking Questions”Use OpenCode to understand unfamiliar code. The @ key lets you fuzzy-search for files:
How is authentication handled in @packages/functions/src/api/index.tsThis is especially useful when onboarding onto a project you didn’t write.
Building Features (Plan → Build)
Section titled “Building Features (Plan → Build)”OpenCode has two modes, toggled with Tab:
| Mode | Purpose |
|---|---|
| Plan | OpenCode suggests how to implement something (read-only) |
| Build | OpenCode actually makes the changes to your files |
Recommended workflow:
- Switch to Plan mode (
Tabkey) - Describe what you want:
When a user deletes a note, flag it as deleted in the database.Then create a screen showing recently deleted notes where theuser can restore or permanently delete them.
- Review the plan, give feedback, add images for UI reference
- Switch to Build mode (
Tabkey) - Tell it to proceed:
Sounds good! Go ahead and make the changes.
Direct Changes
Section titled “Direct Changes”For straightforward tasks, skip the planning step:
Add authentication to the /settings route. Look at how it's done in@packages/functions/src/notes.ts and implement the same logic in@packages/functions/src/settings.tsUndoing and Redoing Changes
Section titled “Undoing and Redoing Changes”Made a mistake? No problem:
| Command | What It Does |
|---|---|
/undo | Reverts the last set of changes and shows your original prompt |
/redo | Re-applies previously undone changes |
You can run /undo multiple times to step back through several changes.
Sharing Conversations
Section titled “Sharing Conversations”Share your OpenCode conversations with teammates:
/shareThis generates a shareable link and copies it to your clipboard. Conversations are private by default — only shared when you explicitly use this command.
Customisation
Section titled “Customisation”Make OpenCode your own:
| Feature | Description | Docs |
|---|---|---|
| Themes | Change the visual appearance | Themes |
| Keybinds | Customize keyboard shortcuts | Keybinds |
| Formatters | Auto-format code after changes | Formatters |
| Commands | Create custom slash commands | Commands |
| MCP Servers | Connect external tools and data | MCP Servers |
| Rules | Define project-specific coding rules | Rules |
| Config | Full configuration reference | Config |
Key Tips
Section titled “Key Tips”- Be specific: The more context you give OpenCode, the better the results. Reference specific files with
@. - Plan first, build second: Use Plan mode for complex features to review the approach before committing.
- Use undo freely: It’s cheap and fast — don’t be afraid to experiment.
- Commit AGENTS.md: It gives OpenCode persistent knowledge about your project.
- Drag & drop images: OpenCode can understand screenshots and mockups — use them for UI work.