model-race
Skill11 starsChanged 3 months agoMITView on GitHub
Race multiple AI models on the same task using cursor-agent-oneoff in isolated git worktrees. Creates worktrees, writes prompt, launches models in parallel, polls progress, merges the winner. General-purpose — works for any coding task, not just Lean proofs.
In this repository18 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- android-app-reverserSkill
- android-emulator-app-live-inspectSkill
- aula-pii-scanSkill
- de-ai-proseSkill
- de-ai-repoSkill
- drawio-figure-reviewerSkill
- explainer-videoSkill
- justfile-hygieneSkill
- nix-scaffoldSkill
- phase1-prd-grillSkill
- phase2-backlog-snowballSkill
- phase3-backlog-ralphSkill
- readme-improverSkill
- refactor-smellerSkill
- scrub-for-publicSkill
- xterm-tmux-controlSkill
- zellij-controlSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Ask the user (or extract from their message):
- Very specific: line 41
Write to tmp/model-race-prompt.txt.
- Distinctive: line 151
If no model produces a verified commit, report all as failed.
- Distinctive: line 170
If cherry-pick conflicts, show the diff and let the user decide.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
/model-race — Multi-Model Race in Git Worktrees
Race 5 AI models on the same task. Each runs in an isolated git worktree. First to succeed wins. Merge the winner.
Step 1: Gather inputs
Ask the user (or extract from their message):
- TASK: What the models should do (plain English description)
- TARGET_FILES: Which files the models may modify
- VERIFY_CMD: Command to check if the task is done (must exit 0 on success)
- ONBOARDING_FILES (optional): Extra files to read for context. Defaults: README.md, CLAUDE.md
- MODELS (optional): Which models to race. Defaults below.
Default models (top 5):
gpt-5.4-xhighclaude-4.6-opus-max-thinkinggpt-5.3-codex-xhighgrok-4-20-thinkinggemini-3.1-pro
Step 2: Set up paths and names
ORIG_REPO=$(pwd)
TASK_SLUG=$(echo "$TASK" | tr ' ' '-' | tr -cd '[:alnum:]-' | head -c 40)
WORKTREE_DIR="${ORIG_REPO}/tmp"
mkdir -p "$WORKTREE_DIR"
echo "tmp/" >> .gitignore 2>/dev/null # Ensure worktrees are gitignoredWorktree naming: tmp/worktree-<task_slug>-<model_name>/
Log naming: tmp/log-<task_slug>-<model_name>.log
Step 3: Write the shared prompt file
Write to tmp/model-race-prompt.txt. Key improvements from lessons learned:
- Tell models their AVAILABLE TOOLS:
read,bash, and file editing. NOgrepToolCall— usebashwithgrepcommand instead. - Give absolute paths for the worktree and original repo.
- Explicit "do not modify original" warning.
You are an AI coding agent working in a git worktree.
YOUR WORKING DIRECTORY: {WORKTREE_PATH} (this is where you should make changes)
ORIGINAL REPOSITORY: {ORIG_REPO} (DO NOT modify anything here)
IMPORTANT TOOL NOTES:
- You have: read (to read files), bash (to run commands), and file editing tools.
- There is NO grep tool. To search files, use bash: grep -n "pattern" ./path/to/file
- There is NO separate edit tool name like "editToolCall". Use your normal file editing capability.
- All file paths should be relative to your working directory (./) or absolute.
ONBOARDING — read these files first to understand the project:
{for each file in ONBOARDING_FILES}
- ./{file}
{end}
YOUR TASK:
{TASK}
FILES YOU MAY MODIFY (and only these):
{for each file in TARGET_FILES}
- ./{file}
{end}
TO VERIFY YOUR WORK:
{VERIFY_CMD}
WORKFLOW:
1. Read the onboarding files
2. Read the target files to understand current state
3. If helpful, search for patterns with: grep -n "pattern" ./file
4. Make your changes using file editing
5. Run the verify command. If it fails, read the error, fix, and retry.
6. When verify passes, commit: git add -A && git commit -m "model-race: {brief description}"
DO NOT push. DO NOT modify files outside the target list. DO NOT touch {ORIG_REPO}.Step 4: Create worktrees and launch models SEQUENTIALLY
IMPORTANT: Launch models ONE AT A TIME, not in parallel. Each model's lake build
can consume 5-15GB RAM. Running 5 in parallel = 50+GB = OOM + swap thrashing.
Strategy: Launch model 1, wait for it to finish or timeout (15 min), then launch model 2, etc. First model to pass verify wins — skip remaining models.
pkill -f cursor-agent-oneoff 2>/dev/null
sleep 1
MODELS=("gpt-5.4-xhigh" "claude-4.6-opus-max-thinking" "gpt-5.3-codex-xhigh" "grok-4-20-thinking" "gemini-3.1-pro")
PROMPT_TEMPLATE=$(cat tmp/model-race-prompt.txt)
WINNER=""
for i in "${!MODELS[@]}"; do
[ -n "$WINNER" ] && break # Skip remaining if we have a winner
MODEL="${MODELS[$i]}"
MODEL_SLUG=$(echo "$MODEL" | tr '.' '-')
WT="${WORKTREE_DIR}/worktree-${TASK_SLUG}-${MODEL_SLUG}"
BRANCH="race-${TASK_SLUG}-${MODEL_SLUG}"
LOG="${WORKTREE_DIR}/log-${TASK_SLUG}-${MODEL_SLUG}.log"
# Create worktree
cd "$ORIG_REPO"
git worktree add "$WT" -b "$BRANCH" HEAD 2>&1 | tail -1
# Customize prompt with this worktree's absolute path
PROMPT=$(echo "$PROMPT_TEMPLATE" | sed "s|{WORKTREE_PATH}|${WT}|g")
# Launch and WAIT (sequential, not parallel)
cd "$WT"
echo "=== Running: $MODEL ==="
timeout 3600 cursor-agent-oneoff --model "$MODEL" -p "$PROMPT" > "$LOG" 2>&1
EXIT=$?
echo " $MODEL finished (exit=$EXIT)"
echo " Log: $LOG"
# Check if it committed and verify passes
HAS_COMMIT=$(cd "$WT" && git log --oneline -1 2>/dev/null | grep -c "model-race")
if [ "$HAS_COMMIT" = "1" ]; then
cd "$WT"
if eval "$VERIFY_CMD" > /dev/null 2>&1; then
echo " *** WINNER: $MODEL ***"
WINNER="$MODEL"
WINNER_WT="$WT"
WINNER_BRANCH="$BRANCH"
else
echo " (committed but verify failed)"
fi
fi
# Kill any lingering lean/lake processes before next model
pkill -f "lean.*${MODEL_SLUG}" 2>/dev/null
sleep 2
doneStep 5: (Sequential mode — no polling needed)
In sequential mode, each model runs to completion (or 15 min timeout) before the next starts. The winner is determined inline in Step 4. No polling loop needed.
If no model produces a verified commit, report all as failed.
Step 6: Inspect winner
cd "$WINNER_WT"
git log --oneline -1
git diff HEAD~1 --stat
# Run verify one more time
eval "$VERIFY_CMD"Step 7: Merge winner into main repo
cd "$ORIG_REPO"
git cherry-pick "$WINNER_BRANCH"If cherry-pick conflicts, show the diff and let the user decide.
Step 8: Kill remaining and clean up
pkill -f cursor-agent-oneoff 2>/dev/null
cd "$ORIG_REPO"
for i in "${!MODELS[@]}"; do
MODEL="${MODELS[$i]}"
MODEL_SLUG=$(echo "$MODEL" | tr '.' '-')
WT="${WORKTREE_DIR}/worktree-${TASK_SLUG}-${MODEL_SLUG}"
BRANCH="race-${TASK_SLUG}-${MODEL_SLUG}"
git worktree remove "$WT" --force 2>/dev/null
git branch -D "$BRANCH" 2>/dev/null
done
# Keep logs for analysis but clean worktrees
echo "Logs preserved in tmp/log-${TASK_SLUG}-*.log"Step 9: Report
| Model | Status | Log lines | Files changed | Committed | Verified | Time |
| ... | WON/FINISHED/RUNNING/CRASHED | N | N | Y/N | Y/N | Nm |
Also note tool failures per model (grep logs for "unknown tool").
Lessons learned (baked into the prompt)
- No
grepToolCall: cursor-agent models try to use a grep tool that doesn't exist. The prompt explicitly says "use bash grep instead." This was the #1 failure mode (74 failures across 5 models in the first race). - No
editToolCall: same issue with edit. The prompt says "use your normal file editing capability." - Absolute paths: models get confused about relative vs absolute. The prompt gives the exact worktree path.
- Original repo protection: models sometimes wander to the original repo. The prompt warns against it.
- Worktrees under repo/tmp/: keeps everything local, gitignored, easy to find.
- Model-named logs:
log-task-gpt-5-4-xhigh.logis more readable thanlog-3.log. - SEQUENTIAL not parallel: Each model's
lake buildcan use 5-15GB RAM. 5 models parallel = 50GB+ = OOM + swap death. Run one at a time with 15min timeout. First winner stops the race. - Kill lean between models: Lean processes linger after cursor-agent exits. Always
pkill -f leanbetween models to free RAM. - Anti-cheating: Models cheat with
validHoare_weaken_trivial_post(trivializes postcondition) or prove against fused bodies (doesn't chain to C). Prompt must explicitly forbid these patterns. Verify after merge.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

