Baraklabs

OpenCode Crash Course

The fully open-source AI coding agent that runs in your terminal and supports 75+ LLM providers — Anthropic, OpenAI, Ollama, DeepSeek, and more. No lock-in.

What Is OpenCode?

OpenCode is an AI-powered coding agent that lives inside your terminal (or IDE). Unlike cloud-locked tools, it lets you bring your own model from 75+ providers — Anthropic, OpenAI, Google, DeepSeek, Ollama (local), xAI, and dozens more — and gives the AI direct access to your codebase through a rich set of built-in tools.

The core workflow is simple: describe what you want in natural language, and OpenCode's agent reads your code, plans changes, edits files, runs commands, and iterates — all inside your project directory. No copy-pasting, no switching tabs.

The fastest way to get started is OpenCode Zen — a curated set of tested models hosted by the OpenCode team. Run /connectinside the TUI, select "OpenCode Zen", sign in, create a Pi key, and paste it. You can also connect any other provider from the same menu.

Key Characteristics

Fully Open Source

No vendor lock-in. Self-host, fork, extend — the entire codebase is yours.

Provider-Agnostic

Use any LLM via API key or local inference. Switch models without changing your workflow.

Multi-Interface

TUI, CLI, Web UI, Desktop app, and IDE extension — work however you prefer.

Agent Architecture

Plan mode and Build mode work together. Plan first, then let the agent execute changes automatically.

Built-in Undo/Redo

Snapshots before every change. Revert with /undo if something goes wrong.

MCP Support

Connect external tools like Notion, GitHub, and databases via Model Context Protocol.

Installation

Pick any one method — all install the same OpenCode CLI.

Recommended — curl

curl -fsSL https://opencode.ai/install | bash

npm

npm install -g opencode-ai

Homebrew (macOS / Linux)

brew install anomalyco/tap/opencode

Chocolatey (Windows)

choco install opencode

Docker

docker run -it --rm ghcr.io/anomalyco/opencode

Connect a Provider

# Inside the TUI, run:
/connect
# Select "OpenCode Zen", sign in at opencode.ai/auth,
# create a Pi key and paste it

Alternatively, pick any provider (Anthropic, OpenAI, etc.) from the /connect menu and paste your API key.

Initialize a Project

# Navigate to your project folder and launch
opencode
# Analyze project and create AGENTS.md
/init

The /init command generates an AGENTS.mdfile in your project root. This file helps OpenCode understand your project's structure, stack, and conventions. Commit it to Git so the whole team benefits.

The Two Modes — Build & Plan

Switch between modes with the Tab key. The current mode is always shown in the lower corner of the TUI.

Build Mode (default)

All tools enabled. The agent can read files, write files, run shell commands, and make real changes to your codebase. This is where actual development happens.

Plan Mode

File edits and bash commands require explicit approval. Use this to analyze code, suggest implementation plans, and reason about architecture — without touching anything.

Recommended Workflow

1

Tab → Plan mode

Describe the feature. Let OpenCode create a detailed implementation plan. Iterate on it until it looks right.

2

Refine the plan

Add constraints like "use the same card layout from the main list" or drop in a screenshot as a design reference.

3

Tab → Build mode

Tell it to execute. OpenCode makes all the changes automatically.

4

Review & undo if needed

If something is off, /undo reverts everything from the last set of changes.

Core Tools & Daily Usage

OpenCode gives the LLM access to these tools automatically — no configuration needed.

bash

Execute shell commands (npm install, git status, tests, etc.)

read

Read file contents with optional line ranges for large files.

edit

Modify existing files via exact string replacement.

write

Create new files or overwrite existing ones.

grep

Regex search across your codebase powered by ripgrep.

glob

Find files by pattern — **/*.ts, src/**/*.jsx, etc.

webfetch

Fetch and read web pages for docs and references.

websearch

Search the web via Exa AI.

todowrite

Manage task lists during complex multi-step operations.

lsp

Go-to-definition and find-references via LSP integration.

Everyday Commands

@file.ts

Attach a file directly to your prompt for targeted context.

/undo

Revert the last set of changes. Repeatable — keep undoing to go further back.

/redo

Re-apply reverted changes.

/share

Create a shareable link to this conversation for your team to interact with.

/models

Switch to a different model mid-session.

/connect

Add or change providers and API keys.

/init

Re-analyze project and regenerate AGENTS.md.

/compact

Manually compress context when it gets long.

Mentioning Subagents

Type @ followed by a subagent name to invoke specialized helpers — e.g. @general help me search for this function or @explore find all files related to authentication.

Configuration Deep Dive

Create opencode.json in your project root. OpenCode works with defaults — add only what you need.

Minimal — just set a model

{
  "$schema": "https://opencode.ai/config.json",
  "model": "anthropic/claude-sonnet-4-5"
}

Full production config

{
  "$schema": "https://opencode.ai/config.json",
  "model": "anthropic/claude-sonnet-4-5",
  "small_model": "anthropic/claude-haiku-4-5",
  "formatter": true,
  "lsp": true,
  "permission": { "edit": "allow", "bash": "allow" }
}

Config Precedence (lowest → highest)

1. Remote org defaultslowest priority
2. Global~/config/opencode/opencode.json
3. CustomOPENCODE_CONFIG env var
4. Projectopencode.json in project root
5. Managedadmin-enforced — can't override

Agents & Customization

Agent Types

Primary agents

The main assistants you interact with. Build and Plan are built-in primary agents. Switch with Tab.

Subagents

Specialized helpers invoked by primary agents or via @mention. Built-ins: General (full tools), Explore (read-only), Scout (external docs research).

Creating Custom Agents

Define agents as markdown files — globally in ~/.config/opencode/agents/ (all projects) or project-specific in .opencode/agents/. The filename becomes the agent name.

# Create a security auditor agent
nano .opencode/agents/security-auditor.md
---
description: Reviews code for security vulnerabilities
mode: subagent
model: anthropic/claude-sonnet-4-5
temperature: 0.1
permission:
  edit: deny
  bash: deny
---
You are a security auditor. Focus on:
- Input validation vulnerabilities
- Authentication and authorization flaws
- Data exposure risks

Ready to go provider-agnostic?

Watch the full crash course above — installation, Plan & Build workflow, custom agents, MCP servers, and GitHub Actions CI/CD, all in one video.

Watch the Full Tutorial

Recommended Blogs