peiraloop
An experiment loop for coding agents that keeps only improvements it can measure.
Peira (πεῖρα) is Greek for a trial or an attempt.
You give peiraloop an objective, an evaluator command, the paths the agent may change, the paths it must not, and a budget.
Each trial, an agent makes one change in an isolated, sandboxed worktree.
peiraloop then measures that change against the current best, interleaving the two in random order, until the result is statistically clear in either direction.
Code, not the agent, decides whether the change is accepted, rejected or inconclusive, and every trial is recorded with its raw measurements.
At the end, the best result is measured again against the baseline on fresh samples, and only that number is reported as the improvement.
Do not trust an agent's claim of improvement. Measure it, reproduce it, and keep the evidence.
Status: v0.1.0.
The loop works end to end with Claude Code as the agent (validation runs).
In a comparative benchmark (5 tasks, 3 repetitions, same model and budget), peiraloop was the only agent approach with no false improvements: 0 of 15 runs, against 4 of 15 for a simple keep-if-better loop and 1 of 15 for a single agent session.
It did not find bigger improvements than the simple loop, and a single session was about five times cheaper and nearly as good on the easy tasks.
Use peiraloop when a wrong "improvement" is expensive, not to squeeze out more.
What it does
$ peira run
[peira 01:16:42] run 20261201-011642-31a4: evaluator 22391dca7d51e036, baseline a31008b0d9
[peira 01:16:42] calibrating: measuring the baseline against itself
[peira 01:16:45] with the observed noise, a true improvement of about 6.4% is needed to be accepted reliably (minEffect is 5.0%)
[peira 01:16:45] t1: asking the agent for a change to baseline
[peira 01:16:59] t1: accepted (224.9%)
[peira 01:16:59] t2: asking the agent for a change to t1
[peira 01:17:14] t2: accepted (171.7%)
[peira 01:17:14] t3: asking the agent for a change to t2
[peira 01:17:31] t3: accepted (28.0%)
[peira 01:17:31] confirming t3 against the baseline on fresh samples
[peira 01:17:36] confirmation: confirmed, 1011.3% [995.2%, 1027.8%]
That is the wordfreq example: 79.6 ms to 7.2 ms, confirmed, for $0.18 of agent spend (Claude Code's estimate) in 54 seconds.
- One agent call per trial, with a hard spend cap, in Claude Code's OS sandbox: it can write only its own worktree, has no network, no web tools, no MCP servers and no subagents.
- The evaluator is protected. Candidates that touch protected paths or leave the allowed scope are rejected before measurement. Every measured checkout is verified against the evaluator files pinned at the start, and the agent cannot write to the checkouts that are measured.
- Noise-aware verdicts. Interleaved blocks against the re-measured incumbent, a sequential test that stops early when the answer is clear, and outlier-robust statistics. Simulations keep the per-trial false-accept rate below the configured alpha (details).
- Calibration before spending. The run measures the baseline against itself first, and refuses to start when the noise is too high to detect the minimum effect you asked for.
- Evidence. Every candidate is a git commit under
refs/peiraloop/. Every raw sample, cost and token count is in .peiraloop/runs/. peira reproduce re-measures any result.
- Local and safe for your work. Your working tree and uncommitted changes are never touched. Nothing is pushed, merged or uploaded.
peira apply only creates a branch.
Install
Requirements: Node 20 or newer, git, and Claude Code on macOS, Linux or WSL2 (the agent sandbox is not available on native Windows).
As a Claude Code plugin, once the repository is published on GitHub:
/plugin marketplace add kiyeonjeon21/peiraloop
/plugin install peiraloop@peiraloop
Until then, from a local clone: claude --plugin-dir ./peiraloop/plugin.
The plugin puts peira on the Bash tool's PATH inside Claude Code.
To use it from a terminal, clone the repository and link the script:
git clone https://github.com/kiyeonjeon21/peiraloop
ln -s "$PWD/peiraloop/plugin/bin/peira" ~/.local/bin/peira
Use
In Claude Code:
/peiraloop:init make topWords faster while the tests pass; 30 minutes and $3
/peiraloop:run
/peiraloop:status
/peiraloop:report
init turns the request into .peiraloop/spec.json, helps you write or pick an evaluator, and runs a calibration.
run starts the loop in the background.
report explains the result from the evidence.
From a terminal: