Oleksandr Kuzmenko, EditorPublished 6 min readAI-assisted · editor-reviewed
TL;DR
- Wraps Claude Code headless sessions in Monte Carlo Tree Search to explore multiple implementation paths.
- Isolates every trial branch in disposable Git worktrees to prevent dirtying your working tree.
- Automated test suites drive node scoring; optional LLM judges improve accuracy but increase runtime and token costs by 5x.
Key facts
- Version
- v0.3.0
- License
- MIT
- Algorithm
- Upper Confidence bounds applied to Trees (UCT)
- Judge Overhead
- ~5x episodes and wall-clock execution time
Tree Search over Single-Trajectory Agent Loops
Production AI agents such as Claude Code and Codex operate sequentially: act, inspect output, and retry in place without backtracking. The open-source agent-mcts harness (v0.3, MIT license) wraps command-line agents using Upper Confidence bounds applied to Trees (UCT). It enables budget-guided branch expansion, dead-end pruning, and selective backtracking.
Each node in the search tree combines a Git worktree with a forked agent session. Conversation state forks natively via claude -p, while filesystem state remains isolated inside dedicated Git branches (agent-mcts/<run>/<node>). Search runs display a real-time terminal UI showing episodes, dollar spend, and node evaluations without browser dependencies.
Value Functions, LLM Judges, and Cost Tradeoffs
The value function relies on automated test commands like pytest, npm test, or cargo test. A passing suite (exit 0) scores 1.0, while partial test passes receive fractional scores that steer future expansions. Passing the --judge flag evaluates git diffs using an LLM evaluator.
Author benchmarks on npm semver and ISO 8601 validation reveal important tradeoffs. While the judge improved hidden test scores from 73% and 85% to 86% and 90% on several tasks, it multiplied episode count and wall time by 5x compared to single agent attempts. In tests-only mode, the agent stops immediately upon passing visible assertions.
Try it in 2 minutes
pip install agent-mcts
agent-mcts run "fix the flaky test in tests/test_auth.py" --max-cost 5.0When to use
- Use when troubleshooting complex, flaky integration tests with multiple potential root causes.
- Deploy when implementing difficult algorithms where single-shot agent outputs consistently produce partial test passes.
- Use when running overnight autonomous debugging runs constrained by a strict dollar budget.
When NOT to use
- Do not use for trivial single-line edits where standard inline Claude Code retries resolve issues instantly.
- Avoid using with `--judge` on high-volume test suites where multi-attempt API token pricing exceeds engineering time savings.
- Not recommended for dirty Git working directories where uncommitted changes cannot be easily stashed.
What to do today
- Install agent-mcts and run a trial search over a failing unit test using `agent-mcts run 'fix flaky test'`.
- Configure `.agent-mcts.toml` with `uv run pytest -q` to ensure fresh worktrees inherit virtual environment packages.
- Set strict `--max-cost` and node limits when benchmarking with `--judge` to avoid unexpected API token spend.
Step names are taken from What to do today.
Step names are taken from What to do today. Install agent-mcts and run a trial search over a failing unit test using `agent-mcts run 'fix flaky test'`.. Configure `.agent-mcts.toml` with `uv run pytest -q` to ensure fresh worktrees inherit virtual environment packages.. Set strict `--max-cost` and node limits when benchmarking with `--judge` to avoid unexpected API token spend.
- Install agent-mcts and run a trial search over a failing unit test using `agent-mcts run 'fix flaky test'`.
- Configure `.agent-mcts.toml` with `uv run pytest -q` to ensure fresh worktrees inherit virtual environment packages.
- Set strict `--max-cost` and node limits when benchmarking with `--judge` to avoid unexpected API token spend.
