一键导入
karpathy-loop
Executes autonomous Loop Engineering cycles (Autoresearch) for continuous code and metric optimization.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Executes autonomous Loop Engineering cycles (Autoresearch) for continuous code and metric optimization.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Recursive error-fix loop. Use when a bash command fails with a build/test/typecheck error, when the same class of error appears more than once, or when the harness itself needs a persistent rule so the error does not come back. Detect → root-cause → minimal fix → test → lint/typecheck → persist rule (SKILL.md / AGENTS.md / docs/rules) → audit with evidence. Cross-harness (Claude Code, OpenCode, Codex, Gemini, Agy).
Wraps any external CLI so the AI harness can invoke it without context bloat. Captures --help output, documents every subcommand/flag in a compact digest, saves token metrics (raw vs wrapped), and exposes a standardized interface (invoke, explain, audit). Use before calling an unfamiliar CLI or when the harness needs to interact with a CLI repeatedly.
One-shot setup that configures the CLI wrapper ecosystem across ALL AI harnesses (Claude Code, Gemini, Codex, Agy, OpenCode). Creates symlinks from Claude (single source of truth) to every other CLI, registers wrapper skills/agents in each harness, and injects the "prefer wrapped CLI" policy into each CLI's config file. Run once per machine or after adding a new CLI to the ecosystem.
Cross-harness skill that teaches Claude Code, Codex (OpenAI), and Antigravity (Agy) how to use OpenCode as a subagent. Covers delegation triggers, task formatting, provider routing, result handling, and the complete protocol for efficient subagent orchestration.
Automatically routes tasks to the optimal AI agent, model, or provider based on complexity, cost, and capability. Use when implementing features, fixing bugs, or any multi-step development work. Triggers on "implement", "build", "create", "fix", "add feature", "develop", or when the user asks to do any coding task.
Surface opportunities to deepen a codebase. Finds modules that are shallow (thin pass-throughs, anemic types, missing domain modeling) and proposes how to make them deep (rich domain types, co-located behavior, testable seams). Outputs a visual HTML report and then runs an interactive grilling loop that pressure-tests each opportunity. Use when the codebase feels "flat", domain logic leaks into controllers/UI, types carry no behavior, or AI agents struggle to navigate the module boundaries. Integrates with domain-modeling, codebase-design, and ADR workflows.
| name | karpathy-loop |
| description | Executes autonomous Loop Engineering cycles (Autoresearch) for continuous code and metric optimization. |
| version | 2.0.0 |
Implements Loop Engineering — the practice of delegating experimentation loops to AI agents that iteratively modify code, run experiments, evaluate metrics, and decide to keep or revert changes. Based on Andrej Karpathy's Autoresearch method.
Three-file contract:
| File | Role | Agent Editable? |
|---|---|---|
prepare.py | Static experiment setup: data, tokenizer, metric definition | No (immutable baseline) |
train.py (or target) | Model/code under optimization | Yes (agent's playground) |
program.md | Human-written instructions, constraints, and acceptance criteria | No (human edits only) |
Each iteration: agent reads program.md → forms hypothesis → edits target code → runs timed experiment (default 5 min) → evaluates metric → commits if improved, reverts if regressed.
Two-layer cache inspired by the AI Engineering Guidebook:
Layer 1 — Cold Cache (CAG / KV Cache) Stable, rarely-changing context cached directly in KV memory:
program.md instructionsAvoids recomputing the same static information on every iteration. Uses Paged Attention to prevent GPU memory fragmentation.
Layer 2 — Hot Cache (Prompt Cache) Dynamic per-iteration state via OpenAI/Anthropic prompt caching:
Cold + hot separation keeps cache size bounded while maximizing reuse. See /getCacheStatus endpoint for current cache utilization.
POST /runLoopStart an autonomous optimization loop.
{
"program_file": "./program.md",
"target_file": "./train.py",
"evaluation_script": "./prepare.py",
"metric_name": "val_bpb",
"max_iterations": 100,
"timeout_seconds": 300,
"cache_strategy": "prompt_cache"
}
Response:
{
"status": "success",
"data": {
"loop_id": "loop_a1b2c3d4",
"status": "running",
"started_at": "2026-07-09T20:00:00Z"
}
}
GET /getResultsRetrieve loop progress and history.
{
"loop_id": "loop_a1b2c3d4"
}
Response:
{
"loop_id": "loop_a1b2c3d4",
"status": "running",
"current_iteration": 42,
"best_metric": {
"name": "val_bpb",
"value": 1.1023,
"improvement_pct": 12.4
},
"total_improvements": 5,
"iterations": [
{
"number": 38,
"hypothesis": "Increase depth from 8 to 12",
"metric_value": 1.1023,
"accepted": true,
"duration_seconds": 298
}
],
"cache_hits": 38,
"cache_savings_ms": 15200
}
POST /runExperimentRun a single isolated experiment without commit.
{
"target_file": "./train.py",
"dry_run": false,
"use_cache": true
}
Response:
{
"execution_time_seconds": 298,
"metric": { "name": "val_bpb", "value": 1.2345 },
"logs": "Epoch 1 loss: 2.1... val_bpb final: 1.2345",
"cached": true
}
GET /getCacheStatusInspect cache state across layers.
Response:
{
"prompt_cache": { "active_entries": 3, "hits": 38, "misses": 4, "savings_ms": 15200 },
"kv_cache": { "active_entries": 2, "memory_usage_mb": 128, "fragmentation_pct": 3.2 },
"cold_storage": { "cached_files": ["program.md", "baseline.json"], "size_bytes": 24576 }
}
POST /revertLastRevert the last accepted change.
{ "loop_id": "loop_a1b2c3d4" }
Response:
{
"status": "success",
"reverted_iteration": 38,
"previous_metric": { "name": "val_bpb", "value": 1.1500 }
}
| Permission | Purpose |
|---|---|
gpu_access | Run ML experiments (PyTorch) within strict time windows |
llm_api_access | Agent generates hypotheses and code edits via LLM APIs |
file_storage_read_write | Read/write target files, logs, and progress artifacts |
network_access | Download datasets, sync results, call LLM APIs |
git_operations | Commit accepted changes, revert regressions, track history |
lemon-cli plugin audit karpathy-loop — verify all 5 permissions requestedtrain.py that prints val_bpb: 1.50 → /runExperiment → verify metric extractionprogram.md targeting metric reduction → /runLoop with max_iterations: 3 → verify autonomous cycle/getCacheStatus pre/post loop — verify prompt cache hits increase with shared prefixes/getResults during loop + /revertLast — verify iteration tracking and git revert