Skip to main content

JournalAI

OpenCode vs Claude Code: I Ran Both on the Same 4 Tasks

OpenCode and Claude Code on the same four TypeScript tasks, graded by hidden tests. Pass rates, speed, tokens, cost and free-model privacy, measured.

By LearnWebCraft Team23 min read

I checked Google Trends before writing this. Among topics people search alongside Claude Code, OpenCode is the fastest riser over the last three months, up 2,400%. Claude Code itself is up about 850% among topics searched with "vibe coding". Put those two numbers next to each other and you get the question a lot of developers are asking right now: should I pay for Claude Code, or use OpenCode, which is open source and has free models?

Most of the comparisons I found answer it with a feature table and a pricing table. Those are useful, but they skip the part I actually care about. If I give both tools the same job, does one of them do it better?

So I set up a small test. Four coding tasks in a TypeScript project, written so that each one has a trap. Hidden tests the agents never saw. Two setups on each side: Claude Code with Sonnet 5.5 and with Haiku 5.5, and OpenCode with two of its free models, Big Pickle and DeepSeek V4.1 Flash Free. Each setup ran every task twice. That is 32 graded runs, plus one I had to throw out because I broke my own harness, which I'll get to.

Here's what this post covers:

  1. What the two tools are, and the real difference between them.
  2. How I tested, including the tasks, the hidden tests and how I kept both tools on a clean config.
  3. The results, task by task, with the code the agents wrote.
  4. Speed, tokens and cost.
  5. Privacy, which matters more than usual with free models.
  6. Day-to-day differences that a benchmark doesn't catch.
  7. Which one I'd use, and when.

Versions tested: Claude Code 2.1.318 and OpenCode 2.2.5 (@opencode/cli), both run headless on Windows 11 on 1 December 2026.

The short answer

On these four tasks, every setup passed every hidden test. Claude Code with Sonnet 5.5 was the fastest by a wide margin, averaging about 30 seconds per task. OpenCode with free models took 60 to 75 seconds on average and cost nothing. Claude Code with Haiku 5.5 sat in between on speed and cost about one cent per task at API rates.

That result surprised me, and it's the most useful thing in this post. On small, well-specified tasks in a small repo, the tool and the model mattered much less than the online debate suggests. Where they did differ was speed, how much context they burned, how many tests they wrote, and what happens to your code once it leaves your machine.

If you already pay for Claude, Claude Code is the faster and smoother experience. If you don't, OpenCode's free models did real work in my tests, but read the privacy section before you point Big Pickle at anything you'd mind a model provider keeping.

What each tool is

Both are coding agents that run in your terminal. You describe a change, the agent reads files, runs commands, edits code and checks its own work. The mechanics are close enough that the same prompt works in both.

Claude Code is Anthropic's agent. It runs Claude models only. You sign in with a Claude Pro or Max subscription, or use an API key. It also runs inside VS Code, JetBrains, a desktop app and the web, all against the same agent. Usage on a subscription shares limits with the Claude chat apps. Anthropic lists Pro at $20 a month and Max at $100 or $200.

OpenCode is an open source agent from Anomaly, under the MIT license, at about 230,000 GitHub stars as of today. It's model-agnostic. You can bring an API key for most providers, use OpenCode's own paid gateway (they call it Zen in some places and Console in others), subscribe to their Go plan, or use a rotating set of free models. Version 2.0 rebuilt it around a background service that the terminal, desktop and web clients all talk to. That detail matters later.

The real difference isn't the feature list. It's this: Claude Code is one company's agent tuned for one family of models. OpenCode is a harness you can plug almost any model into. So "OpenCode vs Claude Code" is partly a question about harnesses and partly a question about models, and a fair test has to keep those two apart as much as it can.

How I tested

The project

I wrote a small TypeScript package called invoice-kit. It has money helpers, an invoice model with tax, discounts and due dates, and Vitest tests. It's small on purpose. A big repo would mostly test how well each agent searches, and I wanted to test whether it gets the logic right.

The package stores money as integer cents. Invoices have line items, a tax rate per customer, optional tax-exempt items, a fixed discount and payment terms. That's enough surface for real bugs.

The four tasks

Task 1 is a bug fix. I planted four bugs and gave the agent this prompt:

Fig. 1text
The test suite in this project is failing. Fix the bugs in src/ so that `npx vitest run` passes. Don't change anything under test/.

The bugs are the kind I've seen in real billing code:

