Claude vs ChatGPT vs Gemini for Coding, with GitHub Copilot (June 2026)
Five real coding tasks, run on each model. Honest results, pricing math, and a decision checklist so you can pick the right tool for your workflow without guessing.
The Models Tested
- Claude Sonnet 4.6 / Opus 4.8 (Anthropic) - via Claude Code CLI and API
- GPT-4o (OpenAI) - via ChatGPT Plus and API
- Gemini 2.5 Pro (Google) - via Google AI Studio and API
- GitHub Copilot (with selectable Claude or GPT-4o backend) - via VS Code agent mode and Copilot CLI
Pricing (June 2026)
| Model | API input / MTok | API output / MTok | Flat subscription |
|---|---|---|---|
| Claude Sonnet 4.6 | $3.00 | $15.00 | - |
| Claude Opus 4.8 | $15.00 | $75.00 | - |
| GPT-4o | $2.50 | $10.00 | - |
| Gemini 2.5 Pro | $1.25 (up to 200k) | $10.00 | - |
| ChatGPT Plus | - | - | $20/mo |
| GitHub Copilot Individual | - | - | $10/mo |
| GitHub Copilot Business | - | - | $19/mo per seat |
The Five Tasks
Task 1: Fix a subtle off-by-one bug
Setup: A recursive binary search returns the wrong index when the target is the last element in an even-length array. The bug is in the caller (not in the snippet shown), one line out of 30. No hint about where to look.
def binary_search(arr, target, lo=0, hi=None):
if hi is None:
hi = len(arr) - 1
if lo > hi:
return -1
mid = (lo + hi) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
return binary_search(arr, target, mid + 1, hi)
else:
return binary_search(arr, target, lo, mid - 1)
# Caller (the actual bug):
result = binary_search(data, value, hi=len(data)) # should be len(data) - 1
| Model | Result |
|---|---|
| Claude Sonnet 4.6 | Found the bug in the caller (not the snippet), explained why hi=len(data) causes the off-by-one on even arrays, fixed it, and added a test. One exchange. |
| GPT-4o | First flagged a non-existent bug in the function itself (false positive), then correctly found the caller issue on follow-up. Two exchanges. |
| Gemini 2.5 Pro | Correctly identified the caller issue on the first try. Also noted the function has no guard for an empty array. One exchange. |
| Copilot (Sonnet 4.6 backend) | Same result as Claude direct. IDE context (the caller file was open) helped it see the issue without being pointed there. |
Verdict: Claude and Gemini both got it in one shot. GPT-4o needed a correction. Claude's fix came with a test; Gemini's came with a bonus edge-case observation. Both useful, different styles.
Task 2: Write a function from a natural-language spec
Spec: "Given a list of order dicts with keys id, amount, currency, and status, return a summary dict: total USD amount (convert GBP at 1.27, EUR at 1.08), count by status, and list of failed order IDs. Amounts are in minor units (pence/cents)."
| Model | Result |
|---|---|
| Claude Sonnet 4.6 | Correct implementation, proper minor-unit division, handled unknown currencies with a logged warning, returned exactly the spec structure. ~25 lines, no extras. |
| GPT-4o | Correct logic but missed the minor-unit division - returned amounts 100x too large. The kind of spec-detail error that slips through without careful review. |
| Gemini 2.5 Pro | Correct, including minor-unit handling. Added type hints and a brief docstring without being asked. ~30 lines. |
| Copilot (GPT-4o backend) | Same minor-unit miss as GPT-4o direct - same underlying model, same result. |
Verdict: Claude and Gemini first-shot it. GPT-4o's miss illustrates that changing the Copilot backend matters: Copilot with GPT-4o inherits GPT-4o's weaknesses, not just its strengths. Switch to Claude backend for spec-dense tasks.
Task 3: Refactor 60 lines of messy imperative code
Setup: A 60-line function handles validation, DB fetch, transformation, and formatting in one block: no separation of concerns, three levels of nesting, magic numbers throughout.
| Model | Result |
|---|---|
| Claude Sonnet 4.6 | Split into four named functions, extracted constants, flattened nesting with early returns, added a comment only where the behavior was non-obvious. Behavior-preserving - confirmed via diff. |
| GPT-4o | Clean extraction, but introduced a class with no reason and added verbose docstrings to every function. Adds review overhead rather than saving it. |
| Gemini 2.5 Pro | Clean extraction with good names, minimal comments (same style as Claude). Also flagged a latent bug in the original validation logic, which was correct. |
| Copilot (Claude backend, VS Code) | Same quality as Claude direct. The IDE inline diff made it easier to review each change without copy-pasting. |
Verdict: Claude and Gemini tied on output quality. GPT-4o's tendency to add structure for structure's sake is a minor but real tax on review time. Gemini's bonus bug catch was useful.
Task 4: Multi-file context - update an endpoint and its test
Setup: A REST endpoint needs a new optional query parameter ?include_archived=true. The endpoint, its Pydantic model, its service layer, and its pytest file are in four separate files. Total context: ~800 lines.
| Model | Result |
|---|---|
| Claude Sonnet 4.6 (Claude Code) | Updated all four files correctly in one shot. Test covered the parameter both present and absent. No hallucinated imports. |
| GPT-4o (ChatGPT with file uploads) | Updated the endpoint and model correctly, missed the service layer change, added a correct test. Required a follow-up for the service layer. |
| Gemini 2.5 Pro | Updated all four files correctly. Its 1M-token context window means it never truncates even very large codebases - a structural advantage on large projects. |
| Copilot (VS Code agent mode, Claude backend) | Opened and edited all four files autonomously. The inline diff view per file is the real workflow win here - no copy-pasting between chat and editor. |
Verdict: Multi-file coherence is where context window size matters most. Gemini's 1M-token window is a structural advantage on large repos. Claude Code matches Gemini here via a different mechanism: it reads files on demand rather than ingesting the whole codebase upfront. GPT-4o via chat needs prodding on multi-file tasks.
Task 5: CLI workflow - find and fix a bug from a bug report
Setup: A bug report says "the export button in the admin dashboard crashes when the dataset has more than 10,000 rows." No file paths provided. Starting from a cold repo.
| Model / Tool | Result |
|---|---|
| Claude Code (CLI) | Searched the codebase for export-related code, identified a pagination bug in the admin export route, wrote the fix, ran the relevant test, committed. Roughly 3 minutes, zero human steps. |
| ChatGPT / GPT-4o | No agentic CLI. Requires copy-pasting code snippets manually. Not applicable to this workflow. |
| Gemini 2.5 Pro | No CLI agent. Same constraint as ChatGPT. |
| Copilot CLI | gh copilot suggest helps with shell one-liners and explains commands - it is not a multi-step coding agent. Cannot search a codebase, write a patch, and run tests autonomously. |
Verdict: For autonomous terminal-based coding, Claude Code is in a different category from everything else. If your workflow is CLI-first, this alone tips the decision.
GitHub Copilot: the model-agnostic delivery vehicle
As of 2026, Copilot lets you select your model inside VS Code:
- Claude Sonnet 4.6 - best for correctness on spec-dense tasks, multi-file changes, agentic mode
- GPT-4o - solid all-rounder; best if you also use ChatGPT for non-coding work
- Gemini 2.5 Pro - best when you need to load a very large file set into one context window
At $10/month individual, Copilot is the cheapest way to get Claude or GPT-4o on real codebases if you stay within the subscription's included token budget. For heavy agentic work (Claude Code-style runs of 100k+ tokens per session), usage-based API access becomes cheaper. Copilot CLI (gh copilot suggest / gh copilot explain) is useful for shell one-liners - it is not a multi-step coding agent.
Where each model wins
| Use case | Best choice | Why |
|---|---|---|
| Autonomous agentic coding (CLI, multi-file changes) | Claude Code (Sonnet 4.6) | Only production-quality agentic CLI; reads files on demand; handles multi-file changes autonomously |
| Very large codebase in one context window | Gemini 2.5 Pro | 1M-token context; can ingest an entire medium-sized repo at once |
| Lowest per-token cost at scale | Gemini 2.5 Pro | $1.25/MTok input - cheapest frontier model for high-volume API work |
| Hard algorithmic problems | Claude Opus 4.8 | Extended thinking; leads SWE-bench Verified; worth the premium on genuinely hard tasks |
| IDE-native workflow, flat monthly bill | GitHub Copilot (Claude backend) | $10/mo flat; inline diffs; PR summaries; pick Claude 4.6 backend for Claude quality at subscription price |
| Mixed coding and image/screenshot tasks | GPT-4o | Best multi-modal integration in ChatGPT; can read screenshots of UIs or error dialogs |
Decision checklist
- I want an autonomous terminal agent that reads my repo and opens PRs. Use Claude Code (Claude Sonnet 4.6 or Opus 4.8).
- My codebase is very large (more than 200k tokens) and I want to ask questions across all of it. Use Gemini 2.5 Pro.
- I want the lowest per-token cost for high-volume API calls. Use Gemini 2.5 Pro ($1.25/MTok input).
- I want a flat monthly subscription and stay inside my IDE. Use GitHub Copilot with Claude Sonnet 4.6 as the backend.
- I need to paste screenshots of errors or UI bugs. Use GPT-4o.
- I have genuinely hard algorithmic problems - competitive programming, novel optimizations. Use Claude Opus 4.8 with extended thinking.
- I want the best first-pass accuracy on everyday coding tasks at a reasonable price. Use Claude Sonnet 4.6.
The bottom line
For most solo developers and small teams, Claude Sonnet 4.6 via Claude Code is the highest-leverage choice in June 2026. It is the only model with a production-quality agentic CLI, first-pass accuracy is consistently higher on spec-dense tasks, and prompt caching brings real-world costs well below the sticker rate.
Gemini 2.5 Pro is the strongest alternative when your codebase is large or your API budget is tight. GPT-4o is a solid choice if you are already in the OpenAI ecosystem or need strong multi-modal support. GitHub Copilot is the pragmatic team pick if you want a flat bill, an IDE-native workflow, and the flexibility to swap models as they improve - just make sure to set the backend to Claude for the best coding accuracy.
Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX