best-of-n-solving — Claude Code skill: parallel attempts, best pick
Runs two or three approaches to a hard problem at once, each in its own git worktree, then helps you pick the winner.
npx skills add spencerpauly/awesome-cursor-skills --skill best-of-n-solving -a claude-codeWhat best-of-n-solving does
Reach for this skill when a problem has several plausible routes and you can't tell upfront which one lands. It spins up isolated git worktrees, so every attempt gets its own branch and working directory and nothing collides. You compare the outcomes and choose.
The work runs through the best-of-n-runner subagent. You define 2–3 distinct strategies first, then launch them with the Task tool and subagent_type: "best-of-n-runner" — all in one message so they run concurrently. Put file paths, the problem statement and a clear success criterion into each prompt: run the tests, measure the query time. Once the runners finish, weigh which one passes tests, which reads cleanest, which performs better. Merge the winning branch or cherry-pick its commits, then clean up the rest.
On a simple problem this is overkill; a single agent does the job. The runners are fully isolated and never see each other's edits, so spell out your success criteria before launching. The branches are real git branches, which means you can inspect them by hand if something looks off.
What it helps with
- chase a bug that could have several root causes
- choose between composition and inheritance in a refactor
- compare libraries for the same feature
- speed up a slow query with competing strategies
- test several architectural options before committing to one
Example prompts for the agent
- Run best-of-n-solving: try three approaches to optimizing this query, each in its own branch
- Launch parallel best-of-n-runner attempts for the payments refactor and show me which branch passes tests
- Use the best-of-n-solving skill to compare two caching options and pick the better one
How to install best-of-n-solving
1Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill best-of-n-solving -a claude-code2Manually: put the files in place
~/.claude/skills/best-of-n-solving/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/best-of-n-solving/
1Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill best-of-n-solving -a codex2Manually: put the files in place
.agents/skills/best-of-n-solving/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill best-of-n-solving -a cursor2Manually: put the files in place
.cursor/skills/best-of-n-solving/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install spencerpauly/awesome-cursor-skills best-of-n-solving2Manually: put the files in place
.github/skills/best-of-n-solving/SKILL.md1Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill best-of-n-solving -a gemini-cli2Platform CLI
gemini skills install https://github.com/spencerpauly/awesome-cursor-skills --path resources/best-of-n-solvingManually: put the files in place
.devin/skills/best-of-n-solving/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill best-of-n-solving -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about best-of-n-solving
How do I install best-of-n-solving in Claude?
Run npx skills add spencerpauly/awesome-cursor-skills --skill best-of-n-solving -a claude-code. The skill file then lands at ~/.claude/skills/best-of-n-solving/SKILL.md.
What does best-of-n-solving do?
It tackles a hard problem by trying multiple approaches in parallel. Each attempt runs in its own git worktree and branch, then you compare the results and keep the best.
When should I skip this skill?
For simple problems it's overkill — one agent is enough. It's built for cases with 2–3 meaningful strategies worth comparing.
Source text
SKILL.md · CC0-1.0
---
name: best-of-n-solving
description: Solve a hard problem by trying multiple approaches in parallel using isolated git worktrees. Each attempt runs in its own branch, and the best solution is selected. Use for complex refactors, tricky bugs, or architectural decisions where multiple strategies could work.
---
# Best-of-N Problem Solving
Use this skill when facing a hard problem with multiple possible approaches — complex refactors, tricky bugs, performance optimization, or architectural decisions where you're not sure which strategy will work best.
## How It Works
Cursor's `best-of-n-runner` subagent type creates isolated git worktrees — each attempt gets its own branch and working directory. Multiple approaches run in parallel without interfering with each other. You compare the results and pick the winner.
## Steps
1. **Identify the approaches** — before launching, define 2-3 distinct strategies. For example, if optimizing a slow database query:
- Approach A: Add a composite index and rewrite the query
- Approach B: Denormalize the schema with a materialized view
- Approach C: Add application-level caching with Redis
2. **Launch parallel runners** — use the Task tool with `subagent_type: "best-of-n-runner"` for each approach. Launch them all in a single message so they run concurrently:
```
Task 1: { subagent_type: "best-of-n-runner", prompt: "Approach A: ..." }
Task 2: { subagent_type: "best-of-n-runner", prompt: "Approach B: ..." }
Task 3: { subagent_type: "best-of-n-runner", prompt: "Approach C: ..." }
```
Each runner gets its own branch and worktree. Include clear success criteria in the prompt (e.g., "run the tests and report if they pass", "measure the query time").
3. **Compare results** — when all runners complete, evaluate:
- Which approach passes all tests?
- Which has the cleanest implementation?
- Which has the best performance characteristics?
- Which is easiest to maintain long-term?
4. **Merge the winner** — check out the winning branch and merge it, or cherry-pick specific commits. Clean up the other worktree branches.
## When to Use This
- A bug that could have multiple root causes
- A refactor where you're choosing between patterns (e.g., composition vs. inheritance)
- Performance optimization with multiple strategies
- Trying different libraries or approaches for the same feature
- Any situation where "just try it" is faster than analyzing
## Notes
- Each runner is fully isolated — they can't see each other's changes.
- Keep prompts specific: include the file paths, the problem statement, and clear success criteria.
- For simpler problems, this is overkill — just use a single agent.
- The branches are real git branches, so you can inspect them manually if needed.
© spencerpauly · CC0-1.0 · spencerpauly/awesome-cursor-skills