Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Experiment Finalize?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/wsauret-experiment-finalize)
---
description: Use when finalizing kept experiments into clean, reviewable branches, one per independent change.
attended: true
agents:
- explorer
direct-output: Report the audit findings and any override, the branches created, what each contains, the overall metric improvement, whether the experiment worktree was removed or why it stays, and the cleanup commands directly in chat.
---
# Finalize Experiments
Turn a noisy experiment branch into clean, independent branches, one per logical change, each starting from the merge-base. An independent audit comes first, and no branch exists while one of its findings stands. The bundled finalize.sh script does the branch surgery; `references/groups-json.md` defines the input it takes, read with the skill tool's resource action before Step 3.
## Step 1: Audit the kept changes
1. Get the full hash of the current HEAD with `git rev-parse HEAD`. HEAD is the combined kept tree.
2. Get the auditor's brief through the skill tool: `skill` with `action:"child-run"`, `skill_id:"experiment-finalize"`, `script:"auditor-brief"`, and `input` set to `{ "final_commit": "<full HEAD hash>" }`. Flywheel writes the brief from `references/gaming-audit.md` and the commit. Dispatch one `explorer` subagent, which is read-only and did not run the loop, with the returned `brief` as its whole prompt, unchanged. Do not add your own view of the changes. Do not fork it. Wait for its result.
3. Run the audit through the skill tool: `skill` with `action:"child-run"`, `skill_id:"experiment-finalize"`, `script:"audit"`, and `input` set to `{ "final_commit": "<full HEAD hash>" }`. Flywheel reads the findings from the recorded result of every read-only subagent that this session dispatched, without fork, with exactly that brief, and takes all of their findings. It refuses while one of them has not completed: wait for it, or resume it when it ended without completing; another auditor does not replace it. It refuses when no such auditor exists. It refuses a `final_commit` that is not the newest kept commit, reruns the recorded measure and checks commands on it in a clean temporary worktree, compares the result with the recorded best within the noise floor, and answers every finding that any audit of that commit reported. A later audit never withdraws a finding.
4. Show the person each finding verbatim. When a finding stands, stop and ask the person whether to fix it, abandon finalization, or override it. Only the person overrides a finding, with the `/experiment override` command; you cannot. Record their words in a session note.
## Step 2: Analyze and propose groups
1. Read the run history: `flywheel events search --type experiment.run.recorded --json --limit 0 --session <sessionId>`. The session id is the `sessions/<sessionId>` segment of your scratchpad directory path. Keep only rows whose `source` is `store` and whose `sessionId` is this session; drop every `log` row. Keep only the runs of the segments that ran in this worktree: the `segment` of each `experiment.initialized` fact whose `workDir` is the chat's current directory, which `flywheel events search --type experiment.initialized --json --limit 0 --session <sessionId>` lists. Validate each payload: `run` and `segment` are integers, `commit` and `description` are strings, `status` is one of `keep`, `discard`, `crash`, `checks_failed`, `metric` is a finite number. Sort the rows by `position` ascending; timestamps are not the order. Then filter to kept experiments only.
2. Read `.experiment/charter.md` for context.
3. Expand every short commit hash to a full hash with `git rev-parse <short_hash>`. The merge-base is the commit that the text after this method says the experiment's worktree was created from; only when the text names no worktree, get it with `git merge-base HEAD main`.
4. For each kept commit, get the diff stat (`$BASE..<commit>` for the first, `<prev_kept>..<commit>` for the rest).
5. Group kept commits into logical changesets. Preserve application order. No two groups may touch the same file, because each branch is applied to the merge-base independently; merge groups that overlap. Flag cross-file dependencies ("group 2 depends on group 1, review together") and merge tightly coupled groups. Keep each group to one idea; the count follows the work.
Present the proposed grouping to the user as a numbered list: title, commits, files, and the metric before and after each group. Before you ask, write the complete groups JSON (the shape in `references/groups-json.md`) to a session note so it is frozen. Wait for approval before proceeding. After approval, run exactly the frozen JSON; do not recompute it. If the user asks for changes, revise the proposal, freeze the revised JSON, and ask again.
## Step 3: Run the frozen groups
Run the bundled finalizer through the skill tool: `skill` with `action:"child-run"`, `skill_id:"experiment-finalize"`, `script:"finalize.sh"`, and `input` set to the frozen groups object. Its `final_tree` must be the audited HEAD. Flywheel refuses it when no audit of that commit exists, while a finding stands that the person did not override with `/experiment override`, and when the union of the groups does not rebuild the audited tree outside `.experiment/`. The host reads the exact bundled finalize.sh, writes it and your approved groups into the session scratchpad, and runs it in the experiment working tree. Never run the script another way and never edit it.
The script creates one branch per group from the merge-base, verifies the union matches the original branch, and prints a summary with all branches and cleanup commands. On creation failure it rolls back (deletes branches, restores the original branch, pops the stash). On verification failure it exits non-zero and leaves the branches intact for inspection.
## Step 4: Leave the experiment worktree
Do this step only when the text after this method names a worktree that this experiment owns. When finalize.sh did not create every branch, keep the worktree and say in your report why it stays. Otherwise call `change_directory` with the project root that the text names, alone in its message. Then remove the worktree through the skill tool: `skill` with `action:"child-run"`, `skill_id:"experiment-finalize"`, `script:"remove-worktree"`, and `input` set to `{ "worktree": "<worktree path>" }`. Flywheel removes it without force only when finalize.sh created every branch of it in this chat, stashed nothing, and the worktree holds nothing that a finalize branch does not hold; otherwise it keeps the worktree and answers why. Report its answer. Never push the experiment branch; it stays local.
## Step 5: Report
Report the audit findings and any override, the branches created and what each contains, the overall metric improvement (baseline to best), whether the experiment worktree was removed or why it stays, the cleanup commands from the script's summary, and any untried ideas from your session notes.
## Edge cases
- One kept experiment: one branch is fine; do not force splits.
- Overlapping files between groups: the script fails naming the file. Merge the overlapping groups and retry.
- Non-experiment commits on the branch: skip them; only kept experiments from the recorded run facts are processed.