Scaffold and run Karpathy-style autoresearch loops in any git repo. This skill should be used when setting up autonomous code improvement, generating adversarial eval harnesses, running hypothesis-implement-eval-keep/discard loops, or checking autoresearch progress. Triggers on "autoresearch", "autonomous improvement", "eval loop", "hypothesis loop", "self-improvement loop".
Scaffold and run Karpathy-style autoresearch loops in any git repo. This skill should be used when setting up autonomous code improvement, generating adversarial eval harnesses, running hypothesis-implement-eval-keep/discard loops, or checking autoresearch progress. Triggers on "autoresearch", "autonomous improvement", "eval loop", "hypothesis loop", "self-improvement loop".
argument-hint
["init|eval-gen|run|status|resume"]
Five Invariants (never violate)
Single mutable surface — one hypothesis per iteration, one change per experiment
Fixed eval budget — eval runs in bounded time, no network calls in gates
One scalar metric — composite score drives keep/discard, not vibes
Git-as-memory — every experiment is a commit, discards are reverts, history is the log
Safety rules
Never modify .lab/ contents during hypothesis implementation
Never skip eval — every commit must be evaluated before keep/discard
Always revert on crash — atexit handler restores git state
Runner uses subscription auth (claude -p with ANTHROPIC_API_KEY stripped)
Autoresearch
Scaffold and run autonomous code improvement loops in any git repo. The pattern: generate a hypothesis via claude -p, implement it, run programmatic eval gates, keep if the composite score improves, discard if it doesn't. Proven across 50+ iterations on two codebases (shadow-engine: 0.69 to 1.0, perplexity-clone: search quality optimization).
Category
Runbooks — mechanical process with clear steps, not cognitive reasoning.
Quick Start
/autoresearch init # scaffold .lab/ in your repo
/autoresearch run # start the loop (default: 50 iterations)
/autoresearch status # check progress
/autoresearch resume # recover interrupted run
Why .lab/ not autoresearch/: Code state (git) and experiment knowledge (.lab/) are fully decoupled. git reset --hard HEAD~1 (the core discard mechanic) never touches .lab/. Results survive branch operations.
Three-Tier Output Protocol
Eval gates emit structured diagnostics to stderr:
GATE build=PASS # Binary — blocks iteration on FAIL
METRIC test_count=475 # Continuous — tracked in results.tsv
TRACE gate_duration_ms=3200 # Execution data — for debugging only
Scripts Reference
Script
Purpose
Run from
scripts/detect_stack.py
Detect language, build system, test runner
Skill dir
scripts/scaffold.py
Create .lab/ with all files
Skill dir
scripts/eval_gen.py
Generate adversarial eval gates
Skill dir
scripts/report.py
Render status report
Skill dir
scripts/runner_template.py
Template copied to .lab/runner.py
Skill dir
assets/eval_base.py
Base eval framework copied to .lab/
Skill dir
assets/config.json.tmpl
Config template with documented fields
Skill dir
assets/program.md.tmpl
Program.md template
Skill dir
All scripts run with python3 (no special dependencies). Use uv run if preferred.
Gotchas
ANTHROPIC_API_KEY in environment: The runner strips it so claude -p uses subscription auth (not pay-per-use API). If you want API auth, set use_api_key: true in config.json.
Gate stochasticity: If gates produce different scores on the same code, the runner will thrash between keep/discard. All gates must be deterministic.
Large dt on resume: If the machine suspends during a run, the runner handles it gracefully via atexit + lock file cleanup.
Eval crashes vs gate crashes: An eval crash (eval.py itself fails) aborts the iteration. A gate crash (one gate throws) is logged in crashed_gates and excluded from composite.
Post-Run Checklist
After every autoresearch run:
tail -f .lab/results.tsv — review keeps/discards
Read .lab/eval-report.md for cumulative progress and ceiling detection
Merge the autoresearch branch to main if satisfied
Update .lab/program.md dead ends with falsified approaches
Run python3 .lab/eval.py to confirm final composite
Never
Never modify .lab/eval_base.py or .lab/runner.py during a run
Never run two runners concurrently (lock file prevents this, but don't bypass)
Never commit .lab/ to git (it's gitignored for a reason)
Never trust a composite that includes crashed gates