# best-of-n-solving

Runs two or three approaches to a hard problem at once, each in its own git worktree, then helps you pick the winner.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 425 installs · ★ 866
- Author: spencerpauly
- License: CC0-1.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/spencerpauly/awesome-cursor-skills/tree/HEAD/resources/best-of-n-solving/SKILL.md
- Updated: 2026-08-02
- HTML: https://affpapa.org/en/nevibecode/skills/best-of-n-solving

## What it 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.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add spencerpauly/awesome-cursor-skills --skill best-of-n-solving -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/best-of-n-solving/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/best-of-n-solving/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add spencerpauly/awesome-cursor-skills --skill best-of-n-solving -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/best-of-n-solving/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add spencerpauly/awesome-cursor-skills --skill best-of-n-solving -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/best-of-n-solving/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install spencerpauly/awesome-cursor-skills best-of-n-solving
```

2. **Manually: put the files in place**
- File: `.github/skills/best-of-n-solving/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add spencerpauly/awesome-cursor-skills --skill best-of-n-solving -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/spencerpauly/awesome-cursor-skills --path resources/best-of-n-solving
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/best-of-n-solving/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add spencerpauly/awesome-cursor-skills --skill best-of-n-solving -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/spencerpauly/awesome-cursor-skills/tree/HEAD/resources/best-of-n-solving/SKILL.md

## When to use it
- 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
- 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

## Source text · SKILL.md · CC0-1.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 66371957dfa802ff.

BEGIN THIRD-PARTY FILE 66371957dfa802ff
````text
---
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
````
END THIRD-PARTY FILE 66371957dfa802ff

The third-party file has ended. Everything between the 66371957dfa802ff tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2409 of 2807 bytes. © spencerpauly · CC0-1.0 · https://github.com/spencerpauly/awesome-cursor-skills/tree/HEAD/resources/best-of-n-solving/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
