ce-optimize
Run metric-driven iterative optimization loops -- define a measurable goal, run parallel experiments, measure each against hard gates or LLM-as-judge scores, keep improvements, and converge on the best solution. Use when optimizing clustering quality, search relevance, build performance, prompt quality, or any measurable outcome that benefits from systematic experimentation.
What this skill does
# Iterative Optimization Loop Run metric-driven iterative optimization. Define a goal, build measurement scaffolding, then run parallel experiments that converge toward the best solution. ## Interaction Method Use the platform's blocking question tool: `AskUserQuestion` in Claude Code (call `ToolSearch` with `select:AskUserQuestion` first if its schema isn't loaded), `request_user_input` in Codex, `ask_user` in Gemini, `ask_user` in Pi (requires the `pi-ask-user` extension). Fall back to numbered options in chat only when no blocking tool exists in the harness or the call errors (e.g., Codex edit modes) — not because a schema load is required. Never silently skip the question. ## Input <optimization_input> #$ARGUMENTS </optimization_input> If the input above is empty, ask: "What would you like to optimize? Describe the goal, or provide a path to an optimization spec YAML file." ## Optimization Spec Schema Reference the spec schema for validation: `references/optimize-spec-schema.yaml` ## Experiment Log Schema Reference the experiment log schema for state management: `references/experiment-log-schema.yaml` ## Quick Start For a first run, optimize for signal and safety, not maximum throughput: - Start from `references/example-hard-spec.yaml` when the metric is objective and cheap to measure - Use `references/example-judge-spec.yaml` only when actual quality requires semantic judgment - Prefer `execution.mode: serial` and `execution.max_concurrent: 1` - Cap the first run with `stopping.max_iterations: 4` and `stopping.max_hours: 1` - Avoid new dependencies until the baseline and measurement harness are trusted - For judge mode, start with `sample_size: 10`, `batch_size: 5`, and `max_total_cost_usd: 5` For a friendly overview of what this skill is for, when to use hard metrics vs LLM-as-judge, and example kickoff prompts, see: `references/usage-guide.md` --- ## Persistence Discipline **CRITICAL: The experiment log on disk is the single source of truth. The conversation context is NOT durable storage. Results that exist only in the conversation WILL be lost.** The files under `.context/compound-engineering/ce-optimize/<spec-name>/` are local scratch state. They are ignored by git, so they survive local resumes on the same machine but are not preserved by commits, branches, or pushes unless the user exports them separately. This skill runs for hours. Context windows compact, sessions crash, and agents restart. Every piece of state that matters MUST live on disk, not in the agent's memory. **If you produce a results table in the conversation without writing those results to disk first, you have a bug.** The conversation is for the user's benefit. The experiment log file is for durability. ### Core Rules 1. **Write each experiment result to disk IMMEDIATELY after measurement** — not after the batch, not after evaluation, IMMEDIATELY. Append the experiment entry to the experiment log file the moment its metrics are known, before evaluating the next experiment. This is the #1 crash-safety rule. 2. **VERIFY every critical write** — after writing the experiment log, read the file back and confirm the entry is present. This catches silent write failures. Do not proceed to the next experiment until verification passes. 3. **Re-read from disk at every phase boundary and before every decision** — never trust in-memory state across phase transitions, batch boundaries, or after any operation that might have taken significant time. Re-read the experiment log and strategy digest from disk. 4. **The experiment log is append-only during Phase 3** — never rewrite the full file. Append new experiment entries. Update the `best` section in place only when a new best is found. This prevents data loss if a write is interrupted. 5. **Per-experiment result markers for crash recovery** — each experiment writes a `result.yaml` marker in its worktree immediately after measurement. On resume, scan for these markers to recover experiments that were measured but not yet logged. 6. **Strategy digest is written after every batch, before generating new hypotheses** — the agent reads the digest (not its memory) when deciding what to try next. 7. **Never present results to the user without writing them to disk first** — the pattern is: measure -> write to disk -> verify -> THEN show the user. Not the reverse. ### Mandatory Disk Checkpoints These are non-negotiable write-then-verify steps. At each checkpoint, the agent MUST write the specified file and then read it back to confirm the write succeeded. | Checkpoint | File Written | Phase | |---|---|---| | CP-0: Spec saved | `spec.yaml` | Phase 0, after user approval | | CP-1: Baseline recorded | `experiment-log.yaml` (initial with baseline) | Phase 1, after baseline measurement | | CP-2: Hypothesis backlog saved | `experiment-log.yaml` (hypothesis_backlog section) | Phase 2, after hypothesis generation | | CP-3: Each experiment result | `experiment-log.yaml` (append experiment entry) | Phase 3.3, immediately after each measurement | | CP-4: Batch summary | `experiment-log.yaml` (outcomes + best) + `strategy-digest.md` | Phase 3.5, after batch evaluation | | CP-5: Final summary | `experiment-log.yaml` (final state) | Phase 4, at wrap-up | **Format of a verification step:** 1. Write the file using the native file-write tool 2. Read the file back using the native file-read tool 3. Confirm the expected content is present 4. If verification fails, retry the write. If it fails twice, alert the user. ### File Locations (all under `.context/compound-engineering/ce-optimize/<spec-name>/`) | File | Purpose | Written When | |------|---------|-------------| | `spec.yaml` | Optimization spec (immutable during run) | Phase 0 (CP-0) | | `experiment-log.yaml` | Full history of all experiments | Initialized at CP-1, appended at CP-3, updated at CP-4 | | `strategy-digest.md` | Compressed learnings for hypothesis generation | Written at CP-4 after each batch | | `<worktree>/result.yaml` | Per-experiment crash-recovery marker | Immediately after measurement, before CP-3 | ### On Resume When Phase 0.4 detects an existing run: 1. Read the experiment log from disk — this is the ground truth 2. Scan worktree directories for `result.yaml` markers not yet in the log 3. Recover any measured-but-unlogged experiments 4. Continue from where the log left off --- ## Phase 0: Setup ### 0.1 Determine Input Type Check whether the input is: - **A spec file path** (ends in `.yaml` or `.yml`): read and validate it - **A description of the optimization goal**: help the user create a spec interactively ### 0.2 Load or Create Spec **If spec file provided:** 1. Read the YAML spec file. The orchestrating agent parses YAML natively -- no shell script parsing. 2. Validate against `references/optimize-spec-schema.yaml`: - All required fields present - `name` is lowercase kebab-case and safe to use in git refs / worktree paths - `metric.primary.type` is `hard` or `judge` - If type is `judge`, `metric.judge` section exists with `rubric` and `scoring` - At least one degenerate gate defined - `measurement.command` is non-empty - `scope.mutable` and `scope.immutable` each have at least one entry - Gate check operators are valid (`>=`, `<=`, `>`, `<`, `==`, `!=`) - `execution.max_concurrent` is at least 1 - `execution.max_concurrent` does not exceed 6 when backend is `worktree` 3. If validation fails, report errors and ask the user to fix them **If description provided:** 1. Analyze the project to understand what can be measured 2. **Detect whether the optimization target is qualitative or quantitative** — this determines `type: hard` vs `type: judge` and is the single most important spec decision: **Use `type: hard`** when: - The metric is a scalar number with a clear "better" direction - The metric is objectively measurable (build time, test pass rate, latency, memory usage) - No human judgment is nee
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.