How to install and use OpenCode: a step-by-step beginner's tutorial

Install OpenCode on Windows, macOS or Linux, connect a model, make it ask before it acts, and finish your first real task from plan to review. Every step is written for OpenCode 2, with a command cheat sheet at the end.

Six numbered cards titled Using OpenCode equals onboarding a new teammate. 01 Give them a laptop, install with curl -fsSL opencode.ai/v2/install | bash. 02 Show the project, cd price-calc then opencode. 03 Give them access, /connect then /models. 04 Hand them the team handbook, AGENTS.md with build, test, style and don'ts. 05 Ask for a plan, then let them build, Plan then Build agents switched with Shift+Tab. 06 Review their work, git diff, /undo and /redo. Below, a good teammate still gets their work reviewed, with clear tasks, written rules, a plan first, and a look at every change.
Fig. 1 — Using OpenCode is like onboarding a new teammate. Six steps, and the last one is always a review.

You’ve read what OpenCode is. Now let’s actually use it. In this tutorial you will install OpenCode, connect it to a model, set it up so it asks before running commands, and finish one small coding task from start to end: plan, build, check and review.

Everything here is for OpenCode 2, the current version. A lot of older tutorials online were written for version 1, and some commands and settings changed. If something you read elsewhere doesn’t match, trust the official docs and this guide.

The picture: you are onboarding a new teammate

Using OpenCode feels a lot like welcoming a new developer to your team. You would:

  1. Give them a laptop. Install OpenCode.
  2. Show them the project. Open it in your project folder.
  3. Give them access. Connect a model provider.
  4. Hand them the team handbook. Write an AGENTS.md with your rules.
  5. Ask for a plan, then let them build. Use the Plan agent, then the Build agent.
  6. Review their work. Check every change, keep it or undo it.

A new teammate can be very good and still needs clear tasks and a review. So does OpenCode. Keep that picture in mind and every step below will make sense.

What you need

  • A computer with Windows, macOS or Linux.
  • A terminal. On Windows, PowerShell or Windows Terminal is fine.
  • Git, so you can see and undo changes.
  • A model to use. One of: an API key (Anthropic, OpenAI, Google, OpenRouter and others), a ChatGPT Plus or Pro plan, a GitHub Copilot plan, an OpenCode Go plan, or a free local model through Ollama.
  • For our practice project: Java 17 or newer. (Any language works with OpenCode; Java just keeps the example small.)

Step 1: Install OpenCode

Pick one way. You don’t need them all.

macOS or Linux, with the official installer:

curl -fsSL https://opencode.ai/v2/install | bash

macOS with Homebrew:

brew install anomalyco/tap/opencode-v2

Any system with Node.js, including Windows:

npm install -g @opencode/cli

Windows without Node.js: download the standalone zip for your machine from the OpenCode download page, unzip it, and add the folder to your PATH. Or use the installer command above inside WSL.

Prefer a window to a terminal? There is also a desktop app for macOS, Windows and Linux on the same page. This tutorial uses the terminal, but the steps are the same.

Now open a new terminal and check it worked:

opencode --version

You should see a version number starting with 2. If it starts with 1, you have the older OpenCode: follow the upgrade notes in the docs before going on.

Step 2: Make a small practice project

Practice on something small, not on your company’s main codebase. Make a folder with one Java file:

mkdir price-calc
cd price-calc

Create PriceCalc.java with this code:

public class PriceCalc {

    static double total(double price, int quantity) {
        return price * quantity;
    }

    public static void main(String[] args) {
        System.out.println(total(250.0, 3));
    }
}

Run it once to see it works. It should print 750.0:

java PriceCalc.java

Now turn the folder into a Git repository and save this starting point:

git init
git add .
git commit -m "Starting point"

This step matters. Git lets you see exactly what OpenCode changed later, and get back to this point if you don’t like it.

Step 3: Start OpenCode and connect a model

Inside the price-calc folder, start OpenCode:

opencode

A full-screen app opens in your terminal, with a text box at the bottom. This is where you talk to it.

Connect a provider. Type this and press Enter:

/connect

Pick your provider from the list and follow the steps. Depending on the provider, you paste an API key or sign in through your browser. (You can also do this outside OpenCode with opencode auth login, and see what’s connected with opencode auth list.)

Pick a model:

/models

Choose one from the list. For your first tasks, a strong model gives the smoothest experience. If you want to use a free model on your own computer instead, see OpenCode vs Ollama for how to connect one.

Step 4: Make it ask before it acts