Fig. 2ts
// Converts 19.99 to 1998, because 19.99 * 100 is 1998.9999999999998
export function toCents(amount: number): Cents {
  return Math.floor(amount * 100);
}

// Charges tax on the full subtotal and takes the discount off afterwards
export function total(inv: Invoice): Cents {
  const sub = subtotal(inv);
  const taxable = taxableSubtotal(inv);
  const tax = Math.round(taxable * inv.customer.taxRate);
  return sub + tax - inv.discountCents;
}

// Month is 1-based in the string but 0-based in Date, and the result
// goes through local time before toISOString
export function dueDate(inv: Invoice): string {
  const [y, m, d] = inv.issuedOn.split('-').map(Number);
  const due = new Date(y, m, d + inv.termsDays);
  return due.toISOString().slice(0, 10);
}

The fourth bug is a missing padStart in the cents formatter, so 1205 cents prints as 12.5.

There are two traps here. The doc comment on total says the discount is shared between taxable and exempt items in proportion to their value. None of the visible tests check that, so an agent that only chases red tests can miss it. The other trap is time zones. My machine runs at UTC+8. The lazy fix for dueDate, which is new Date(y, m - 1, ...), still goes through local midnight, and toISOString() then shifts it back a day. The visible tests catch that on my machine, but I also run the hidden tests under three time zones to catch fixes that only work by luck.

Task 2 is a feature from a written spec: add invoicesToCsv with RFC 4180 quoting, CRLF line endings, a fixed column order, sorting by date then id, and money as plain decimals. The agent also has to write its own tests.

Task 3 is a refactor: rename the Customer type to Client and the customer field to client everywhere, but keep Customer exported as a deprecated alias so other code doesn't break.

Task 4 is the hard one. Generate invoice issue dates from a recurrence rule:

Fig. 3text
- Monthly schedules keep the start date's day of month, clamped to the last day of shorter months. A schedule starting on Jan 31 goes Jan 31, Feb 28 (or 29), Mar 31, Apr 30. The clamping never "sticks".
- Each scheduled date is computed from the start date, not from the previous (possibly adjusted) date.
- With businessDays, a date on a Saturday, Sunday or holiday moves forward to the next business day. If moving forward would leave the month (for any unit), it moves backward to the previous business day instead.

That last rule is what banks call "modified following". It's easy to describe and easy to get subtly wrong, especially the case where moving backward also has to skip a holiday.

The hidden tests

Each task has tests the agent never sees. I copy them in after the agent finishes, run them, and delete them again. For task 4 they include cases like this one:

Fig. 4ts
test('backward move skips a holiday too', () =>
  // 2026-05-31 is a Sunday. Moving forward leaves May, so move back:
  // Saturday the 30th is a weekend, Friday the 29th is a holiday,
  // so the answer is Thursday the 28th.
  expect(
    issueDates('2026-05-31', { every: 1, unit: 'month', businessDays: true, holidays: ['2026-05-29'] }, 1)
  ).toEqual(['2026-05-28']));

Before running any agent, I wrote my own reference solutions and checked that every hidden test passes against them in UTC, Asia/Kolkata and America/Los_Angeles, and fails against the original buggy code. A hidden test that fails on correct code would make the whole thing meaningless, so I checked that first.

The grader also runs tsc --noEmit, checks whether the agent touched files under test/ when it was told not to, and counts how many test cases it wrote for tasks 2 and 4.

Keeping the configs clean

This part took longer than I expected, and it's the most practical thing I learned.

My normal setup for both tools has plugins, MCP servers and global instruction files. Those would skew the test, so I wanted both agents running close to stock.

For Claude Code I used --setting-sources project and --strict-mcp-config. Those skip user-level settings, which is where hooks and plugins live, and skip any MCP servers. I first tried --bare, which is the obvious flag for this, but --bare only accepts API key auth and never reads a subscription login, so it was no use with a Pro or Max plan.

For OpenCode I pointed XDG_CONFIG_HOME at an empty folder. My first run still called tools named ctx_resume and ctx_execute, which come from a context plugin in my real config. That had me confused for a few minutes. The reason is the 2.0 design: opencode run connects to the background service by default, and that service had already started with my normal config. Adding --standalone starts a private server for the run, and after that the agent listed only its built-in tools.

So the two commands looked like this:

Fig. 5bash
claude -p "$prompt" --model sonnet --output-format json \
  --setting-sources project --strict-mcp-config \
  --permission-mode acceptEdits \
  --allowedTools "Bash(npx vitest:*)" "Bash(npx tsc:*)" "Bash(npm test:*)" "Bash(npm run:*)"

XDG_CONFIG_HOME=./emptycfg OPENCODE_DISABLE_CLAUDE_CODE=1 \
  opencode run --standalone --auto -m opencode/big-pickle --format json "$prompt"

OPENCODE_DISABLE_CLAUDE_CODE=1 stops OpenCode from reading Claude Code's instruction files as a fallback, which it does by default. Claude Code got edit permission plus the test and typecheck commands. OpenCode's --auto approves anything that isn't explicitly denied, so it had slightly more freedom. Neither agent used anything beyond reading, editing and running tests, so I don't think that changed the outcome.

One more thing about the Claude Code runs. With my user settings skipped, a run without --model used Haiku 5.5, so I pinned the model on every run. Even with --model sonnet, Claude Code's JSON output shows a little Haiku usage, because it uses a small model for side jobs.

The run I threw out

My first OpenCode run on task 1 failed the typecheck and produced no hidden test results at all. For a moment it looked like a real finding.

It wasn't. A smoke test from earlier had left a folder with the same name, and a file in it was still locked, so my script's rm -rf silently failed. The script then copied the project into the existing folder, which nested it one level down. The agent found the code in the nested folder and fixed it, and my grader checked the empty outer folder. I reran that case in a fresh folder and it passed everything. I've left the bad run out of every number below, and I mention it because it's a good reminder that most "the AI failed" results deserve a second look at the test harness first.

Results

All 32 graded runs passed every hidden test. Every run left tsc --noEmit clean. No agent edited a test file it was told not to touch.

Setup Hidden tests passed Avg time per task Avg turns Avg input tokens Cost per task
Claude Code + Sonnet 5.5 8 of 8 runs 30.5 s 7.5 194,000 $0.125 at API rates
Claude Code + Haiku 5.5 8 of 8 runs 50.8 s 15.9 436,000 $0.013 at API rates
OpenCode + Big Pickle 8 of 8 runs 74.0 s 7.4 112,000 free
OpenCode + DeepSeek V4.1 Flash Free 8 of 8 runs 60.6 s 7.3 106,000 free

Input tokens include cache reads. The cost figure for Claude Code is the total_cost_usd value its JSON output reports, which is priced at API rates. On a Pro or Max plan you aren't billed that amount. It counts against your usage limits instead.

Here's the time per task, since the averages hide where the gaps are:

Task Sonnet 5.5 Haiku 5.5 Big Pickle DeepSeek Flash Free
1. Bug fix 26 s, 25 s 39 s, 38 s 38 s, 49 s 57 s, 38 s
2. CSV feature 32 s, 30 s 45 s, 55 s 55 s, 50 s 45 s, 62 s
3. Rename refactor 21 s, 23 s 37 s, 22 s 30 s, 36 s 23 s, 46 s
4. Schedule rules 46 s, 41 s 73 s, 97 s 211 s, 123 s 93 s, 121 s

The gap is small on easy tasks and opens up on the hard one. On task 4, Sonnet finished both runs in under 50 seconds. Big Pickle needed 211 seconds on its first try.

Task 1: the bug fix

All four setups fixed all four bugs, and all four found the discount rule that only the doc comment describes. That was the trap I expected someone to fall into, and nobody did.

They also all landed on the same fix for the date bug:

Fig. 6ts
const due = new Date(Date.UTC(y, m - 1, d + inv.termsDays));

The discount fixes were more interesting, because they show style rather than correctness. Sonnet and DeepSeek wrote nearly the same thing as my reference: work out the taxable share of the discount, round it, and tax what's left. Big Pickle skipped the intermediate rounding and taxed a fractional amount, which still rounds to the right cents for every test case. Haiku did something I liked better than my own solution. It noticed the package already had an allocate helper for splitting cents by ratio, and reused it:

Fig. 7ts
const exempt = sub - taxable;
// Share the discount between taxable and exempt items in proportion to value.
const discountOnTaxable =
  sub === 0 ? 0 : allocate(inv.discountCents, [taxable, exempt])[0];
const taxableAfterDiscount = taxable - discountOnTaxable;
const tax = Math.round(taxableAfterDiscount * inv.customer.taxRate);
return sub - inv.discountCents + tax;

allocate hands leftover cents out deterministically, so this version can never lose or invent a cent when it splits the discount. That's the kind of choice you'd hope a careful human would make.

Task 2: the CSV feature

