Node Tools & CLI

OpenCode: AI Coding Agent for Terminal & CLI

OpenCode is a full-featured AI coding agent available as a command-line tool, with optional IDE and desktop integrations. It's built on Node.js and works on macOS, Linux, and Windows.

OpenCode: AI Coding Agent for Terminal & CLI

OpenCode is a full-featured AI coding agent available as a command-line tool, with optional IDE and desktop integrations. It's built on Node.js and works on macOS, Linux, and Windows.


Quick Install

# Recommended: Install script
curl -fsSL https://opencode.ai/install | bash

# Or via npm
npm install -g opencode-ai

# Or via Homebrew (macOS)
brew install anomalyco/tap/opencode

Installation Options

macOS

Homebrew (Recommended):

# Add the anomalyco tap for latest releases
brew install anomalyco/tap/opencode

# Alternative: Official Homebrew formula (updated less frequently)
brew install opencode

npm:

npm install -g opencode-ai

Linux

Arch Linux:

# Stable release
sudo pacman -S opencode

# Latest from AUR
paru -S opencode-bin

npm:

npm install -g opencode-ai

# Using Mise (Node version manager)
mise use -g github:anomalyco/opencode

Windows

Chocolatey:

choco install opencode

Scoop:

scoop install opencode

npm:

npm install -g opencode-ai

Docker:

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

From Source

git clone https://github.com/anomalyco/opencode.git
cd opencode
npm install
npm run build
npm install -g .

Prerequisites

Terminal Emulator

You'll need a modern terminal that supports:

  • Kitty graphics protocol (for image display in terminal)
  • Unicode and ANSI color codes

Recommended:

API Keys

You'll need credentials for at least one LLM provider:


Getting Started

1. Launch OpenCode

opencode

This opens the TUI (text user interface) with an interactive prompt.

2. Configure LLM Provider

In the TUI, run:

/connect

Options:

  • OpenCode Zen (recommended): Pre-tested models with good defaults
  • Claude (API key required)
  • GPT-4 (API key or ChatGPT Plus account)
  • GitHub Copilot (GitHub sign-in)
  • Custom provider (75+ available)

Navigate to your project:

cd ~/Projects/my-app
opencode

Then run:

/init

This creates an AGENTS.md file that documents your project structure, coding standards, and build/test commands. OpenCode reads this in every conversation.

4. Start Coding

Ask OpenCode to help:

Add authentication to the /settings route. 
Look at how it's done in /notes and use the same pattern.

Key Commands

CommandPurpose
TabToggle between Plan Mode and Build Mode
Ctrl+CExit OpenCode

Project Management

CommandPurpose
/initInitialize project (create AGENTS.md)
/connectSet up or switch LLM provider
/themeChange terminal theme

Conversation Control

CommandPurpose
/undoRevert last set of changes
/redoRestore undone changes
/shareGenerate shareable link to conversation

Model Selection

CommandPurpose
/modelSwitch LLM model mid-conversation
/providersList available providers

Workflow: Plan → Build → Verify

Mode 1: Plan Mode (Tab key)

In Plan Mode, OpenCode analyzes your request and suggests an approach without making changes.

Use this for:

  • Complex features (plan first, code later)
  • Risky refactors (review the plan, approve, then build)
  • Learning how OpenCode would solve it

Example:

I want to add soft delete support to notes. 
Users should see a deleted notes recovery screen.
They can undelete or permanently delete from there.

OpenCode responds with a detailed plan:

Plan:
1. Add `deletedAt` timestamp to notes table
2. Update queries to exclude soft-deleted notes
3. Create new recovery screen component
4. Add restore/permanent delete endpoints

Mode 2: Build Mode (Tab key again)

In Build Mode, OpenCode makes actual code changes.

Example (continuing from plan):

Looks good! Go ahead and implement it.

Or for simple changes, skip planning:

Add form validation to the email field in AuthComponent.
Match the pattern used in PasswordField.

Usage Examples

Example 1: Explain Existing Code

How is authentication handled in src/api/middleware.ts?
What are the security assumptions?

OpenCode will:

  • Analyze the file
  • Explain the authentication flow
  • Identify potential issues
  • Suggest improvements

Example 2: Add a Feature (With Planning)

/plan-mode

Then:

Add a rate limiter to the API endpoints.
- Limit to 100 requests per minute per IP
- Return 429 with Retry-After header
- Exclude health check endpoints

OpenCode creates a plan. Review it, ask follow-ups:

Can you make it configurable in environment variables?
Should we also rate limit by API key in addition to IP?

Once happy, switch to build mode:

/build-mode
Implement the plan.

Example 3: Refactor with Confidence

Refactor the processOrder function to use async/await
instead of promise chains. Keep the same error handling.

OpenCode:

  • Suggests refactoring approach
  • Shows before/after code
  • Ensures error handling is preserved
  • Updates any dependent functions

Example 4: Fix a Bug

Error: TypeError: Cannot read property 'id' of undefined
in pages/settings.js line 42

Can you find the root cause and fix it?

OpenCode analyzes the error, finds the issue, proposes a fix.

Example 5: Share Your Work

/share

OpenCode generates a URL like https://opencode.ai/s/abc123xyz

