This directory contains benchmarks for evaluating LLM performance on filesystem tool usage in OpenCode.
The benchmark evaluates how well different LLMs use specialized filesystem tools (Read, Glob, Grep) instead of falling back to bash commands when working with code repositories. This is critical for ensuring agents use the most appropriate and efficient tools available.
-
Build OpenCode:
./packages/opencode/script/build.ts --single
-
Ensure Python 3.x is installed
Run the benchmark for a single model:
PYTHONUNBUFFERED=1 python benchmarks/bench.py --model <model-name> --agent build
We regularly benchmark these 4 models:
- anthropic/claude-opus-4-5-20251101 - Highest reliability, best tool discipline
- anthropic/claude-sonnet-4-5-20250929 - Best value, good performance
- openai/gpt-5.2-codex - Good tool discipline, extreme token usage
- google/gemini-3-pro-preview - Testing alternative providers
# Run all 4 standard models
PYTHONUNBUFFERED=1 python benchmarks/bench.py --model anthropic/claude-opus-4-5-20251101 --agent build
PYTHONUNBUFFERED=1 python benchmarks/bench.py --model anthropic/claude-sonnet-4-5-20250929 --agent build
PYTHONUNBUFFERED=1 python benchmarks/bench.py --model openai/gpt-5.2-codex --agent build
PYTHONUNBUFFERED=1 python benchmarks/bench.py --model google/gemini-3-pro-preview --agent build--cases Path to test cases JSON (default: benchmarks/cases.json)
--model Model identifier (default: anthropic/claude-sonnet-4-5-20250929)
--binary Path to opencode binary (default: ./packages/opencode/dist/opencode-linux-x64/bin/opencode)
--agent Agent to use: build, general, explore (default: build)
The benchmark includes 5 test cases:
- where-is-anthropic-system-prompt - Find system prompt file for Anthropic
- where-is-bash-txt - Find bash tool instruction file
- where-is-oauth-callback - Find OAuth callback implementation
- lib-for-md-in-desktop - Identify markdown parsing library
- dd-trace-java-look-for-test - Find complex test file in external repo
Test cases are defined in benchmarks/cases.json.
The benchmark displays real-time progress including:
- Per-case results (pass/fail)
- Tool calls made
- Token usage and cost
- Number of turns
- Summary table at the end
Detailed results are saved to benchmarks/output/<case-id>/<timestamp>-<session-id>.json containing:
- Complete event stream
- Tool calls with parameters
- Token usage breakdown
- Cost information
- OpenCode version
- Repository and commit information
Comparative analysis of all models is documented in benchmarks/ANALYSIS.md.
Tests pass when:
- Only allowed tools are used (no inappropriate bash commands)
- The expected flag/answer appears in the final response
Tests fail when:
- Inappropriate bash commands are used (e.g.,
find,grep -A,ls) - The expected answer is not found in the response
- No tools are used (hallucination)
The benchmark automatically prepends a timestamp to each prompt to prevent token cache contamination between runs:
[Current time: YYYY-MM-DD HH:MM:SS UTC]
<original prompt>
The benchmark uses git worktrees for efficient repository management:
- Clones are cached in
benchmarks/repositories/ - Working copies are created in
benchmarks/workspaces/ - Each test case runs in an isolated checkout at a specific commit
# Rebuild OpenCode
./packages/opencode/script/build.ts --single# Ensure binary is executable
chmod +x ./packages/opencode/dist/opencode-linux-x64/bin/opencodeAlways use PYTHONUNBUFFERED=1 to see real-time output.
Edit benchmarks/cases.json:
{
"id": "test-case-id",
"repo": "github.com/org/repo",
"commit": "commit-sha",
"prompt": "Your test prompt",
"allowed_tools": ["read", "glob", "grep", "bash/ls"],
"flag": "expected-string-in-answer"
}"read","glob","grep"- Allow these tools"bash/ls","bash/git"- Allow specific bash commands- Bash commands are validated by first word only
After running benchmarks, you can generate a new analysis by examining the JSON output files in benchmarks/output/ and updating benchmarks/ANALYSIS.md.
- PYTHONUNBUFFERED=1 is required for real-time output
- Average runtime: 2-5 minutes per model (5 test cases)
- Token caching significantly reduces cost on subsequent runs
- Gemini models take longer due to reasoning overhead
| Model | Pass Rate | Avg Cost | Avg Tokens |
|---|---|---|---|
| Claude Opus | 80% (4/5) | $0.0817 | 336.6 |
| Claude Sonnet | 80% (4/5) | $0.0523 | 506.4 |
| GPT-5.2-codex | 80% (4/5) | $0.0000 | 20,262.2 |
| Gemini 3 Pro Preview | 40% (2/5) | $0.1064 | 33,717.6 |
See benchmarks/ANALYSIS.md for detailed analysis.