All eight runs got quoting, CRLF, sorting and money formatting right on the first try, including the field with an embedded newline and doubled quotes. All eight sorted a copy rather than the caller's array, which one hidden test checks.

The difference was in the tests each one wrote for itself. Sonnet wrote 6 and 5 test cases in its two runs. Haiku wrote 9 and 10. Big Pickle wrote 5 and 9. DeepSeek wrote 6 both times. More tests isn't automatically better, but it does tell you something about each agent's habits.

Task 3: the rename

The rename was the least interesting task, which is itself useful to know. Every run renamed the type and the field, added the deprecated alias, updated the test fixtures, and left zero stray references to customer. The hidden test, which imports both Client and Customer and type-checks an invoice built with client, passed everywhere.

Two years ago a cross-file rename with a compatibility alias was a decent test for a coding agent. It isn't anymore.

Task 4: the schedule rules

This was the only task where I expected real failures, and there weren't any. All eight runs passed all eight hidden tests in all three time zones, including the holiday-on-the-way-back case.

The solutions did differ a lot in size and approach. Sonnet's were the shortest, at 67 and 74 lines, and the only ones that validated the input date and rejected something like 2026-02-30 with a RangeError, which the spec didn't ask for. Here's the core of its business-day adjustment:

Fig. 8ts
const adjust = (t: number): number => {
  if (!rule.businessDays || isBusiness(t)) return t;
  const month = new Date(t).getUTCMonth();
  let f = t;
  while (!isBusiness(f)) f += DAY_MS;
  if (new Date(f).getUTCMonth() === month) return f;
  let b = t;
  while (!isBusiness(b)) b -= DAY_MS;
  return b;
};

Big Pickle wrote 107 and 132 lines. It built a small CalendarDate type with 1-based months and did all the date logic on that, converting to timestamps only for weekday checks. It's longer, but it reads clearly and every function has a doc comment. Haiku and DeepSeek both landed between 100 and 122 lines.

The tests they wrote for themselves varied even more. Sonnet wrote 8 and 9 cases. Haiku wrote 21 and 28. Big Pickle wrote 23 and 19. DeepSeek wrote 24 and 21. If you value an agent that leaves you a thorough test file, the cheaper models were more generous with them here.

Speed, tokens and cost

Speed is where Claude Code with Sonnet clearly won. It averaged 30.5 seconds per task and never went over 46. The free OpenCode models were roughly twice as slow on average, and much slower on the hard task. Some of that is the model and some is the free tier's serving capacity, which I can't separate from the outside. I only noticed it as waiting.

Token use tells a different story. Claude Code read much more context per run than OpenCode. With Sonnet it averaged 194,000 input tokens per task, and with Haiku 436,000, against about 110,000 for OpenCode. Most of that is cache reads of a large system prompt and tool definitions, repeated on every turn. Haiku also took about twice as many turns as Sonnet, checking its work more often, which multiplies the effect. Cache reads are cheap, so this doesn't hurt much in dollars, but it does mean Claude Code spends more of your usage limit per task than the raw output suggests.

On cost, the free models are free, as long as you accept the privacy terms below. Haiku in Claude Code came to about a cent per task at API rates, and Sonnet to about twelve cents. For context, I ran all 32 tasks for about $1.11 in total at API prices, and that was all on a subscription, so I paid nothing extra.

Privacy, which is the real catch with free models

"Free" in OpenCode means free to you, not free to run. Someone is paying for those tokens, and the terms differ by model. OpenCode's own model docs, which I read today, describe them roughly like this:

Free model What the docs say about your data
DeepSeek V4.1 Flash Free The provider follows a zero-retention policy and doesn't use your data for training
Hy4 flash Free Same zero-retention wording
Big Pickle During its free period, collected data may be used to improve the model
Tidepool, Seaglass, Iceman Free Collected data is retained and used to improve the model
Flint 40B Free Data may be used to improve the model, retained for 30 days
Beam Free Not used for training, retained for 30 days for safety
Nemotron 3.5 Free models Trial use only, don't submit personal or confidential data

The free list changes often, so check the live page before you rely on any row. Still, the pattern matters. Big Pickle, the default free model a lot of people try first, is one where your prompts and code may be used to improve the model. My test project was synthetic invoice code I wrote for this post, so I didn't mind. I wouldn't point Big Pickle at a client's codebase.

If you want OpenCode for free and care about this, DeepSeek V4.1 Flash Free did just as well in my tests and has the zero-retention wording. If you need stronger guarantees, use your own API key with a provider whose terms you've read, or a local model.

