Autonomous optimization loop — hill-climb any target. Code with metrics, or skills/prompts/agents with LLM-as-judge. USE WHEN optimize, hill climb, improve metr
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-optimize-7613e65603f0 ,按照其中的说明把「Optimize」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Runs an autonomous optimization loop against any target. The agent modifies the target, measures the result, keeps improvements, discards failures, and repeats until it stops climbing. Two modes: metric mode for code targets that produce a number (latency, bundle size), and eval mode for skills, prompts, or agents judged by LLM-as-judge binary evals.
Tuning a thing for a measurable outcome is slow, boring, manual work. You change a file, run the measurement, eyeball whether it got better, keep or revert, then do it again — dozens of times. People give up after a few rounds and settle for "good enough" far short of the real ceiling. The targets without a clean number (a skill's quality, a prompt's effectiveness) are worse: there's no easy way to tell if a change actually helped. This skill runs that whole loop for you and only keeps changes that measurably win.
Two modes drive the same hill-climb loop:
Inspired by Karpathy's autoresearch and extended with LLM-as-judge evaluation.
/optimize --metric "lighthouse_score" --higher-is-better \
--measure "npx lighthouse http://localhost:3000 --output=json" \
--extract "jq '.categories.performance.score * 100' lighthouse.json" \
--files "src/**/*.tsx,src/**/*.css" \
--budget 120
/optimize --resume # Resume a previous optimization loop
/optimize --status # Show results summary from last/current run
/optimize --target "~/.claude/skills/ExtractWisdom"
/optimize --target "~/.claude/skills/Research/Workflows/QuickResearch.md"
/optimize --target "prompts/my-prompt.md"
/optimize --target "~/.claude/skills/ExtractWisdom" --max-experiments 20
In eval mode, the system automatically:
This skill drives the LifeOS Algorithm as an autonomous mutation loop:
optimize-loop.md)
optimize-loop.md):
| Argument | Required | Default | Description |
|---|---|---|---|
--metric NAME | yes | Human-readable metric name | |
--measure COMMAND | yes | Shell command that produces the metric | |
--files GLOB | yes | Files the agent may modify (comma-separated) | |
--higher-is-better | (default) | Higher metric values are better | |
--lower-is-better | Lower metric values are better | ||
--extract COMMAND | Last number in stdout | Extract metric from output | |
--budget SECONDS | 300 | Time budget per experiment | |
--target VALUE | none | Stop when metric reaches this value | |
--max-experiments N | none | Stop after N experiments | |
--locked GLOB | none | Files the agent must NOT modify | |
--constraints TEXT | none | Additional rules (e.g., "tests must pass") |
| Argument | Required | Default | Description |
|---|---|---|---|
--target PATH | yes | Path to skill directory, prompt file, or agent definition | |
--max-experiments N | none | Stop after N experiments | |
--runs N | 3 | Runs per experiment (more = more reliable, slower) | |
--criteria "Q1" "Q2" | auto-generated | Override auto-generated eval criteria | |
--inputs "I1" "I2" | auto-generated | Override auto-generated test inputs | |
--budget SECONDS | 300 | Time budget per experiment |
| Argument | Description |
|---|---|
--resume | Resume a previous optimization run |
--status | Show results summary |
When /optimize is invoked, the eval_mode is set based on arguments (mode: is retired — never write it to frontmatter):
--measure provided → eval_mode: metric (git branch sandbox)--target provided → eval_mode: eval (directory sandbox)ISC criteria become guard rails — assertions that must hold true across ALL experiments. Guard rails must REMAIN satisfied perpetually. A violation triggers automatic revert regardless of score improvement.
Reference files:
~/.claude/LIFEOS/ALGORITHM/optimize-loop.md — the full loop protocol~/.claude/LIFEOS/ALGORITHM/eval-guide.md — how to write good eval criteria~/.claude/LIFEOS/ALGORITHM/archive/target-types.md — target detection and ISC generationOptimize page load time:
/optimize --metric "lighthouse_perf" --higher-is-better \
--measure "npx lighthouse http://localhost:3000 --output=json --output-path=lh.json" \
--extract "jq '.categories.performance.score * 100' lh.json" \
--files "src/**/*.tsx,src/**/*.css" \
--target 95 --budget 120
Optimize bundle size:
/optimize --metric "bundle_bytes" --lower-is-better \
--measure "bun run build 2>&1 && du -sb dist/ | cut -f1" \
--files "src/**/*.ts" \
--constraints "all tests must pass"
ML training (Karpathy-style):
/optimize --metric "val_bpb" --lower-is-better \
--measure "uv run train.py > run.log 2>&1 && grep '^val_bpb:' run.log | cut -d' ' -f2" \
--files "train.py" \
--locked "prepare.py" \
--budget 300
Optimize a skill's Extract workflow:
/optimize --target "~/.claude/skills/ExtractWisdom" --max-experiments 15
Optimize a standalone prompt:
/optimize --target "prompts/summarize-article.md" --runs 5
Optimize with custom criteria:
/optimize --target "~/.claude/skills/Research/Workflows/QuickResearch.md" \
--criteria "Does the output contain specific facts with sources?" \
"Is the output structured with clear sections?" \
"Does the output avoid generic filler?" \
--inputs "research quantum computing breakthroughs 2025" \
"quick research on supply chain security" \
"find recent developments in AI agents"