OpenCode First Project Setup: Install to First Passing Test
Configure providers, context files, and project conventions so the agent produces useful output on an existing codebase from 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-09-02
DeepSeek MLA: 70 GB of KV Cache at 1M Tokens
No DeepSeek-V4 config is public yet. The V3 one is, and its KV-cache math tells you what a million-token window actually costs in GPU memory.
2026-08-13
A Daily LLM Digest Agent Costs $166 and 34 Hours a Year
A year of one scheduled digest agent in production: token costs per stage, infrastructure line items, and the 41 runs that needed a human.
2026-08-13
When Agent Output Passes Zod and Still Breaks the Build
Four failure classes that survive a clean parse, and the three-layer validation pass we run instead.
2026-08-13
Idempotency: Publishing Agents That Survive a Mid-Run Kill
A per-channel ledger makes cross-posting resumable. Why exit code 0 is not a receipt, and what to do when an API has no idempotency key.
2026-08-13
AI Agent Auth: API Keys vs Device Flow vs Scoped Tokens
Three credential models for non-human callers: static keys, the OAuth 2.0 device grant, and short-lived scoped tokens - and when each one fits.
Get the best tools, weekly
One email every Friday. No spam, unsubscribe anytime.