The Complete Guide to Using OpenCode Effectively
In the rapidly evolving landscape of AI-powered development tools, few have captured the imagination of the developer community quite like OpenCode. In less than a year, this open-source AI coding agent accumulated over 100,000 GitHub stars,a pace that rivals the fastest-growing developer tools in history. Companies like OpenAI and GitHub have partnered with them. Developers who once relied on Claude Code or Cursor have found a new home. And the reason is simple: OpenCode offers something that no other AI coding tool does,complete freedom over your AI provider.
But having access to a powerful tool is only half the battle. Knowing how to wield it effectively separates the developers who ship faster from those who merely experiment. This guide will take you from your first installation to advanced workflows that will make your team wonder what happened to your productivity.
What Makes OpenCode Different
Before diving into the how, it's worth understanding the why. OpenCode is not just another AI coding assistant. It is an open-source AI coding agent that runs in your terminal, your desktop, or your IDE. It reads your codebase, understands your project structure, writes code, runs commands, and learns your patterns. If you have used Claude Code, Cursor, or GitHub Copilot's agentic features, you understand the concept.
The critical difference lies in provider freedom. OpenCode supports over 75 LLM providers out of the box. You can use Claude, GPT, Gemini, or open-source models like DeepSeek, Kimi, and dozens of others. Same interface, any brain. This is not merely about cost savings (though those are real). It is about choice. When a new model releases, you can try it immediately. When a provider offers better rates, you can switch without changing your workflow. When your company mandates a specific provider for compliance, you can adapt in seconds.
The story of OpenCode's rise is itself instructive. In mid-2025, three factors converged to create its explosive growth. First, the Anthropic block crisis: Claude Code users began receiving emails from Anthropic's abuse-detection systems, leaving thousands of developers searching for alternatives. Second, the provider freedom pitch: OpenCode offered not just an alternative but freedom from ever being locked into a single provider again. Third, the SST pedigree: OpenCode came from the team behind SST, one of the most respected infrastructure-as-code frameworks, giving it credibility that a random open-source project could not command.
Today, OpenCode is used by over 2.5 million developers monthly. It has 700 contributors and over 9,000 commits. But numbers only tell part of the story. The real value lies in what you can build with it.
Getting Started: Installation and Setup
The first step toward OpenCode mastery is getting it running on your machine. Installation is straightforward and works across all major platforms.
Quick Install
The fastest way to install OpenCode is through the official installer:
curl -fsSL https://opencode.ai/install | bash
For npm users:
npm i -g opencode-ai@latest
Or if you prefer Homebrew:
brew install anomalyco/tap/opencode
After installation, you will find OpenCode available as both a desktop application (with a graphical interface) and a terminal-based TUI (terminal user interface). Both share the same underlying capabilities, so choose based on your preference.
Connecting Your AI Provider
Once installed, you need to connect an AI provider. The easiest way is to run OpenCode and use the /connect command:
opencode
/connect
This will guide you through selecting a provider and entering your API key. For free usage, OpenCode provides access to models like MiniMax 2.5, and through OpenRouter, there are additional free APIs you can configure. The trade-off is that free tiers can be slow or throw random error codes during peak times.
For serious work, I recommend using Claude models because they excel at sustained reasoning and planning. However, having multiple providers configured gives you flexibility to switch based on task requirements and budget constraints.
Core Concepts: Build Mode and Plan Mode
Understanding the two primary modes in OpenCode is essential for effective usage. You toggle between them with the Tab key.
Build Mode: Full Power for Implementation
Build mode has full access to all tools. It can read files, write code, run commands, and make changes across your entire codebase. This is your workhorse for implementing features, fixing bugs, and getting things done. When you need code written, tests created, or deployments triggered, Build mode is your answer.
The key to effective Build mode usage is understanding when to let it operate autonomously and when to guide it closely. For routine tasks like generating boilerplate, creating components based on existing patterns, or implementing well-defined features, you can give OpenCode substantial freedom and trust it to deliver. For critical sections involving security, complex business logic, or areas where specific architectural decisions matter, you should provide more detailed guidance.
Plan Mode: Thinking Before Doing
Plan mode is more cautious. It can read files and understand your codebase but cannot make changes without your explicit approval. This makes it ideal for exploration, architecture discussions, and planning complex changes before implementation.
Use Plan mode when you need to understand how something works before changing it. Ask OpenCode to explain a complex piece of code, analyze your project structure, or outline an approach to a challenging problem. Once you have a plan you like, you can switch to Build mode to execute it.
The Power of Context: AGENTS.md
One of OpenCode's most powerful features is its ability to understand your project's specific context. This happens through the AGENTS.md file, which serves as your project's instruction manual for the AI.
OpenCode can automatically generate this file by scanning your codebase:
opencode
/generate-agents
This creates an AGENTS.md file in your project root that captures your project's structure, the languages you are using, your coding patterns and conventions, and your build and test commands. But the real magic comes from manually editing this file to add team-specific guidelines.
Here is an example of what a well-crafted AGENTS.md might contain:
# Project Context
## Tech Stack
- Frontend: React 18 with TypeScript
- Backend: Next.js 14 API routes
- Database: PostgreSQL with Prisma ORM
- Styling: Tailwind CSS
## Project Structure
- /app - Next.js app router pages
- /components - React components
- /lib - Utility functions and helpers
- /prisma - Database schema and migrations
## Coding Conventions
- Use functional components with hooks
- Prefer composition over inheritance
- All components must have TypeScript types
- Use meaningful variable names
- Max function length: 50 lines
## Testing
- Run tests: npm test
- Run tests with coverage: npm run test:coverage
- Test location: /__tests__/*.test.ts
## Build Commands
- Development: npm run dev
- Production build: npm run build
- Lint: npm run lint
The more specific your AGENTS.md, the better OpenCode performs. I revisit mine weekly to add patterns I want it to follow and remove ones that are no longer relevant. Think of it as a living document that evolves with your project.
The Art of Prompting: Getting What You Want
The single most important skill for OpenCode effectiveness is prompt writing. Most users who say "AI coding tools don't work" actually mean "I gave it a vague instruction and got vague output back." That is not an AI problem. That is a thinking problem.
The framework that consistently produces quality output follows this structure:
1. Define the Role
Tell the AI who it is. Without this, it defaults to generic responses.
Example: "Act as a senior full-stack engineer specializing in scalable SaaS architecture using React, TypeScript, Node.js, and PostgreSQL."
2. Define the Objective
Be stupidly precise about what you want. "Build me a dashboard" will get you a generic dashboard. "Build me a SaaS analytics dashboard showing daily active users, revenue trends, and churn rates with interactive charts" will get you exactly that.
3. Define the User
Software without user context is hollow. Are you building for enterprise admins who need dense data or casual consumers who need simplicity? The answer changes everything about how the software should be designed.
4. Define the Stack
Otherwise, AI just guesses. "Use Vite + React + TypeScript + Recharts for the frontend and Express + PostgreSQL + Prisma for the backend" gives much better results than "make it fast."
5. Think in Modules
Instead of "Build feature," think in terms of "auth module, billing module, user module, admin module." Break it apart before you even start. This helps OpenCode understand the boundaries and interfaces between parts of your system.
6. Think in States
Every system has states. When building a feature, consider all the states it can be in: loading, success, error, empty, partial, and so on. Specify these explicitly to get robust handling.
7. Define Constraints
Budget, timeline, existing codebase patterns, team size,anything that limits the solution space. Without constraints, AI optimizes for generic solutions that may not fit your specific situation.
8. Define Edge Cases
Empty input, API failure, auth errors, rate limits. The more edge cases you specify, the more production-ready the output will be.
9. Define Security Expectations
Middelware, validation, rate limiting, access control. If you do not specify these, AI assumes generic handling that may not meet your security requirements.
10. Control Output Format
Structure first, then implementation, then refinement. When you control the output format, you get consistent, predictable results.
Advanced: The Skills System
Even with good prompts, you are still rewriting context every single time. This is wildly inefficient for common patterns. This is where the skills system comes in.
Skills let you define reusable behavior that OpenCode can load on-demand. Create a skill for API integrations, another for SaaS patterns, another for dashboard components. One-time setup, infinite reuse.
To create a skill, add a .md file to your .opencode/skills directory:
.opencode/
skills/
api-skill.md
saas-skill.md
testing-skill.md
Each skill file contains the instructions and patterns you want OpenCode to follow for that type of task. When you need that context, simply reference the skill and OpenCode loads it automatically.
This is how serious builders operate. They create an API skill, a SaaS skill, a dashboard skill, a marketing tool skill. That is how you move from "AI user" to "AI orchestrator."
Building Multi-Agent Systems
One of OpenCode's most powerful features is the ability to run multiple agents in parallel. This is where things get truly interesting.
Imagine giving one agent frontend review, another backend review, and a third DevOps review,all simultaneously. This is not science fiction. This is what you can build with OpenCode today.
You can create a multi-agent code review system that gives every PR the attention of your best frontend, backend, and DevOps engineers, without pulling them into every review. Each agent specializes in its domain, provides focused feedback, and together they provide comprehensive coverage that no single reviewer could match.
To implement this, you configure multiple agents with different system prompts and run them against the same codebase. The frontend agent might check component structure, prop typing, and accessibility. The backend agent might focus on database queries, API design, and error handling. The DevOps agent might review deployment configurations, security settings, and infrastructure code.
Cost Optimization Strategies
Using AI coding tools can get expensive. Here is how to maximize value while minimizing costs.
Intelligent Model Routing
Not every task needs the most expensive model. Use this framework:
- Plan with Opus 4.6 or Codex 5.3 xHigh for architecture, task breakdown, and design discussions
- Execute with Sonnet 4.6 for routine implementation tasks
- Quick tasks with MiniMax or other free/fast models for mechanical diffs and simple changes
Leveraging Free Tiers
OpenCode provides access to models like MiniMax 2.5 that are free to use. Through OpenRouter, there are additional free APIs available. The trade-off is potential slowness and occasional errors during peak times, but for learning and non-critical tasks, these can dramatically reduce costs.
Context Management
Long conversations fill up context windows and increase costs. OpenCode automatically summarizes sessions when tokens exceed thresholds, but you can help by keeping conversations focused and starting new sessions for unrelated tasks.
Production Workflows That Work
Let us bring everything together with some real-world workflows that I use daily.
Feature Development Flow
When I need to build a new feature, I start in Plan mode:
- Describe what I want to build in detail
- Ask OpenCode to analyze the existing codebase and suggest an approach
- Discuss the trade-offs and refine the plan
- Switch to Build mode and implement incrementally
- Run tests and review the changes
- Iterate based on feedback
Code Review Flow
For code review, I use a multi-agent approach:
- Load the code to be reviewed
- Ask separate agents to review for correctness, security, performance, and style
- Consolidate feedback and address issues
Debugging Flow
When something breaks:
- Describe the error and the expected behavior
- Ask OpenCode to analyze the relevant code paths
- Work through potential causes systematically
- Implement a fix and verify it works
Common Pitfalls to Avoid
After months of using OpenCode daily, here are the mistakes I see most often:
Giving Too Much Autonomy Too Quickly
Start with supervised runs and gradually increase automation as you build trust. It is better to over-guide initially and relax controls as you develop confidence in the system's behavior.
Not Setting Clear Boundaries
Use OpenCode's permission system to control what agents can modify. By default, many operations require explicit permission. Configure these based on your risk tolerance.
Ignoring Context Limits
Long autonomous sessions need proper context management. Start new sessions for unrelated tasks. Keep conversations focused. Review and summarize periodically.
Not Leveraging Skills
Creating reusable skills for common patterns makes agents more effective. Do the upfront work to set up skills for your recurring tasks.
Scaling for Teams
For team environments, consider these patterns:
Shared Context Directories
Store team patterns in .opencode/context/project/. Commit these to the repo. Everyone uses the same standards. This ensures consistency across the team.
Shared Skills Directories
Create team-wide skills for common operations:
.opencode/
context/
project/
standards.md
tech-stack.md
skills/
code-review/
guidelines.md
deployment/
process.md
testing/
guidelines.md
The Future of AI-Assisted Development
We are living through a remarkable transformation in software development. The tools available today would have seemed like science fiction just a few years ago. And the rate of progress shows no signs of slowing.
The future is not about AI replacing programmers. It is about AI amplifying what we can build. As Kent Beck said after 52 years of coding, 90% of traditional programming skills become irrelevant, but the remaining 10% become 10x more valuable. The ability to articulate what you want, to design systems, to evaluate quality, and to make architectural decisions,that is where human developers will always add value.
OpenCode and tools like it give us superpowers. They handle the repetitive implementation work so we can focus on the creative and architectural work that truly requires human judgment. The developers who embrace this shift will build things we cannot yet imagine. Those who resist will find themselves increasingly left behind.
The choice is yours. Start small, build trust, and gradually expand what your AI assistants can handle independently. The future of development is collaborative,human and AI working together. And tools like OpenCode make that future accessible today.
This guide is part of my ongoing exploration of AI-powered development tools. For more articles on building with AI, engineering practices, and the future of software development, visit sajad.dev.