Share this with your team for:

  • Code review
  • Documentation
  • Pair programming
  • Debugging help

Configuration

AGENTS.md (Project Config)

After /init, you have an AGENTS.md file that looks like:

# Project: MyApp

## Overview
Full-stack TypeScript application using Next.js and PostgreSQL.

## Tech Stack
- **Runtime**: Node.js 18+
- **Frontend**: React 18 with Next.js 13
- **Backend**: Next.js API routes
- **Database**: PostgreSQL with Prisma ORM

## Project Structure

src/ ├── api/ # Backend handlers ├── components/ # React components ├── pages/ # Next.js pages └── utils/ # Shared utilities


## Coding Standards
- TypeScript with strict mode
- ESLint configured
- Prettier for formatting
- Functional components (no class components)
- Error handling with try/catch

## Key Files
- `tsconfig.json` - TypeScript config
- `next.config.js` - Next.js config
- `.eslintrc.json` - Linting rules
- `prisma/schema.prisma` - Database schema

## Build & Deploy
- `npm install` - Install dependencies
- `npm run dev` - Local development
- `npm run build` - Production build
- `npm run test` - Run tests
- `npm run lint` - Check code style

## Important URLs
- Local dev: http://localhost:3000
- Staging: https://staging.example.com
- Production: https://example.com

OpenCode reads this before every conversation, so it always understands your stack.

.opencoderc (CLI Config)

Create a .opencoderc file in your home directory for global settings:

{
  "defaultModel": "claude-opus",
  "defaultProvider": "anthropic",
  "theme": "nord",
  "editorKeymap": "vim"
}

Terminal Setup

WezTerm works great with OpenCode on all platforms. Here's a basic config:

-- ~/.wezterm/wezterm.lua
local wezterm = require 'wezterm'

return {
  font = wezterm.font('JetBrains Mono'),
  font_size = 12,
  color_scheme = 'Nord',
  
  -- Enable kitty graphics protocol
  enable_kitty_graphics = true,
  
  -- Window padding for readability
  window_padding = {
    left = 2,
    right = 2,
    top = 2,
    bottom = 2,
  },
}

Tips & Tricks

Tip 1: Provide Good Context

The better your prompt, the better OpenCode's response:

❌ Bad:

Fix the bug in authentication.

✅ Good:

Users can't log in with Google OAuth. 
Error: "redirect_uri_mismatch"
The OAuth config is in src/config/oauth.ts.
Check what the redirect URI should be.

Tip 2: Use Images

Drag/drop a screenshot or design image into OpenCode:

Implement a UI component matching this design:
[drag image here]

Tip 3: Reference Files Explicitly

OpenCode understands @filename references:

Look at @src/utils/auth.ts and implement similar logic 
in @src/utils/api.ts

Tip 4: Ask for Plans First

For complex work, always ask for a plan:

How would you implement infinite scroll pagination
in this infinite list component?

Review, iterate, then ask it to implement.

Tip 5: Undo/Redo Safely

Not happy with changes? No problem:

/undo

Tweak your prompt and try again:

/redo

Troubleshooting

"Terminal doesn't support kitty graphics"

OpenCode will fall back to text-only output. Update your terminal:

  • WezTerm: Latest version
  • Alacritty: Latest version
  • Or switch to Ghostty/Kitty

"API key invalid"

/connect

Re-enter your API key. Check that:

  • You copied the full key (no spaces)
  • The key has the right permissions
  • You're using the correct provider URL

"AGENTS.md not found"

/init

OpenCode will create it. It needs to understand your project structure.

"Changes aren't applying"

Check that you're in Build Mode (not Plan Mode). Press Tab to toggle.


Integration with Your Tools

Git + OpenCode

OpenCode commits are normal git commits:

git log --oneline
# Shows OpenCode's commits alongside human commits

Always review before pushing:

git diff HEAD~1
git push  # After review

GitHub + OpenCode

  1. OpenCode makes commits to your branch
  2. You push to GitHub
  3. Create a PR for human review
  4. Merge after approval

Linear + OpenCode

  1. Create a well-scoped Linear issue with acceptance criteria
  2. Ask OpenCode to implement it:
    Implement Linear issue RFX-40:
    [paste acceptance criteria]
    Context files: [list relevant files]
    
  3. Review the changes
  4. Push to GitHub
  5. GitHub/Linear integration auto-updates the issue

Pricing

  • Free: Local models (Ollama) or community models
  • OpenCode Zen: Pre-tested models (small fee or free trial)
  • API Keys: You pay the LLM provider (OpenAI, Anthropic, etc.)

No vendor lock-in. You control your data and costs.


Privacy & Data

  • ✅ Code never stored on OpenCode servers
  • ✅ Works with air-gapped/self-hosted models
  • ✅ All context stays local until sent to your chosen LLM
  • ✅ Share links are read-only snapshots
  • ✅ No telemetry by default

Resources


Next Steps

  1. Install: npm install -g opencode-ai
  2. Configure: Run opencode/connect → choose provider
  3. Initialize: cd ~/projectopencode/init
  4. Try it: Ask OpenCode to explain your codebase
  5. Learn: Read the full docs

OpenCode in one sentence: Open source, privacy-first, terminal-native AI coding agent that pairs well with Linear, GitHub, and your favorite editor.