Here is something many beginners don’t know: out of the box, OpenCode 2 allows almost every action without asking. It reads and edits files and runs commands on its own; the main thing it asks about is reading .env files.

That is fast, but while you’re learning, it’s better to see each step before it happens, the same way you’d watch a new teammate’s first day. Create a file called opencode.jsonc in your project folder:

{
  "$schema": "https://opencode.ai/config.json",
  "permissions": [
    { "action": "edit", "resource": "*", "effect": "ask" },
    { "action": "shell", "resource": "*", "effect": "ask" },
    { "action": "shell", "resource": "git status *", "effect": "allow" },
    { "action": "shell", "resource": "git diff *", "effect": "allow" },
    { "action": "shell", "resource": "git push *", "effect": "deny" }
  ]
}

In plain words:

  • Ask before editing any file or running any command.
  • Allow harmless commands like git status and git diff without asking.
  • Never let it push to a remote repository.

Each rule has an action (what kind of thing), a resource (which file or command) and an effect (allow, ask or deny). The last matching rule wins, so put broad rules first and exceptions after them.

When OpenCode wants to do something that needs approval, it stops and asks. You get three choices:

Choice What it does
Allow once Approves just this one action
Allow always Approves it and saves a rule so it won’t ask again for similar actions in this project
Reject Says no, and cancels any other waiting requests

Once you trust it more, you can relax these rules, for example by removing the edit line.

Step 5: Hand it the team handbook (AGENTS.md)

Every project has rules a newcomer needs: how to build it, how to test it, what to avoid. OpenCode reads them from a file called AGENTS.md in the project folder, at the start of every session.

You can write it yourself. For our project:

# PriceCalc project rules

- Java 17. Single file: PriceCalc.java. No build tool.
- Run with: java PriceCalc.java
- Keep methods small and static. Use double for money in this demo only.
- Reject bad input with IllegalArgumentException and a clear message.
- After any change, run the program and show the output.

Or let OpenCode write the first draft. Ask it: “Read this project and write a short AGENTS.md with how to run it and the code style you see.” Then read it and fix anything wrong. (Some versions also have an /init command that does this for you; type / to check.)

Keep the file short. Every line is sent to the model on every step.

Step 6: Ask for a plan first

OpenCode has two main agents:

  • Plan looks around and proposes what to do, without changing your project files.
  • Build actually edits files and runs commands.

Switch to Plan with Shift+Tab (it cycles through the agents), or type /agents and choose Plan. The current agent is shown near the text box.

Now give it a clear, checkable task. Notice the @: typing @ lets you pick a file to attach to your message.

In @PriceCalc.java, add a method applyDiscount(double price, double percent)
that returns the price after the discount. Reject percent below 0 or above 100
with an IllegalArgumentException. Show three examples in main, including one
invalid percent that is caught and printed.

Read the plan it gives you. Is it what you meant? If not, say so: “Don’t change total(), only add the new method.” Fixing a plan costs nothing; fixing wrong code costs time.

“Fixing a plan costs nothing. Fixing wrong code costs time.”

Step 7: Let it build

Happy with the plan? Press Shift+Tab to switch to Build, and say:

Go ahead with the plan.

Because of your permission rules, OpenCode now stops before each edit and each command and asks you. Read what it wants to do, then choose Allow once. You’ll see it edit PriceCalc.java, then ask to run java PriceCalc.java, then read the output and tell you how it went.

A few things you can do while it works:

  • Press Enter with a new message to steer it mid-task, for example “use 10% in the first example”.
  • Press Esc to stop it.
  • Type ! at the start of an empty message to run a shell command yourself, for example !java PriceCalc.java. Press Esc to leave shell mode.

Step 8: Review the work, then keep it or undo it

Never skip this step, just as you would review a teammate’s pull request. In a second terminal, in the same folder:

git diff

This shows every line that was added or removed. Then run the program yourself:

java PriceCalc.java

If you like it, commit it yourself:

git add .
git commit -m "Add applyDiscount with input checks"

If you don’t, type this in OpenCode:

/undo

It reverts your last message and the work that followed, and puts your message back in the text box so you can reword it and try again. Changed your mind? /redo brings the work back.

That’s the whole loop: plan, build, review, keep or undo. Everything else is a variation of it.