Claude Code has its own data terms, which depend on whether you're on a consumer plan, a team plan or the API. They're Anthropic's terms rather than a mix of providers, which makes them easier to reason about, but read them too if you work on code you don't own.

The differences a benchmark doesn't catch

Here are the things I ran into while setting this up that would matter more in daily use than a few seconds per task.

Model choice is OpenCode's whole point. The model list on my machine had 40 options, 11 free and 29 on the Go plan, from DeepSeek and Qwen to Kimi, GLM, Grok and Claude Haiku. If a new model comes out tomorrow and it's good at your kind of code, you can use it in OpenCode the same day. In Claude Code you get Claude models, which happen to be very good at this, but that's the only choice you have.

Claude Code's integrations are broader. The same agent shows up in VS Code, JetBrains, the desktop app, the web and CI. OpenCode has terminal, desktop and web clients and an Agent Client Protocol server for editors, which covers a lot, but Anthropic's side is more polished and better documented.

OpenCode's background service is a real design change in 2.x, and it has consequences. It's nice when you hop between the terminal and the desktop app, because they share sessions. It also means opencode run doesn't load config the way you'd expect from a one-off command. If you script OpenCode in CI or for evals like this one, use --standalone.

Headless use works well in both. Claude Code's -p with --output-format json gives you a single result object with turns, tokens and cost. OpenCode's run --format json streams one JSON event per line, with tokens and cost on each step_finish event. Both were easy to parse, and I used a few lines of Node for each.

Your API key can expire without you noticing. My machine had an OpenCode Go key configured from earlier testing, and the first call to a Go model failed with "This API key has expired". The free models kept working. That's not a flaw so much as something to know: the free and paid paths in OpenCode are separate, and one can break while the other keeps going.

Permissions differ in their defaults. Claude Code asks before it edits or runs anything outside what you've allowed. OpenCode's --auto approves anything not explicitly denied. For interactive use both ask by default, but for scripted runs read the permission docs for whichever you pick, and run them in a folder you can throw away.

What this test doesn't tell you

I want to be clear about the limits, because it would be easy to read too much into "everything passed".

The tasks were small and well specified. Real work is often vague, spread across dozens of files, and depends on context in someone's head. That's where models differ most, and this test doesn't measure it. Third-party indexes that run harder, longer agent tasks do show bigger gaps between top paid models and free ones.

Two runs per task is a small sample. With 32 runs I can say none of these setups failed at this level of difficulty. I can't say how often each one would fail on harder work.

I didn't test interactive use. How it feels to steer an agent mid-task, review its diffs and recover from a wrong turn matters more day to day than anything a headless script can measure.

And the free tier is a moving target. The model list, rate limits and terms will be different in a month.

Which one I'd use

If you have a Claude subscription and mostly want to get work done, use Claude Code. With Sonnet it had the fastest average on every task, its solutions were the tightest, and it's in every editor you're likely to use. What you're paying for is speed and polish, more than correctness.

If you don't want to pay, or you're learning, use OpenCode with DeepSeek V4.1 Flash Free. In my tests it passed everything, it has the clearest privacy wording of the free options, and the price is zero. Expect to wait about twice as long per task.

If you want to try many models, or you need to run a local model for compliance, OpenCode is the only one of the two that can do that. Bring an API key from a provider you trust.

If you're working on code you don't own, avoid the free models whose terms say your data may be used for training. That includes Big Pickle, even though it did well in these tests.

And if you're choosing a coding agent for a team, run something like this on your own code. It took me an afternoon to build, including the mistakes. The tasks your team actually does will tell you far more than any comparison table, including this one.

Run it yourself

The setup is three small pieces. A run.sh copies a clean project, makes a git commit so the diff is easy to read, and runs one agent with one prompt. A grade.sh runs the visible tests and the typecheck, copies in the hidden tests, runs them under three time zones, and deletes them again. A loop runs every setup on every task twice.

The part I'd copy first is the time-zone check, because it catches a whole class of date bugs that pass on the author's machine:

Fig. 9bash
for tz in UTC Asia/Kolkata America/Los_Angeles; do
  TZ=$tz npx vitest run test/schedule.hidden.test.ts
done

The second is the habit of grading a known-good reference solution before grading any agent. If your hidden tests fail on correct code, you're measuring your test, not the agent. And when an agent appears to fail badly, check your harness before you write it up. In my case, the only failure in the whole experiment turned out to be my script.