| name | autoresearch |
| description | Autonomous Goal-directed Iteration. Apply Karpathy's autoresearch principles to ANY task. Loops autonomously โ modify, verify, keep/discard, repeat. Supports optional loop count via Claude Code's /loop command. Invoking /autoresearch <free-form goal> builds a real-data benchmark harness, captures a baseline, and iterates with a regression gate until the goal is hit. |
| version | 1.0.4 |
Claude Autoresearch โ Autonomous Goal-directed Iteration
Inspired by Karpathy's autoresearch. Applies constraint-driven autonomous iteration to ANY work โ not just ML research.
Core idea: You are an autonomous agent. Modify โ Verify โ Keep/Discard โ Repeat.
Subcommands
| Subcommand | Purpose |
|---|
/autoresearch <goal> | Default path โ parse free-form goal, build harness, capture baseline, loop until goal met |
/autoresearch | Run the autonomous loop (default) |
/autoresearch:plan | Interactive wizard to build Scope, Metric, Direction & Verify from a Goal |
/autoresearch:security | Autonomous security audit: STRIDE threat model + OWASP Top 10 + red-team (4 adversarial personas) |
Default Path: /autoresearch
When the user invokes /autoresearch <goal> with any free-form string after the command, parse the goal into seven slots, print the parsed-slot dump back for user visibility, then run the harness protocol in references/benchmark-harness.md before entering the loop.
Goal-parsing rubric:
| Slot | Extraction rule | Fallback |
|---|
| metric | First measurable noun (latency, reliability, coverage, flakiness, bundle size, p95, accuracy, error-rate, LOC, build time) | Ask user (1 sentence) |
| direction | reduce/lower/below/under/minimise/to 0% + cost-word โ minimise; increase/raise/above/over/maximise/to 100% + quality-word โ maximise | minimise for cost/time/size/error, maximise for coverage/score/throughput |
| target | Number + unit in goal (500ms, 95%, 0%, <200KB) | "best achievable" โ unbounded loop |
| scope | Grep repo for goal's domain terms (API, test, build); propose globs | Whole repo minus node_modules, .venv, dist, target |
| corpus_source | If goal names inputs (signals, queries, PRs, logs) โ find source; if absent โ ASK, never fabricate | corpus_required=false only when metric is purely structural (LOC, build time, bundle size) |
| verify_cmd | Single shell command that prints metric: <float> on stdout โ typically python benchmark.py or equivalent single-file rig | Constructed during harness build |
| regression_cmd | Auto-detect: first of pytest -q, npm test, cargo test, go test ./... whose config exists | Ask user |
Worked examples:
/autoresearch reduce API p95 latency to 200ms
โ metric=p95_latency_ms, direction=minimise, target=200, scope=src/api/**,
corpus_source=prod log tail or fixtures, verify_cmd=python benchmark.py,
regression_cmd=pytest -q
/autoresearch reduce test flakiness to 0%
โ metric=flaky_test_rate, direction=minimise, target=0, scope=tests/**,
corpus_source=CI run history, verify_cmd=python benchmark.py (N reruns),
regression_cmd=pytest -q
/autoresearch increase signal-parser reliability to 99%
โ metric=reliability, direction=maximise, target=0.99, scope=src/parser/**,
corpus_source=autoresearch/data/signals.jsonl, verify_cmd=python benchmark.py,
regression_cmd=pytest -q
Print the parsed slot dump to the user before any action โ this is the single confirmation checkpoint before the harness protocol begins.
/autoresearch:security โ Autonomous Security Audit (v1.0.3)
Runs a comprehensive security audit using the autoresearch loop pattern. Generates a full STRIDE threat model, maps attack surfaces, then iteratively tests each vulnerability vector โ logging findings with severity, OWASP category, and code evidence.
Load: references/security-workflow.md for full protocol.
What it does:
- Codebase Reconnaissance โ scans tech stack, dependencies, configs, API routes
- Asset Identification โ catalogs data stores, auth systems, external services, user inputs
- Trust Boundary Mapping โ browserโserver, publicโauthenticated, userโadmin, CI/CDโprod
- STRIDE Threat Model โ Spoofing, Tampering, Repudiation, Info Disclosure, DoS, Elevation of Privilege
- Attack Surface Map โ entry points, data flows, abuse paths
- Autonomous Loop โ iteratively tests each vector, validates with code evidence, logs findings
- Final Report โ severity-ranked findings with mitigations, coverage matrix, iteration log
Key behaviors:
- Follows red-team adversarial mindset (Security Adversary, Supply Chain, Insider Threat, Infra Attacker)
- Every finding requires code evidence (file:line + attack scenario) โ no theoretical fluff
- Tracks OWASP Top 10 + STRIDE coverage, prints coverage summary every 5 iterations
- Composite metric:
(owasp_tested/10)*50 + (stride_tested/6)*30 + min(findings, 20) โ higher is better
- Creates
security/{YYMMDD}-{HHMM}-{audit-slug}/ folder with structured reports:
overview.md, threat-model.md, attack-surface-map.md, findings.md, owasp-coverage.md, dependency-audit.md, recommendations.md, security-audit-results.tsv
Flags:
| Flag | Purpose |
|---|
--diff | Delta mode โ only audit files changed since last audit |
--fix | After audit, auto-fix confirmed Critical/High findings using autoresearch loop |
--fail-on {severity} | Exit non-zero if findings meet threshold (for CI/CD gating) |
Usage:
# Unlimited โ keep finding vulnerabilities until interrupted
/autoresearch:security
# Bounded โ exactly 10 security sweep iterations
/loop 10 /autoresearch:security
# With focused scope
/autoresearch:security
Scope: src/api/**/*.ts, src/middleware/**/*.ts
Focus: authentication and authorization flows
# Delta mode โ only audit changed files since last audit
/autoresearch:security --diff
# Auto-fix confirmed Critical/High findings after audit
/loop 15 /autoresearch:security --fix
# CI/CD gate โ fail pipeline if any Critical findings
/loop 10 /autoresearch:security --fail-on critical
# Combined โ delta audit + fix + gate
/loop 15 /autoresearch:security --diff --fix --fail-on critical
Inspired by:
- Strix โ AI-powered security testing with proof-of-concept validation
/plan red-team โ adversarial review with hostile reviewer personas
- OWASP Top 10 (2021) โ industry-standard vulnerability taxonomy
- STRIDE โ Microsoft's threat modeling framework
/autoresearch:plan โ Goal โ Configuration Wizard
Converts a plain-language goal into a validated, ready-to-execute autoresearch configuration.
Load: references/plan-workflow.md for full protocol.
Quick summary:
- Capture Goal โ ask what the user wants to improve (or accept inline text)
- Analyze Context โ scan codebase for tooling, test runners, build scripts
- Define Scope โ suggest file globs, validate they resolve to real files
- Define Metric โ suggest mechanical metrics, validate they output a number
- Define Direction โ higher or lower is better
- Define Verify โ construct the shell command, dry-run it, confirm it works
- Confirm & Launch โ present the complete config, offer to launch immediately
Critical gates:
- Metric MUST be mechanical (outputs a parseable number, not subjective)
- Verify command MUST pass a dry run on the current codebase before accepting
- Scope MUST resolve to โฅ1 file
Usage:
/autoresearch:plan
Goal: Make the API respond faster
/autoresearch:plan Increase test coverage to 95%
/autoresearch:plan Reduce bundle size below 200KB
After the wizard completes, the user gets a ready-to-paste /autoresearch invocation โ or can launch it directly.
When to Activate
- User invokes
/autoresearch <goal-string> (anything after the command) โ parse with Default Path rubric, then build harness per references/benchmark-harness.md
- User types
/autoresearch with no argument โ ask for a one-sentence goal OR suggest /autoresearch:plan
- User invokes
/autoresearch or /ug:autoresearch โ run the loop
- User invokes
/autoresearch:plan โ run the planning wizard
- User invokes
/autoresearch:security โ run the security audit
- User says "help me set up autoresearch", "plan an autoresearch run" โ run the planning wizard
- User says "security audit", "threat model", "OWASP", "STRIDE", "find vulnerabilities", "red-team" โ run the security audit
- User says "work autonomously", "iterate until done", "keep improving", "run overnight" โ run the loop
- Any task requiring repeated iteration cycles with measurable outcomes โ run the loop
Optional: Controlled Loop Count
By default, autoresearch loops forever until manually interrupted. However, users can optionally specify a loop count to limit iterations using Claude Code's built-in /loop command.
Requires: Claude Code v1.0.32+ (the /loop command was introduced in this version)
Usage
Unlimited (default):
/autoresearch
Goal: Increase test coverage to 90%
Bounded (N iterations):
/loop 25 /autoresearch
Goal: Increase test coverage to 90%
This chains /autoresearch with /loop 25, running exactly 25 iteration cycles. After 25 iterations, Claude stops and prints a final summary.
When to Use Bounded Loops
| Scenario | Recommendation |
|---|
| Run overnight, review in morning | Unlimited (default) |
| Quick 30-min improvement session | /loop 10 /autoresearch |
| Targeted fix with known scope | /loop 5 /autoresearch |
| Exploratory โ see if approach works | /loop 15 /autoresearch |
| CI/CD pipeline integration | /loop N /autoresearch (set N based on time budget) |
Behavior with Loop Count
When a loop count is specified:
- Claude runs exactly N iterations through the autoresearch loop
- After iteration N, Claude prints a final summary with baseline โ current best, keeps/discards/crashes
- If the goal is achieved before N iterations, Claude prints early completion and stops
- All other rules (atomic changes, mechanical verification, auto-rollback) still apply
Setup Phase (Do Once)
- Parse the goal using the Default Path rubric โ print slot dump
- Read all in-scope files for full context before any modification
- Ingest corpus per
references/benchmark-harness.md Phase A โ refuse if synthetic or empty
- Build single-file harness per Phase B โ must print
metric: <float> on stdout
- Capture baseline per Phase C โ record as iteration #0 in
autoresearch/results.tsv
- Establish regression gate per Phase D โ detect existing test suite, record pass count in
autoresearch/.regression-baseline
- Read hot path per Phase E โ list candidate ideas (never apply more than one per iteration)
- Confirm and go โ show setup summary, BEGIN THE LOOP
The Loop
Read references/autonomous-loop-protocol.md for full protocol details.
LOOP (FOREVER or N times):
1. Review: Read current state + git history + results log
2. Ideate: Pick next change based on goal, past results, what hasn't been tried
3. Modify: Make ONE focused change to in-scope files
4. Commit: Git commit the change (before verification)
5. Verify: Run the mechanical metric (tests, build, benchmark, etc.)
5a. Regress: Run regression_cmd. If passed < N_pre โ STATUS=discard (skip Decide).
6. Decide:
- IMPROVED โ Keep commit, log "keep", advance
- SAME/WORSE โ Git revert, log "discard"
- CRASHED โ Try to fix (max 3 attempts), else log "crash" and move on
7. Log: Record result in results log
8. Repeat: Go to step 1.
- If unbounded: NEVER STOP. NEVER ASK "should I continue?"
- If bounded (N): Stop after N iterations, print final summary
Critical Rules
- Loop until done โ Unbounded: loop until interrupted. Bounded: loop N times then summarize.
- Read before write โ Always understand full context before modifying
- One change per iteration โ Atomic changes. If it breaks, you know exactly why
- Mechanical verification only โ No subjective "looks good". Use metrics
- Automatic rollback โ Failed changes revert instantly. No debates
- Simplicity wins โ Equal results + less code = KEEP. Tiny improvement + ugly complexity = DISCARD
- Git is memory โ Every kept change committed. Agent reads history to learn patterns
- When stuck, think harder โ Re-read files, re-read goal, combine near-misses, try radical changes. Don't ask for help unless truly blocked by missing access/permissions
- Real data only โ corpus must be scraped/exported from reality; synthetic cases forbidden
- Regression gate is absolute โ any drop in pre-existing passing tests triggers auto-discard
- Harness is read-only during iteration โ only source files change; harness edits need a separate commit prefixed
harness:
Principles Reference
See references/core-principles.md for the 7 generalizable principles from autoresearch.
Adapting to Different Domains
| Domain | Metric | Scope | Verify Command | Corpus Source |
|---|
| Backend code | Tests pass + coverage % | src/**/*.ts | npm test | test fixtures |
| Frontend UI | Lighthouse score | src/components/** | npx lighthouse | staging URLs |
| ML training | val_bpb / loss | train.py | uv run train.py | training dataset |
| Blog/content | Word count + readability | content/*.md | Custom script | source manuscripts |
| Performance | Benchmark time (ms) | Target files | npm run bench | benchmark inputs |
| Refactoring | Tests pass + LOC reduced | Target module | npm test && wc -l | existing test suite |
| Security | OWASP + STRIDE coverage + findings | API/auth/middleware | /autoresearch:security | codebase |
| Real-traffic performance | p95 latency (ms) | hot-path files | python benchmark.py | prod log tail / export |
Adapt the loop to your domain. The PRINCIPLES are universal; the METRICS are domain-specific.