Skip to content

Getting Started with OpenCode

Official Website: opencode.ai — Open-source AI coding agent built for the terminal.

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.

The fastest way to get started:

Terminal window
curl -fsSL https://opencode.ai/install | bash
MethodCommand
npmnpm install -g opencode-ai
Bunbun install -g opencode-ai
pnpmpnpm install -g opencode-ai
Yarnyarn global add opencode-ai
Homebrewbrew install anomalyco/tap/opencode
Arch Linuxsudo pacman -S opencode
Chocolatey (Windows)choco install opencode
Scoop (Windows)scoop install opencode
Dockerdocker run -it --rm ghcr.io/anomalyco/opencode

You’ll need:

  1. A modern terminal emulator: WezTerm, Alacritty, Ghostty, or Kitty
  2. API keys for the LLM provider(s) you want to use

If you’re new to LLM providers, the easiest path is OpenCode Zen — a curated set of pre-tested models:

  1. Launch OpenCode and type /connect
  2. Select opencode from the list
  3. Visit opencode.ai/auth, sign in, and copy your API key
  4. Paste your API key when prompted

You can also connect to any supported provider (Anthropic, OpenAI, Google, etc.). Check the full Providers Directory for setup instructions.

Terminal window
cd /path/to/your/project
Terminal window
opencode

Run the /init command inside OpenCode:

/init

This creates an AGENTS.md file in your project root that helps OpenCode understand your project structure, coding patterns, and conventions.

Use OpenCode to understand unfamiliar code. The @ key lets you fuzzy-search for files:

How is authentication handled in @packages/functions/src/api/index.ts

This is especially useful when onboarding onto a project you didn’t write.

OpenCode has two modes, toggled with Tab:

ModePurpose
PlanOpenCode suggests how to implement something (read-only)
BuildOpenCode actually makes the changes to your files

Recommended workflow:

  1. Switch to Plan mode (Tab key)
  2. 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 the
    user can restore or permanently delete them.
  3. Review the plan, give feedback, add images for UI reference
  4. Switch to Build mode (Tab key)
  5. Tell it to proceed:
    Sounds good! Go ahead and make the 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.ts

Made a mistake? No problem:

CommandWhat It Does
/undoReverts the last set of changes and shows your original prompt
/redoRe-applies previously undone changes

You can run /undo multiple times to step back through several changes.

Share your OpenCode conversations with teammates:

/share

This generates a shareable link and copies it to your clipboard. Conversations are private by default — only shared when you explicitly use this command.

Make OpenCode your own:

FeatureDescriptionDocs
ThemesChange the visual appearanceThemes
KeybindsCustomize keyboard shortcutsKeybinds
FormattersAuto-format code after changesFormatters
CommandsCreate custom slash commandsCommands
MCP ServersConnect external tools and dataMCP Servers
RulesDefine project-specific coding rulesRules
ConfigFull configuration referenceConfig
  1. Be specific: The more context you give OpenCode, the better the results. Reference specific files with @.
  2. Plan first, build second: Use Plan mode for complex features to review the approach before committing.
  3. Use undo freely: It’s cheap and fast — don’t be afraid to experiment.
  4. Commit AGENTS.md: It gives OpenCode persistent knowledge about your project.
  5. Drag & drop images: OpenCode can understand screenshots and mockups — use them for UI work.