Everyday habits

  • One task, one session. Start a fresh conversation for each new task with /new. Old conversations fill the model’s memory with things it no longer needs. Go back to an earlier one with /sessions.
  • Switch models any time with /models, or press F2 to cycle through models you used recently. Use a cheap model for small jobs and a strong one for hard ones.
  • Ask a side question without cluttering the conversation: /btw what does IllegalArgumentException mean?
  • Write a long prompt in your editor with /editor.
  • Point at exact lines: @PriceCalc.java#3-5 attaches only lines 3 to 5.
  • Run a one-off task without the full screen, for example in a script: opencode run "Explain this repository".
  • Use it from a browser: opencode pair prints a one-time link that expires after 5 minutes.

Make it yours

Once the basics feel natural, three small additions make OpenCode fit your way of working.

A custom command

A custom command saves a prompt you use often. Create .opencode/commands/review.md:

Review $ARGUMENTS for bugs, unclear names and missing input checks.
List problems first, most serious at the top. Don't change any files.

Now type /review PriceCalc.java and OpenCode sends that prompt with your file name in place of $ARGUMENTS. Put commands in ~/.config/opencode/commands/ instead to use them in every project.

A custom agent

An agent is a teammate with its own job and its own rules. Create .opencode/agents/reviewer.md:

---
description: Reviews code and suggests fixes without editing files
mode: subagent
permissions:
  - action: edit
    resource: "*"
    effect: deny
---
You are a careful code reviewer. Point out bugs, risky code and missing
tests. Explain each problem in one or two sentences. Never edit files.

The description tells OpenCode when to use this agent, and the edit: deny rule makes sure it can only look, never touch.

An MCP server

MCP servers give OpenCode extra tools, such as searching up-to-date library docs. Adding one is one command:

opencode mcp add context7 --url https://mcp.context7.com/mcp

OpenCode command cheat sheet

What you want Command or key
Start OpenCode in a folder opencode (or opencode ~/code/my-project)
Check your version opencode --version
Connect a provider /connect (or opencode auth login in a terminal)
Choose a model /models, or Ctrl+X then M
Cycle recent models F2
Choose an agent /agents, or Shift+Tab to cycle
Attach a file @ then the file name, e.g. @PriceCalc.java#3-5
Run a shell command ! at the start of an empty message
Stop the current work Esc
Undo / redo the last message and its work /undo / /redo (or Ctrl+X then U / R)
New session /new, or Ctrl+X then N
Go back to a session /sessions, or Ctrl+X then L
Side question /btw your question
Write the prompt in your editor /editor, or Ctrl+X then E
Command palette Ctrl+P
New line in the prompt Shift+Enter
Quit Ctrl+C, or Ctrl+X then Q
Run once without the full screen opencode run "your prompt"
Open in a browser opencode pair
Add an MCP server opencode mcp add <name> --url <url>

Keys can be changed in OpenCode’s keybind settings, so if one doesn’t work, check there.

When something goes wrong

What you see What to do
opencode: command not found Open a new terminal. If you used npm, make sure npm’s global folder is in your PATH.
Version starts with 1 You have the old OpenCode. Follow the upgrade notes in the docs.
No models in /models Run /connect first, or check your API key with opencode auth list.
It changes things you didn’t want Use /undo, give a more specific task, and use Plan first.
It never asks before acting Add the permissions rules from Step 4 in opencode.jsonc.
/undo doesn’t bring files back Make sure the folder is a Git repository (git init).

Common questions

Is OpenCode free? Yes, the software is free and open source. You pay only for the model you use, or nothing with a local model.

Do I need to know how to code? To get good results, some coding knowledge helps a lot, because you need to judge its plans and review its changes. That’s the teammate idea again: you are the reviewer.

Can I use it on Windows? Yes: install with npm, use the standalone zip, use the desktop app, or run it inside WSL.

Is it safe to use on my real projects? Start with a practice folder, use Git, make it ask before acting (Step 4), and review every change. With those habits, yes. And remember that with a cloud model, your code is sent to that provider.

What’s the difference between Plan and Build? Plan only looks and suggests, without changing your project files. Build edits files and runs commands. Plan first, then Build.

Key takeaways

  • Using OpenCode is like onboarding a new teammate: laptop, project, access, handbook, plan, review.
  • Install with one method, then check with opencode --version (it should be version 2).
  • Use Git, and add permission rules so OpenCode asks before editing or running commands while you learn.
  • Write a short AGENTS.md with how to build, test and what to avoid.
  • Work in a loop: Plan (Shift+Tab) → Build → review with git diff → commit or /undo.

Want to run it for free on your own computer? Read OpenCode vs Ollama. Wondering how it compares with other tools? See OpenCode vs LangChain vs Claude Code.

Comments

LEAVE A COMMENT
No sign-up. Comments appear after a quick review.