Show HN: agent-mcts – Monte Carlo tree search on top of Claude Code An open-source MIT-licensed tool called agent-mcts, at version v0.3, wraps coding agent CLIs such as Claude Code with Monte Carlo Tree Search so agents explore multiple solution branches and backtrack from dead ends instead of running a single linear loop. In the author's benchmark on two harder tasks (npm semver ranges and ISO 8601 durations, 10 runs per setting, Claude Code with haiku and a 5-episode budget), tests-only search beat the first attempt in 0 of 10 runs with a mean change of −2.2 points, while adding a --judge option produced 4 better, 4 same and 2 worse answers for a mean change of −0.1 points at roughly 5× the episodes and wall time. The author reports the judge picks the better of two attempts that both pass visible tests 38 times in 62, and calls better judging the next thing to work on. Turn any coding agent into a tree-searching agent. agent-mcts is an open-source MIT test-time search harness that wraps a coding agent CLI with Monte Carlo Tree Search. It is verified with Claude Code; see Supported agents supported-agents for the rest. Instead of a single trajectory that either works or doesn't, your agent explores multiple solution branches, backtracks from dead ends, and concentrates budget on the most promising path. Status: v0.3. Early but real — the full loop search → live tree → apply works today with Claude Code. A Codex CLI adapter ships too, but so far it has only been tested against a fake codex binary. Built in the open; star the repo to follow along, or jump in contributing — early contributors shape the architecture. Not yet, on the tasks measured so far bench/ https://github.com/natsu0529/agent-mcts/blob/main/bench/README.md , v0.3.0, Claude Code with haiku , 5-episode budget . Each answer is scored on hidden tests the agent never sees, and compared with the first attempt of the same run, which is what a single agent run would have returned. Two harder tasks npm semver ranges, ISO 8601 durations , 10 runs per setting: | | answer better than the first attempt | same | worse | mean change | wall time | |---|---|---|---|---|---| | agent-mcts, tests only | 0 | 9 | 1 | −2.2 pt | ~5 min | | agent-mcts, with --judge | 4 | 4 | 2 | −0.1 pt | ~23 min | What the per-run numbers show: - The judge rescues some failures that tests miss, and loses some good answers. First attempts that passed the visible tests but scored 73% and 85% on the hidden ones became 86% and 90%. In another run the judge replaced a 91% first attempt with a 68% one it scored higher. - The judge's ranking is the limit. Between two attempts that both pass the visible tests, it picks the better one 38 times in 62. - Tests-only search is close to a single run. It stops at the first attempt that passes the visible tests, which was the first attempt in 9 of 10 runs. - The judge costs 5× the episodes and about 5× the wall time. An earlier, smaller measurement on three easier tasks looked better 99% with the judge against 90% for a single attempt , but there every first attempt in the judge runs already scored 98% or more, so it never tested this case. Better judging is the next thing to work on full report https://github.com/natsu0529/agent-mcts/blob/main/bench/results/REPORT.md . Production coding agents Claude Code, Codex, Kimi, ... run a single linear loop : act, observe, retry in place. No branching, no backtracking, no principled exploration. Research shows search helps: SWE-Search ICLR 2025 https://arxiv.org/abs/2410.20285 reported a ~23% relative improvement on SWE-bench by adding MCTS on top of software agents. But that result lives in a research framework — there is no tool that brings it to the agent you already use. agent-mcts closes that gap: - Bring your own agent. A thin adapter layer speaks to each agent's headless mode claude -p ; codex exec untested against the real CLI; kimi -p planned . The search engine never knows which agent it's driving. - Real MCTS, not best-of-N. UCT selection, expansion, evaluation, backup. Budget flows toward branches that look promising, away from dead ends. - State you can trust. Every node is an isolated git worktree + a forked agent session. Your working tree is never touched until you apply a result. - Terminal-native. Watch the tree grow live in your terminal. 100% Python, no browser required. uv tool install agent-mcts cd your-project agent-mcts run "fix the flaky test in tests/test auth.py" agent-mcts run --agent codex "fix the flaky test in tests/test auth.py" untested with the real Codex CLI The run auto-detects your installed agent and your test command, then shows the plan before spending anything: Agent: claude · Value: pytest -x -q · Budget: 12 nodes / $10.00 Proceed? y/N While searching, the tree grows live in your terminal real output : task: fix the flaky test in tests/test auth.py run 20260802-190219 · episodes 3/12 · cost $0.31/$10.00 ✓ n0 r=0.00 Q=0.42 N=4 ├── ✓ n1 r=0.67 Q=0.78 N=2 mocked the clock in the auth fixture │ └── ● n3 r=? Q=0.00 N=0 expanding… └── ✗ n2 r=0.00 Q=0.00 N=1 sleep-based fix tests timed out When it finishes or when you Ctrl-C — MCTS is anytime, the partial tree is saved : agent-mcts show inspect the tree; show n3 prints a node's prompt, summary, evaluation agent-mcts resume continue the latest run where it stopped resume -n 20 raises the budget agent-mcts apply stage the best node's changes squash merge — you review and commit agent-mcts apply n2 ...or pick a different branch ┌─────────────────────────────┐ │ search engine │ UCT selection · expansion │ agent-agnostic, Python │ hybrid value fn · backup └──────────────┬──────────────┘ │ AgentBackend protocol ┌──────────────────┼──────────────────┐ ▼ ▼ ▼ claude adapter codex adapter kimi adapter claude -p codex exec kimi -p verified fake-tested planned - Node = git worktree, agent session . Filesystem state branches via worktrees; conversation state branches via session forking native on Claude Code, context-injection fallback elsewhere . - Value function = your tests. Exit 0 scores 1.0; a failing run earns partial credit by pass ratio read from pytest, jest, cargo test, go test and JUnit-style summaries , and the failing output is fed into children's revision prompts. pytest / npm test / make test are picked up automatically. Add --judge to have an LLM score each attempt's diff as well — see LLM judge https://github.com/natsu0529/agent-mcts/blob/main/docs/configuration.md llm-judge . - Every node is a git branch agent-mcts/