OpenCode First Project Setup: From Install to First Passing Test
A practical setup guide for OpenCode on an existing project. Configure providers, context files, and project conventions so the agent produces useful output on day one.
Most AI coding agents promise to work out of the box. OpenCode does not. It is a harness, not a product, and the first-run experience reflects that. You will spend more time configuring it than Claude Code or Cursor, but the payoff is a setup that matches your project instead of a vendor’s defaults.
We have onboarded OpenCode to three projects: a TypeScript monorepo, a Python service, and a Go CLI. The same three setup steps mattered every time.
Step 1: Install and Add a Provider
Install the binary with the official shell script, then run opencode in a project directory. The first thing it asks for is a model provider. You can use Anthropic, OpenAI, Google, OpenRouter, or a local Ollama endpoint.
For most developers, Anthropic is the easiest starting point because Claude Sonnet is the most capable general-purpose model. OpenRouter is the better long-term choice if you want to switch models later without reconfiguring API keys for each provider.
Step 2: Define Context File Patterns
By default, OpenCode will try to read everything in your repository. That wastes tokens and confuses the agent with build artifacts, generated code, and dependency directories.
Create .opencode/config.toml in your project root and set include and exclude patterns. For a TypeScript project, we use something like this:
[context]
include = ["src/**/*.ts", "tests/**/*.ts", "package.json", "tsconfig.json"]
exclude = ["node_modules", "dist", "coverage", "*.min.js", ".next"]
The exact paths matter less than the principle: the agent should only see files that are relevant to the task. If your project uses path aliases like @/components, include the alias configuration so the agent understands imports.
Step 3: Write a Conventions File
This is the step most people skip, and it is the step that determines whether the agent’s first pass is usable. Create a CONTEXT.md file with short rules specific to your project:
- Import style: absolute aliases or relative paths?
- Error handling pattern: exceptions, Result types, or error codes?
- Test framework: Jest, Vitest, pytest, Go test?
- Formatting: Prettier, gofmt, ruff?
- Any naming conventions that are not obvious
We keep ours under 300 words. The agent reads it at the start of the session, and the output quality improves immediately.
OpenCode
Set up OpenCode on your project with provider keys, context patterns, and a conventions file. The free tier is enough to test the full workflow.
Free tier available
Affiliate link · We earn a commission at no cost to you.
Step 4: Run a Calibration Task
Before asking for real work, run a task you already know the answer to. Something like “add a simple utility function and a test for it.” Review the diff for three things:
- Did it use the right import style?
- Did it follow the test framework conventions?
- Did it run the test and report the result?
If the answer is yes, your setup is solid. If not, adjust the context patterns or conventions file and try again. This ten-minute calibration saves hours of cleanup later.
What Good Output Looks Like
With the three setup steps in place, a typical request like “refactor the user service to use async database calls” produces a plan, reads the right files, generates a diff, and runs the tests. The diff will not be perfect, but it will be in the right shape. You review, approve, and edit rather than rewrite.
That is the real measure of a working setup. The agent is not replacing you. It is producing a first draft you can finish in minutes instead of hours.
FAQ
Do I need to commit before using OpenCode?
Which provider should I start with?
How long does useful setup take?
Tools used in this review
Some links above are affiliate links. We may earn a commission if you sign up. See our disclosure for details.
Related reading
2026-07-16
How to Measure Cost Per Task with Terminal AI Agents
Terminal AI agents like OpenCode and Claude Code bill by the token, which makes cost per task the metric that matters. Here is how we tracked it and what we learned.
2026-07-16
Multi-Agent Terminal Workflows: Combining OpenCode, Claude Code, and Aider
Running more than one AI coding agent in your terminal is becoming a real workflow. Here is how we split work between OpenCode, Claude Code, and Aider without losing track of the changes.
2026-07-16
Running OpenCode with Local LLMs for Private AI Coding
You do not need to send source code to a cloud API to use an AI coding agent. Here is how we ran OpenCode against a local Ollama model for a proprietary codebase.
2026-07-16
OpenCode Review: A Terminal-Native AI Coding Agent That Keeps Your Editor
We tested OpenCode as a daily driver for two weeks. It is a terminal-based AI coding agent that edits files, runs tests, and supports multiple models without replacing your IDE.
2026-05-28
Aider Review: The Open-Source AI Pair Programmer That Works With Any LLM
I tested Aider across 9 projects with 6 different LLMs over six weeks, spending $47.30 total in API costs. Here's why git-native pair programming is better than accept/reject buttons — and where Aider's terminal-only approach falls short.
Get the best tools, weekly
One email every Friday. No spam, unsubscribe anytime.