/ai-methodology:autoresearch [--scaffold <loop-name>] [--run <loop-name>] [--status]from ai-methodology
Scans codebase quality metrics, scaffolds experiment files, and runs autonomous agent-driven improvement loops that measure, propose changes, and revert if metrics don't improve.
Ships in ai-methodology. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Scan codebase quality metrics, propose improvement loops, and run autonomous agent iterations. Inspired by karpathy/autoresearch, adapted from ML research to code quality.
Concept: The agent proposes a code change, runs the measurement, keeps the change if the metric improved, reverts it if the metric did not improve or the check.sh gate failed, and repeats until manually stopped.
The loop has no built-in end: set an iteration cap in program.md or stop it yourself.
Measure current state, detect existing loops, propose next actions.
Run the following metrics and display a prioritized proposal table.
Step 1: Measure codebase metrics
Adapt grep patterns to your project's conventions. These are TypeScript defaults, adjust for your stack.
# M1: Function declarations (prefer arrow functions)
M1=$(grep -r "export function " src/ --include="*.ts" --include="*.tsx" -l 2>/dev/null | wc -l | tr -d ' ')
# M2: Interface declarations (prefer type aliases)
M2=$(grep -r "export interface " src/ --include="*.ts" --include="*.tsx" -l 2>/dev/null | wc -l | tr -d ' ')
# M3: ESLint disables
M3=$(grep -r "eslint-disable" src/ --include="*.ts" --include="*.tsx" -l 2>/dev/null | wc -l | tr -d ' ')
# M4: Type casts to any
M4=$(grep -r " as any" src/ --include="*.ts" --include="*.tsx" -l 2>/dev/null | wc -l | tr -d ' ')
# M5: TODO comments
M5=$(grep -r "// TODO" src/ --include="*.ts" --include="*.tsx" -l 2>/dev/null | wc -l | tr -d ' ')
Step 2: Detect existing loops
for dir in scripts/autoresearch/loop-*/; do
[ -d "$dir" ] || continue
LOOP_NAME=$(basename "$dir")
# Check if loop has results
if [[ -f "$dir/results.tsv" ]]; then
ITERS=$(wc -l < "$dir/results.tsv" | tr -d ' ')
BEST=$(sort -t$'\t' -k2 -n "$dir/results.tsv" | head -1 | cut -f2)
echo "ACTIVE:$LOOP_NAME:iterations=$ITERS:best=$BEST"
else
echo "SCAFFOLDED:$LOOP_NAME"
fi
done
Step 3: Display
Autoresearch Scan: {date}
Codebase metrics:
| # | Loop | Metric | Current | Target | Priority | Risk |
|---|-------------------|-------------------|---------|--------|----------|------|
| A | loop-remove-as-any| `as any` casts | {M4} | 0 | P1 | LOW |
| B | loop-eslint-disable| eslint-disable | {M3} | 0 | P2 | MED |
| C | loop-export-fn | export function | {M1} | 0 | P1 | LOW |
| D | loop-interface-type| export interface | {M2} | 0 | P1 | LOW |
| E | loop-todo-comments| TODO comments | {M5} | 0 | P3 | LOW |
Existing loops: {detected loops or "none yet"}
Recommended next step (P1, LOW risk):
/autoresearch --scaffold loop-remove-as-any
Then write program.md, create a worktree, and run the loop.
--scaffold <loop-name>Generate the 4 mechanical files for a loop. Does not generate program.md: write that yourself to encode project-specific constraints.
Create the following files under scripts/autoresearch/{loop-name}/:
measure.sh: the evaluation harness (single metric, returns an integer):
#!/usr/bin/env bash
# measure.sh: {loop-name}
# Returns an integer. Direction: lower = better (unless loop targets coverage/score).
set -euo pipefail
# A missing scope must fail: BSD grep with --include can report it as "no match"
[ -d src/ ] || { echo "ERROR: src/ not found" >&2; exit 2; }
# grep exits 1 on zero matches (the target, not an error); 2 or more is a real failure
{ grep -r "PATTERN" src/ --include="*.ts" --include="*.tsx" || [ $? -eq 1 ]; } | wc -l | tr -d ' '
check.sh: the gate. It must exit 0 before any KEEP, because a lower grep count does not show that the code still works. Replace with your project's type check and test commands:
#!/usr/bin/env bash
# check.sh: {loop-name}
set -euo pipefail
npx tsc --noEmit
npm test
direction.txt: improvement direction:
lower
(Use higher for metrics like test coverage or quality score.)
files.txt: scope the agent should operate on:
src/
After creating the files, display:
Loop scaffolded: scripts/autoresearch/{loop-name}/
measure.sh : {pattern} in {scope} -> {N} occurrences today
check.sh : type check + tests (must pass before any KEEP)
direction : lower (fewer = better)
files.txt : src/
Current metric: {N} (target: 0)
Next steps:
1. Write program.md -- agent behavior, constraints, what it can/cannot touch
Reference: scripts/autoresearch/loop-remove-as-any/program.md
2. Review and commit scripts/autoresearch/{loop-name}/, including program.md
(a new worktree does not contain untracked files)
3. Create a worktree: /worktree feature/autoresearch-{loop-name}
4. cd into the worktree
5. /autoresearch --run {loop-name}
--run <loop-name>Execute the autonomous loop. The agent runs indefinitely: stop it manually when satisfied.
Verify prerequisites. If any line fails, stop and report it. Do not clean, stash or commit anything to make it pass.
LOOP_DIR="scripts/autoresearch/{loop-name}"
[ -f "$LOOP_DIR/measure.sh" ] || { echo "ERROR: measure.sh missing. Run --scaffold first."; exit 1; }
[ -f "$LOOP_DIR/program.md" ] || { echo "ERROR: program.md missing. Write it first, this encodes your constraints."; exit 1; }
[ -f "$LOOP_DIR/check.sh" ] || { echo "ERROR: check.sh missing. Run --scaffold first."; exit 1; }
[ -s "$LOOP_DIR/files.txt" ] || { echo "ERROR: files.txt missing or empty."; exit 1; }
# The loop reverts files: it only runs in a linked worktree with a clean scope
[ "$(git rev-parse --git-dir)" != "$(git rev-parse --git-common-dir)" ] || { echo "ERROR: not in a linked worktree."; exit 1; }
SCOPE_STATUS=$(xargs git status --porcelain -- < "$LOOP_DIR/files.txt") || exit 1
[ -z "$SCOPE_STATUS" ] || { echo "ERROR: uncommitted changes in scope:"; echo "$SCOPE_STATUS"; exit 1; }
# Baseline: the gate must pass before the first change
bash "$LOOP_DIR/check.sh" || { echo "ERROR: check.sh fails before any change."; exit 1; }
Run the loop:
Read scripts/autoresearch/{loop-name}/program.md fully before starting. Then enter the following cycle, repeat until stopped:
LOOP ITERATION #{N}
1. Current metric: bash scripts/autoresearch/{loop-name}/measure.sh
2. Read program.md constraints
3. Propose ONE targeted change to files in files.txt
4. Apply the change
5. Re-measure: bash scripts/autoresearch/{loop-name}/measure.sh
6. Evaluate. "Improved" means new < previous (direction=lower) or new > previous (direction=higher). Then run bash scripts/autoresearch/{loop-name}/check.sh
- improved AND check.sh exits 0 -> KEEP (git add the files in scope, then git commit -m "autoresearch: {description}")
- otherwise -> REVERT (git checkout --pathspec-from-file=scripts/autoresearch/{loop-name}/files.txt, then remove only the new files this change created)
7. Log to results.tsv: {timestamp}\t{metric}\t{status}\t{description}
8. Continue to iteration #{N+1}
Never edit measure.sh, check.sh or files.txt during the loop. If measure.sh exits non-zero, or the change touched a file outside the scope, stop and report.
Stopping criteria (from program.md):
Display each iteration:
[iter #{N}] metric: {before} -> {after} | {KEPT/REVERTED} | {change description}
--statusShow status of all loops in the project.
for dir in scripts/autoresearch/loop-*/; do
[ -d "$dir" ] || continue
NAME=$(basename "$dir")
CURRENT=$(bash "$dir/measure.sh" 2>/dev/null || echo "?")
ITERS=$([ -f "$dir/results.tsv" ] && wc -l < "$dir/results.tsv" | tr -d ' ' || echo "0")
KEPT=$([ -f "$dir/results.tsv" ] && { grep -c "KEPT" "$dir/results.tsv" || true; } || echo "0")
echo "$NAME | current: $CURRENT | iters: $ITERS | kept: $KEPT"
done
Display:
Autoresearch Status
| Loop | Current | Iterations | Kept | Status |
|---------------------|---------|------------|------|-----------|
| loop-remove-as-any | {N} | {N} | {N} | ACTIVE |
| loop-export-fn | {N} | 0 | 0 | SCAFFOLDED|
program.md: The most important fileprogram.md is the agent's behavior contract. Write it yourself, never auto-generate it. It must encode what the agent can/cannot touch for your specific codebase.
Minimal structure:
# Program: {loop-name}
## Objective
Reduce `{metric}` in `src/` to 0. One mechanical change per iteration.
## Measurement
bash scripts/autoresearch/{loop-name}/measure.sh
Lower = better. Target: 0.
## What you CAN do
- Replace `export function X(` with `export const X = (`
- Keep the function signature identical
## What you CANNOT do
- Modify test files
- Change function signatures
- Touch files outside src/
- Make multiple changes per iteration
## Stop when
- Metric = 0
- No more mechanical replacements exist
This skill implements the autoresearch loop pattern from karpathy/autoresearch:
| ML Research (karpathy) | Code Quality (this skill) |
|---|---|
Modify train.py | Modify src/ files |
Measure val_bpb | Measure grep count |
| 5-minute GPU budget | One atomic change per iteration |
| Keep if val_bpb improves | Keep if count decreases |
git reset if not | git checkout on the files.txt paths if not |
program.md = agent skill | program.md = agent skill |
Key insight: a fixed, objective metric, a pass/fail gate and git as rollback mechanism allow iteration without per-change approval. A change that misses the metric or fails check.sh is reverted. Anything the gate does not cover goes unchecked, so review the commits before merging.
Scan and propose loops:
/autoresearch
Scaffold files for a specific loop:
/autoresearch --scaffold loop-remove-as-any
Run the autonomous loop (after writing program.md):
/autoresearch --run loop-remove-as-any
Check status of all loops:
/autoresearch --status
$ARGUMENTS
What SKILL.md sets; muted values are Claude Code's defaults
highThree short reads, in order
20 skills in this plugin
/audit-agents-skillsAudit Claude Code agents, skills, and commands for quality and production readiness. Use when evaluating skill quality, checking production readiness scores, or comparing agents against best-practice templates./audit-codebaseCodebase health audit scoring 7 categories with progression plan/eval-agentsAudit custom subagent definitions for Claude Code (.claude/agents/*.md) and Codex (.codex/agents/*.toml): loadability against the native schema, description overlap, model tier, tool scope, and headless-safe instructions. Use when onboarding to a project with agents, after adding or importing agents, or when the parent agent delegates to the wrong agent./eval-hooksAudit Claude Code and Codex hooks for validity, safety, and correctness across settings.json, hooks.json, config.toml, plugin, and skill or agent frontmatter hooks. Resolves each command, checks event names, handler types, matchers, exit-code and JSON decision strategy, and timeouts against each host's documented rules, then reviews hooks one by one. Use when setting up hooks, debugging a hook that never fires, never blocks, or hangs the agent, or doing a periodic hooks hygiene pass. Not for writing a new hook from scratch./git-ai-archaeologyGit-history archaeology of a repository's AI coding harness (Copilot, Claude Code, Codex, Cursor, MCP, skills, agents, hooks). Use to date when each AI config appeared, trace how it spread, churned or was abandoned across modules, measure AI-assisted commits over time, or derive maturity phases. Not for auditing the current config or generic git stats./landing-page-generatorGenerate complete, deploy-ready landing pages from any repository. Use when creating a homepage for an open-source project, building a project website, converting a README into a marketing page, or standardizing landing pages across multiple repos.npx claudepluginhub florianbruniaux/claude-code-plugins --plugin ai-methodology2 plugins in one repository ship this exact skill · first indexed Nov 30, 2026
Other plugins' skills for the same job