Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add spencerpauly/awesome-cursor-skills --skill best-of-n-solving -a claude-code
Open on GitHub

What 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-code

2Manually: put the files in place

~/.claude/skills/best-of-n-solving/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/best-of-n-solving/

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

Similar skills

All skills for Agent setup: memory, context, orchestration →

From the same set59

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor