A terminal coding agent usually drags a subscription and a lock-in to a single provider along with it: switching models to save money turns into moving your entire setup. OpenCode is built on the opposite principle — it is a model-agnostic agent: any models through any provider, an open stack, active development. In the 2026 ecosystem, the OpenCode Zen model gateway and the OpenCode agent complement each other: Zen opens access to coding models, while the agent does the work in the terminal. This guide covers installation, configuration for the free pool, and the tool’s place in a practitioner’s stack.
Installation and First Run
OpenCode installs with a single command and requires nothing but a terminal. Installer and command status as of fall 2026.
# install with the official script
curl -fsSL https://opencode.ai/install | bash
# or via npm
npm install -g opencode-ai
cd my-project
opencode # interactive session in the terminalAfter launch you get a terminal interface: a dialog with the agent and a panel of file changes. To start, all you need is to pick a model and describe the task. Models switch right inside the session with the /models command — the list is assembled from the connected providers, no restart required. A useful habit for complex tasks: first use planning mode (Plan), where the agent proposes a plan and waits for your confirmation, and only then move to execution — switching takes a single press of the Tab key.
On first launch the agent will ask you to choose a provider and a model — the list comes from the built-in catalog; a missing provider is added through the config described below. Session history is stored locally on your machine: you can return to yesterday’s conversation and pick up where you left off, and the work stays on your computer.
Three commands worth knowing on day one. /init — the agent walks through the codebase and generates a starter AGENTS.md. /compact — compress an overgrown session context without losing the flow of work. /undo — roll back the latest edits if the agent went off course. For scripts and automation there is a non-interactive mode: opencode run “run the tests and fix the failures” completes the task without any interface. Authorization with commercial providers is handled by the opencode auth login command: pick a provider from the list, paste the key, and it is stored locally.
Configuration: opencode.json and AGENTS.md
Configuration lives in the opencode.json JSON file in the project root, or in the global ~/.config/opencode/opencode.json for all projects at once. Minimal example:
{
"model": "groq/openai/gpt-oss-20b"
}The model field sets the default model in the “provider/model” format — here it is GPT-OSS-20B with open weights on Groq’s free pool. The agent reads behavior rules from AGENTS.md in the project root — the same principle as CLAUDE.md in the Claude ecosystem: project goal, stack, code conventions, prohibitions. Sample content:
Goal: a booking web service, Python 3.12 and FastAPI.
Style: ruff and mypy checks are mandatory, tests run with pytest.
Forbidden: editing migrations by hand, pushing to main directly.The file-memory discipline matches the Claude approach almost verbatim: section structure, operating modes, and restrictions transfer between agents with minimal edits. The investment in agent file memory pays off on any harness. API keys never go into the config — only environment substitution like {env:GROQ_API_KEY}: keys stay out of the repository, and the config is safe to commit.
Rules can be spread across several files and connected through the instructions list in the config — a shared team standards file plus a separate file for a specific repository. This is convenient in monorepos where different parts have their own conventions: the agent gets a targeted set of rules instead of a wall of text that eats the context.
Connecting the Free Model Pool
OpenCode works with any OpenAI-compatible provider — the entire matrix of the free LLM API directory connects directly: Groq, Z.ai, OpenRouter, NVIDIA NIM, and other endpoints with a compatible format. The providers section in the config:
{
"provider": {
"groq": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://api.groq.com/openai/v1",
"apiKey": "{env:GROQ_API_KEY}"
}
},
"zai": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://api.z.ai/api/paas/v4",
"apiKey": "{env:ZAI_API_KEY}"
}
}
},
"model": "groq/openai/gpt-oss-20b"
}Switching models inside a session is done with the /models command; switching providers means editing the config. Keys live in environment variables, not in the repository config.
On the free pool the main enemy is per-minute and per-day request limits: an agent session generates many small calls, and the quota drains faster than in a regular chat. If you hit a 429 error, give the session a pause or switch to another provider from the config; typical response patterns are covered in the article on 429 errors and rate limits.
A practical two-layer strategy: routine runs on the free pool, complex tasks go to paid models. The second layer in this ecosystem is covered by the Zen gateway: the OpenCode Zen coding model pool provides dollar-scale limits on coding models for $10 (subscription terms as of fall 2026). A beginner’s mistake is leaving one expensive flagship on every task in a row: switching models in OpenCode takes so little effort that you should be using it.
Strengths from Practice
- Model agnosticism. Any models through any provider, including local ones: Ollama on localhost connects as a regular provider. This is the basis for private setups where the code never leaves the machine — the scheme is described in the article on local models for sensitive data.
- Active development. Updates ship several times a day: fresh features from the agent world reach OpenCode quickly.
- Open stack. The config is transparent, behavior is predictable, customization is complete — from rules to providers and key bindings.
- Price. The agent itself is free; you pay only for the models or for the Zen subscription.
- Two operating modes. Build for direct execution and Plan for agreeing on plans before edits — switching with a single keypress saves both tokens and rework time.
Honest Limits
- Agent maturity. Skills and hooks are weaker than in Claude Code; part of the automation and guardrail mechanics has to be assembled by hand.
- Entry barrier. The terminal and configs scare off beginners: if you are not yet comfortable with the command line, it is easier to start with an IDE agent and move to the terminal once the basic scenarios feel familiar.
- Young ecosystem. Fewer ready-made integrations and templates than the market leaders offer.
- Rate of change. Updates several times a day sometimes change behavior — after major updates, re-check your configs.
Role in the Stack and Common Questions
From the review of five Claude replacements: OpenCode Zen at $10 is the “best helper” with dollar-scale limits, and OpenCode itself is the terminal layer of that subscription. In the “flagship + worker” pairing, the agent takes over the routine: DeepSeek-class models on Zen limits cover the typical backlog, while the flagship is connected for architecture and hard debugging. OpenCode’s place in the overall row of terminal agents is the topic of a separate article on choosing a harness; that article also covers configuring a unified proxy over providers with LiteLLM.
OpenCode versus Claude Code? Agent capabilities, skills, and polished mechanics — Claude Code wins; agnosticism, price, and openness — OpenCode wins. Many practitioners keep both: one for complex tasks, the other for the bulk of routine work.
Do local models work? Yes: an Ollama provider in the config makes private setups on OpenCode real, with no code sent outward. Speed is lower than that of cloud flagships, but for routine and sensitive tasks it is enough.
What about caching and context? Standard mechanisms: long dialogs get compacted, session history is preserved, and the discipline is the same for all terminal agents. One subtlety: the prompt cache is tied to a specific model and the exact sequence of the request, so when you switch models the cache starts building from scratch — one more reason not to switch models mid-task without a real need.
Is AGENTS.md portable? Yes: project rules work in Claude Code and back again with almost no edits — memory files are not tied to a specific agent.
The main takeaway: OpenCode is a working tool of the open stack whose value is defined not by a subscription but by the models you connect to it. Concrete action: install the agent with one command, connect a free provider from the directory, generate AGENTS.md via /init, and run your first routine task — at that very step you will see how the agent reads your project. Tool status as of fall 2026.
