All articles

OpenCode: How a Free AI Coding Agent That Rivals Claude Code Actually Works

OpenCode: How a Free AI Coding Agent That Rivals Claude Code Actually Works

How an AI Agent Differs From Chatting With a Model

This article is an extended version of my YouTube video "OpenCode: The Best AI Coding Agent I've Ever Used." The video shows the live workflow; here I go deeper into the tool's architecture, security setup, and common mistakes people make when they first try it.

Video source: OpenCode: The Best AI Coding Agent I've Ever Used — if you want to see the interface and a real code-editing session, start there.

When I first opened OpenCode, my first thought was — how is this actually different from a regular chat with ChatGPT or Gemini? The answer turned out to be in the nature of an agent itself, not in the specific model running underneath.

A regular chat with a model works in a loop: you ask a question, get code, paste it into your project, run it, get an error, paste the error back into the chat, re-explain the context — and round and round on every iteration. Worse, if you edit the code by hand between requests, the model has no idea and keeps answering in the context of an old file version you've already rewritten.

An agent works differently: it connects directly to your project, sees the file structure and file contents, remembers settings and code style you set once — no need to repeat them in every next request. On top of that, an agent can decompose a task into subtasks, run some of them in parallel instead of strictly one after another, and interact directly with external tools — a browser, the filesystem, MCP servers — instead of just outputting text.

Installation: Terminal, Desktop, or Web

OpenCode installs with a single command (npm, a curl script, Homebrew on macOS, an AUR package on Arch) and is then available in three modes at once:

  • TUI (terminal UI) — an interface right in the terminal, similar to Claude Code: run opencode inside a project folder and get a chat with access to that folder's files.
  • Desktop — a graphical version for anyone who'd rather not use the terminal.
  • Web — the opencode web command spins up an interface on localhost that you can connect to from any device on the same local network — a phone, a tablet, another computer, as long as they're all on the same network. One session, accessible from multiple screens.

Worth mentioning separately — editor integrations for VS Code, Cursor, and Zed, available as a plugin that opens as its own tab and runs on the same engine as the terminal version.

Build and Plan — Two Modes of One Agent

Among the built-in agents, two are the core ones — Plan and Build. Plan analyzes the task and lays out a step-by-step plan: which files to create or change, in what order, what project structure is needed — without touching a single line of code. You can read the plan, edit it by hand, remove parts you don't need — and only then switch to Build (Tab key), which executes the plan step by step, creates files directly in the project, and maintains its own todo list of progress.

This split solves a real problem: if you hand a complex task straight to an agent with no plan, it might go in the wrong direction and rewrite half the project incorrectly. Planning is a cheap, token-wise check on direction before the expensive, token-wise work of generating code.

Models and Providers: Not Just a Paid API

By default, OpenCode runs on a free model with no need to connect a paid API key. Running models and then connect opens a list of roughly a hundred providers: local models via Ollama and LM Studio, Hugging Face, OpenRouter, Perplexity, a direct API-key connection to Anthropic and others — one tool instead of a separate browser tab for every service.

If you need a proxy to reach a specific provider, it's configured through environment variables or directly in the config file, including proxies with a username and password.

AGENTS.md — Project Rules the Agent Doesn't Forget

After the first planning run, the init command creates an AGENTS.md file — instructions for the agent itself, based on the plan and project structure it just built. It's worth manually adding rules there that should hold in every future session: a consistent interface style already described in one file, for example, or an explicit instruction not to delete existing comments in the code — a common problem with regular chat models, which tend to strip comments written specifically for documentation during a refactor unless you explicitly forbid it in the system context.

The practical effect: you don't need to re-introduce the agent to your project's context every time — the rules get read from AGENTS.md on every run.

Saving Tokens: Point at the File Directly

A separate practice that noticeably cuts token usage — don't make the agent search the whole project for a file; name it directly in the request ("edit settings.py, add..."). That way the agent doesn't analyze the entire structure, it opens the right file right away — faster and cheaper on tokens, especially noticeable on large projects with hundreds of files.

Skills and MCP — Extending What the Agent Can Do

Skills — predefined capabilities for specific types of tasks (implementing a particular interface style, say), installed into the project folder and pulled in by the agent during a prompt if it decides the skill is relevant to the task. OpenCode uses the same skills structure as Claude Code, so compatibility genuinely runs both ways.

MCP (Model Context Protocol) — a protocol for connecting the agent to external services and tools. The example from the video is Playwright MCP: an automated browser you can drive with a plain-language request like "go to this site, collect these listings, save them to a JSON file." The agent opens a browser via the MCP server, performs the actions, and returns a finished result instead of code you'd otherwise have to write yourself for that same scraping job.

Security: Don't Give the Agent Blanket Permissions

A separate opencode.json config in the project root lets you fine-tune the agent's permissions — and it's worth doing before an incident, not after. The practical recommendation from the video: by default, any file edit and any bash command should require confirmation, except for operations that are clearly safe. That protects against a scenario where the agent, due to a hallucination, deletes part of the project or runs a destructive command without explicit consent.

Other common-sense rules: don't run the agent with more privileges than necessary directly in the root of an important project without a sandbox, and always keep Git history and take backups before running an agent on new or unfamiliar code — that way the consequences of a wrong decision by the agent roll back with one command instead of a restore from an archive.

Summary

Feature What It Gives You
Direct access to project files No more copying code and errors back and forth manually
Plan / Build modes Cheap plan verification first, expensive code generation second
~100 providers and local models One tool instead of tabs for every service — and it works for free
AGENTS.md Project rules don't need to be repeated in every request
Skills and MCP Extending the agent with ready-made skills and external services (browser, etc.)
Permission settings Confirmation before destructive agent actions

OpenCode is free and open source, so there's nothing to lose by trying it — start with opencode in a test project on the default free model, see Plan/Build in action, and only then decide whether a paid provider is worth it for your specific task. A full demo is in the original YouTube video.