Autonomous goal-directed iteration for Claude Code
Inspired by Karpathy's autoresearch -- generalized to every domain
github.com/uditgoenka/autoresearch
Explain Like I'm Five: the simple version
Imagine you have a robot chef that keeps trying to make your cookie recipe better:
"Make the cookies taste better" -- you give the robot a clear target
A little more sugar, a little less flour -- one thing at a time
Better? Keep it. Worse? Undo it. Then try something new.
That's AutoResearch in a nutshell: Set a goal, let the AI try thousands of tiny improvements, keep the wins, throw away the fails -- all while you sleep.
In March 2026, Andrej Karpathy (famous AI researcher) showed the world something cool:
Karpathy proved the concept works. Udit made it work everywhere.
The secret sauce: constraints enable autonomy. By narrowing what the AI can change and giving it a clear number to optimize, it can safely experiment forever without breaking things.
If you can measure it, AutoResearch can improve it. Tests pass/fail? A score going up? Errors going down? That's enough.
Architecture, protocols, code patterns, and implementation details
autoresearch/ claude-plugin/ commands/ autoresearch.md # core loop autoresearch/ debug.md # 8 subcommands fix.md learn.md plan.md predict.md scenario.md security.md ship.md skills/ autoresearch/ SKILL.md # main skill def references/ autonomous-loop-protocol.md results-logging.md core-principles.md *-workflow.md # 8 workflows guide/ # docs + walkthroughs scripts/ # release tooling
Total code: ~0 lines of traditional code. The "program" is a set of markdown instructions that Claude Code interprets as behavior.
AGENT + CONSTRAINED_SCOPE + SCALAR_METRIC + FAST_VERIFICATION = AUTONOMOUS_IMPROVEMENT
| Field | Purpose |
|---|---|
| Goal | What to optimize |
| Scope | File globs to modify |
| Metric | Number to track |
| Direction | Higher or lower = better |
| Verify | Shell cmd producing metric |
| Guard | (optional) Regression check |
Priority order when choosing next experiment:
The most elegant insight: git history IS the agent's brain. No database, no vector store -- just commits.
# Every change gets committed BEFORE verify git add <specific-files> # never git add -A git commit -m "experiment: add batch norm" # On failure: revert preserves history git revert HEAD # NOT git reset --hard # Reading memory before each iteration git log --oneline -20 git show <commit-hash> --stat
Key rule: "Git IS the memory. After rollbacks, state may differ from what you expect." -- The agent always re-reads before acting.
Every experiment is tracked in autoresearch-results.tsv (gitignored):
# direction: higher iteration commit metric delta guard status description 0 a1b2c3d 72.3 - pass baseline Initial measurement 1 e4f5g6h 74.1 +1.8 pass keep Add caching to hot path 2 - 71.9 -0.4 - discard Inline function calls 3 i7j8k9l 76.5 +2.4 pass keep Batch DB queries 4 - 76.5 +0.0 - discard Add connection pooling 5 - ERR - - crash Async refactor (syntax)
| keep | Metric improved, guard passed |
| discard | Same/worse, reverted |
| crash | Verification failed entirely |
| no-op | No measurable change |
| hook-blocked | Pre-commit hook rejected |
Optional parallel check that prevents regressions:
# Metric improves BUT guard fails? # System tries to rework (max 2 attempts) if metric_improved && guard_failed: # Attempt 1: modify implementation # (NEVER modify tests/guard) rework_change() if guard_still_fails: # Attempt 2: different approach rework_change() if guard_still_fails: git_revert() # discard entirely
For volatile metrics (benchmarks, Lighthouse):
After 5 consecutive discards, the agent enters recovery mode with an escalating strategy:
Fresh read of all in-scope files, review the goal, analyze result log patterns
Merge successful prior changes from history that may compound together
Invert assumptions -- if adding complexity failed, try simplifying
Attempt fundamentally different approaches -- structural redesign
Unbounded mode rule: "NEVER STOP. NEVER ASK IF YOU SHOULD CONTINUE." -- the loop only ends via user interrupt or iteration limit.
| Command | Purpose | Key Feature |
|---|---|---|
| /autoresearch | Core autonomous loop | Unbounded or N iterations |
| :plan | Goal-to-config wizard | 7 interactive gates with validation |
| :security | STRIDE + OWASP audit | Red-team personas, code evidence |
| :ship | Universal shipping | 8-phase deploy for any deliverable |
| :debug | Scientific bug-hunting | 7 investigation techniques |
| :fix | Error repair loop | Loops until 0 errors remain |
| :scenario | Edge-case exploration | 12 dimensions of scenario analysis |
| :predict | Multi-persona analysis | 5 experts debate with anti-herd safeguards |
| :learn | Documentation engine | Scout, generate, validate-fix cycle |
Commands are chainable: --chain debug,fix,ship lets predict hand off findings to debug, then fix, then ship.
Comprehensive autonomous security audit using industry frameworks:
score = (owasp_tested/10) * 50 + (stride_tested/6) * 30 + min(findings, 20)
security/YYMMDD-HHMM-slug/
overview.md
threat-model.md
attack-surface-map.md
findings.md
owasp-coverage.md
dependency-audit.md
recommendations.md
security-audit-results.tsv
--diff delta mode | --fix auto-fix critical | --fail-on CI gate
Multi-persona swarm analysis: independent experts debate and reach consensus.
Anti-herd mechanism: mandatory dissent + flip-rate monitoring + entropy detection prevent groupthink.
With --adversarial flag:
# Predict finds issues, debug hunts them, # fix resolves them /autoresearch:predict \ --chain debug,fix \ --depth deep
8-phase universal shipping workflow:
Supports: code PRs, releases, deployments, content, marketing emails, campaigns, sales, research, design
ship_score = (passing/total)*80 + (dry_run_passed? 15:0) + (no_blockers? 5:0) # Score 100 = ready; <80 = not shippable
7 investigation techniques:
Iterative repair loop that auto-detects broken states (tests, types, lint, builds). Loops until zero errors remain. Prioritizes blockers first.
Explores edge cases across 12 dimensions:
metric = scenarios*10 + edge_cases*15 + (dimensions/12)*30 + unique_actors*5
Flags: --domain --depth --focus --format
Autonomous documentation engine with 4 modes:
| init | Generate all docs from scratch |
| update | Refresh for code changes |
| check | Read-only health assessment |
| summarize | Quick inventory + summary |
Lifecycle: Scout → Analyze → Map → Generate → Validate → Fix (max 3 retries) → Finalize → Log
Fully dynamic: no hardcoded doc list. Scans for existing docs, detects project type, only generates relevant files (e.g., deploy guide only if deploy config exists).
/autoresearch:plan converts a plain-language goal into a validated, executable config through 7 mechanical gates:
# User types: /autoresearch:plan Goal: Reduce bundle size below 200KB # Wizard auto-detects: Stack: React + Webpack Scope: src/**/*.{ts,tsx} Metric: Bundle size (KB) Direction: lower Verify: npm run build && stat dist/ Guard: npm test
Both implement the same core equation. The divergence is depth vs. breadth:
| Dimension | Karpathy | Claude AutoResearch |
|---|---|---|
| Scope | Single file (train.py, 630 LOC) | Any file pattern via glob |
| Domain | ML training only | Code, content, security, marketing... |
| Commands | 1 (run the script) | 9 specialized subcommands |
| Hardware | NVIDIA GPU + CUDA required | No special hardware |
| Metrics | val_bpb (fixed) | User-defined, unlimited |
| Setup | Manual program.md editing | Interactive 7-step wizard |
| Rollback | Destructive (git reset) | Preserves history (git revert) |
| Safety | None | Guard cmds, crash recovery, rework |
| Speed | ~12 experiments/hour (5 min train) | Up to ~360/hour (fast verifiers) |
| Stars | 26,000 (1 week) | 1,700 (9 days) |
The same loop pattern, configured differently for each domain:
| Domain | Scope | Metric | Verify Command |
|---|---|---|---|
| Backend | src/**/*.ts | Test coverage % | npm test |
| Frontend | src/components/** | Lighthouse score | npx lighthouse |
| ML Training | train.py | val_loss / bpb | uv run train.py |
| Performance | Target files | Benchmark (ms) | npm run bench |
| Content/SEO | content/*.md | Readability score | Custom script |
| Security | API/auth/middleware | OWASP + STRIDE + findings | :security |
| Refactoring | Module | Tests + LOC reduced | npm test && wc -l |
| Documentation | docs/*.md | Validation % | :learn |
The insight: any domain with a constrained scope and a mechanical metric can be autonomously improved. The framework is the same; only the config changes.
# Option 1: Plugin marketplace /plugin marketplace add uditgoenka/autoresearch /plugin install autoresearch@autoresearch # Option 2: Manual git clone github.com/uditgoenka/autoresearch cp -r claude-plugin/* .claude/
# Improve test coverage overnight /autoresearch Goal: Increase test coverage to 90% Scope: src/**/*.ts Verify: npm test -- --coverage # Security audit with auto-fix /autoresearch:security --diff --fix Iterations: 15 # Debug a flaky endpoint /autoresearch:debug Issue: API returns 500 intermittently Scope: src/api/**
The repo includes 10 detailed guides in guide/scenario/:
CI/CD integration: GitHub Actions and GitLab CI templates are included. Use --fail-on critical as a pipeline gate.
github.com/uditgoenka/autoresearch · MIT License · v1.8.2