Spawn multiple agents to compete on the same task, cross-pollinate ideas, and pick the best solution by vote.
SaferSkills independently audited horse-race (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
You are orchestrating a "horse race" — multiple independent agents competing to produce the best solution to a programming task. Agents can be Claude Code subagents or OpenAI Codex CLI agents (when available). The process has three phases: independent implementation, cross-pollination improvement rounds, and Borda count consensus voting by independent judges.
Phase 0: Detect Codex CLI
`which codex` → found?
Yes → 2 Claude Code + 2 Codex CLI agents (4 total)
No → 3 Claude Code agents
Phase 1: Independent Implementation
Agent A (Claude) ──► Solution A
Agent B (Claude) ──► Solution B (all in parallel, isolated worktrees)
Agent C (Codex) ──► Solution C
Agent D (Codex) ──► Solution D
Phase 2: Improvement Rounds (repeat N times)
Each agent receives ALL other agents' diffs
Agent A sees B+C+D diffs ──► Improved A'
Agent B sees A+C+D diffs ──► Improved B' (all in parallel)
Agent C sees A+B+D diffs ──► Improved C'
Agent D sees A+B+C diffs ──► Improved D'
Phase 3: Borda Count Voting by Independent Judges
3 fresh judge agents rank all solutions
Points tallied, highest Borda score wins
Ties broken by a 4th independent judge
Winning diff applied to current branchThe user can override these, e.g., "horse race this with 5 agents and 3 rounds".
Before spawning agents:
which codex. If the command is found, set codex_available = true and plan for 2 Claude Code agents + 2 Codex CLI agents (4 total). If not found, set codex_available = false and use 3 Claude Code agents. Tell the user which configuration was detected.Spawn all agents in a single message so they run in parallel.
#### Claude Code Agents
For each Claude Code agent (numbered 1 through N_claude), use the Agent tool with isolation: "worktree":
description: "horse-{i}"
isolation: "worktree"
prompt: |
You are Agent {i} in a competitive programming challenge. Your goal is to produce the best possible solution.
TASK:
{task_description}
INSTRUCTIONS:
- Implement the task fully and correctly
- Make sure your code compiles/runs without errors
- Write clean, well-structured code
- When you are COMPLETELY DONE, run this command to capture your diff:
git diff HEAD
- Include the FULL diff output as the LAST thing in your response, inside a fenced code block with the label "diff". This diff is critical — it's how your solution gets shared with other agents.
Before the diff, include a SUMMARY section with exactly this format:
SUMMARY:
- {bullet 1}
- {bullet 2}
- ... (max 5 bullets)
Each bullet should be one concise sentence describing a key decision or approach you took.#### Codex CLI Agents (only when codex_available = true)
For each Codex agent, you must first create a worktree manually, then run the Codex CLI inside it. Spawn these Bash commands in the same single message as the Claude Code agents above so everything runs in parallel.
For each Codex agent (numbered N_claude+1 through N_total), use the Bash tool with run_in_background: true:
# Create a worktree for this Codex agent
WORKTREE_PATH="$(git rev-parse --show-toplevel)/.worktrees/codex-agent-{i}"
git worktree add "$WORKTREE_PATH" HEAD --detach
# Run Codex CLI non-interactively in the worktree with full-auto mode
cd "$WORKTREE_PATH" && codex exec --full-auto -o /tmp/codex-agent-{i}-output.txt "{task_description}"
# Capture the diff
cd "$WORKTREE_PATH" && git diff HEADNotes on Codex CLI flags:
codex exec runs non-interactively (no TUI)--full-auto enables on-request approvals + workspace-write sandbox (low-friction preset)-o /tmp/codex-agent-{i}-output.txt writes the final assistant message to a file for easy parsingImportant: The diff comes from the git diff HEAD output at the end. The Codex agent's reasoning is in the -o output file. Codex agents do not produce a SUMMARY section — you should generate a brief summary by reading their diff.
After all agents complete, extract the diff and SUMMARY from each agent's response.
For Claude Code agents: The agent ID is returned automatically when each Agent tool call completes (e.g., agentId: a63a526a86822148a). You MUST save these IDs — they are required to continue agents in improvement rounds via SendMessage.
For Codex CLI agents: Parse the diff from the Bash output. Save the worktree path — it's needed for improvement rounds. Generate a brief summary by reading their diff since Codex agents don't produce a SUMMARY section.
Store for each agent:
Display each agent's summary to the user. Output a status update like:
### Phase 1 Complete — Initial Implementations
**Agent 1:**
- {bullet 1}
- {bullet 2}
- ...
**Agent 2:**
- {bullet 1}
- {bullet 2}
- ...
**Agent 3:**
- {bullet 1}
- {bullet 2}
- ...This is important because the user cannot see subagent output directly — they rely on the orchestrator to surface it.
If an agent failed to produce a diff or errored out, exclude it from subsequent rounds. If fewer than 2 agents remain, abort and report to the user.
For each improvement round (default: 1 round), send all agents the other agents' diffs. Send all messages in a single message so they run in parallel.
#### Claude Code agents — use SendMessage
Continue each Claude Code agent using SendMessage with the agent ID captured in Step 2:
to: "{agent_id_i}" # The agent ID returned from Step 1 (e.g., "a63a526a86822148a")
message: |
IMPROVEMENT ROUND {round}
Here are the other agents' solutions from last round. Study them carefully.
{for each other agent j:}
--- Agent {j}'s diff ---{agent_j_diff}
{end for}
INSTRUCTIONS:
1. Carefully study every other agent's diff. For each one, consider:
- What did they do better than you?
- What did they do worse?
- Are there clever approaches or edge cases they handled that you missed?
- Are there bugs or issues in their code?
2. Now improve YOUR solution by incorporating the best ideas while fixing any issues
3. You already have your changes in the worktree — modify your code to improve it
4. Cherry-pick good ideas freely, but maintain coherence
5. When COMPLETELY DONE, run: git diff HEAD
6. Include the FULL diff output as the LAST thing in your response, inside a fenced code block with the label "diff"
Before the diff, include these two sections in exactly this format:
IDEAS ADOPTED:
- From Agent {j}: {what you took and why} (one line per idea, max 5)
SUMMARY:
- {bullet 1}
- {bullet 2}
- ... (max 5 bullets describing your key changes this round)#### Codex CLI agents — use Bash
For each Codex agent, construct a prompt that includes the other agents' diffs and run Codex CLI again in the same worktree. Use the Bash tool with run_in_background: true:
cd "{worktree_path_i}" && codex exec --full-auto -o /tmp/codex-agent-{i}-round-{round}.txt "IMPROVEMENT ROUND {round}
Here are other agents' solutions. Study them and improve your solution by incorporating the best ideas.
{for each other agent j:}
--- Agent {j}'s diff ---
{agent_j_diff}
{end for}
Carefully study every other agent's diff. Consider what they did better, what they did worse, and any clever approaches or edge cases they handled that you missed. Improve your solution by incorporating the best ideas while fixing any issues. Cherry-pick good ideas freely, but maintain coherence."
# Capture the updated diff
cd "{worktree_path_i}" && git diff HEADImportant: Codex agents don't produce IDEAS ADOPTED or SUMMARY sections. Generate these by comparing their new diff against their previous diff.
After each round, collect the new diffs and display each agent's IDEAS ADOPTED and SUMMARY to the user:
### Improvement Round {round} Complete
**Agent 1:**
Ideas adopted:
- From Agent 2: {what they took}
- ...
Summary:
- {bullet 1}
- ...
**Agent 2:**
Ideas adopted:
- From Agent 1: {what they took}
- ...
Summary:
- {bullet 1}
- ...
(repeat for all agents)This keeps the user informed of how solutions are evolving across rounds.
After all improvement rounds, spawn 3 fresh judge agents in parallel. These judges have no connection to any solution — they evaluate purely on merit. Each judge ranks ALL solutions from best to worst.
Spawn all 3 judges in a single message:
description: "Horse race judge {i}"
prompt: |
You are Judge {i}, an independent evaluator in a programming competition. You had no part in writing any of these solutions. Your job is to rank them all from best to worst, purely on merit.
ORIGINAL TASK:
{task_description}
SOLUTIONS TO EVALUATE:
{for each agent j:}
--- Agent {j}'s solution ---{agent_j_diff}
{end for}
EVALUATION CRITERIA:
- Correctness: Does it solve the task fully? Any bugs?
- Code quality: Is it clean, readable, maintainable?
- Edge cases: Does it handle edge cases well?
- Simplicity: Is it appropriately simple without being simplistic?
- Performance: Is it efficient where it matters?
INSTRUCTIONS:
1. For each solution, list what you like and dislike in concise bullet points
2. Think through the tradeoffs between them
3. Rank ALL solutions from best to worst
Respond with EXACTLY this format:
EVALUATION:
Agent {number}:
Likes:
- {concise bullet}
- ...
Dislikes:
- {concise bullet}
- ...
(repeat for each agent)
RANKING:
1. Agent {number} - {one-sentence reason}
2. Agent {number} - {one-sentence reason}
... (continue for all agents)Scoring:
In Borda count, each position in a ranking awards points. With N solutions, each judge ranks all N:
For example, with 3 solutions: 1st = 2 pts, 2nd = 1 pt, 3rd = 0 pts.
Process:
Tiebreak — 4th Independent Judge:
If two or more agents are tied for the highest Borda score, spawn one more fresh judge to break the tie, seeing only the tied solutions:
description: "Horse race tiebreak judge"
prompt: |
You are a tiebreak judge in a programming competition. These solutions are tied and you must pick the winner.
ORIGINAL TASK:
{task_description}
TIED SOLUTIONS:
{for each tied agent j:}
--- Agent {j}'s solution ---{agent_j_diff}
{end for}
CONTEXT — SCORES FROM 3 OTHER JUDGES:
{summary of Borda scores and individual rankings with reasons}
EVALUATION CRITERIA:
- Correctness: Does it solve the task fully? Any bugs?
- Code quality: Is it clean, readable, maintainable?
- Edge cases: Does it handle edge cases well?
- Simplicity: Is it appropriately simple without being simplistic?
- Performance: Is it efficient where it matters?
Carefully analyze each tied solution. Consider the other judges' reasoning but form your own independent judgment.
Respond with EXACTLY:
WINNER: Agent {number}
REASON: {one-sentence justification} cat > /tmp/horse-race-winner.patch << 'PATCH_EOF'
{winning_diff}
PATCH_EOF
git apply /tmp/horse-race-winner.patchgit apply fails, try git apply --3way /tmp/horse-race-winner.patch/tmp/horse-race-winner.patch for manual applicationAgent worktrees with changes are not automatically cleaned up. Remove all worktrees created during the race:
git worktree list --porcelain | grep -E "^worktree .*/\.worktrees/" | sed 's/^worktree //' | while read wt; do
git worktree remove --force "$wt"
doneIf git worktree remove fails for any worktree, fall back to:
git worktree remove --force <path>If that also fails, report the leftover worktree paths to the user so they can clean up manually.
Give the user a concise summary:
/tmp/horse-race-winner.patch, inform user.git worktree remove --force <path>.~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.