Transcript miner: corrections into fixes

Read seven sessions, find the human corrections, and group them by what they ask for. Find the tool calls that failed the same way and the procedures people repeated, then propose one fix per pattern, with its evidence: a hook, a path-scoped rule, a permission deny, a codebase-map line or a skill draft. Nothing is applied. Session background: human corrections, rules, sessions into skills and proposing.

  • Python 3.9+
  • standard library only
  • offline: transcripts/*.jsonl
  • the sample repo's CLAUDE.md

The seven sessions are lab-made, in the documented stream-json message shape: what you'd save from claude -p --output-format stream-json --verbose. The lab doesn't read Claude Code's own session files under ~/.claude/projects/, because their format isn't documented. The reader skips lines it doesn't recognize, redacts credential-like strings, and sends nothing anywhere.

python3 autonomy-5/transcript_miner.py
┌──────────────────────────────────────────────────────────┐
│ Transcript miner: corrections -> rules, hooks and skills │
└──────────────────────────────────────────────────────────┘
[1] Read 7 session(s)
session           first prompt                                        tool calls  errors  corrections
────────────────  ──────────────────────────────────────────────────  ──────────  ──────  ───────────
s1-bulk-discount  Give 10% off when an order has 10 or more items.    4           0       2          
s2-save5          Add a SAVE5 discount code worth 5%.                 4           1       1          
s3-currency       Show prices with a currency symbol for the region.  4           1       1          
s4-release-0.3.1  Cut release 0.3.1: update the changelog and bump t  5           0       0          
s5-release-0.3.2  Cut release 0.3.2: update the changelog and bump t  6           0       1          
s6-rounding       Tax on 1005 cents in CA is off by a cent; fix it.   6           0       2          
s7-receipt        Move receipt formatting into tinyapp/receipt.py.    5           0       2          
[2] Corrections, grouped by what they ask for
  #1 cent-float-integer (2 session(s))
      s1-bulk-discount: "No, don't use floats for money. Integer cents only, like CLAUDE.md says."
      s6-rounding: "Stop using floats here. Cents are integers."
  #2 run-test-before (3 session(s))
      s1-bulk-discount: "You also didn't run the tests before saying done."
      s2-save5: "Please run the tests before you finish."
      s7-receipt: "run the test suite first, then tell me it's done."
  #3 add-dependency-library (1 session(s))
      s3-currency: "Don't add third-party dependencies. Use the standard library."
  #4 changelog-heading (1 session(s))
      s5-release-0.3.2: "Use the same changelog headings as last time."
  #5 pass-test-change (2 session(s))
      s6-rounding: "Don't change the tests to make them pass. Fix the code."
      s7-receipt: "Don't edit the tests so they pass"
[3] Proposals (nothing is applied)

  Enforce: cent-float-integer  ->  hook   [2 sessions: s1-bulk-discount, s6-rounding]
    why: CLAUDE.md already says "All amounts are integer cents. Never introduce floats for money." and it was still corrected in 2 session(s): an adherence gap. Make it mechanical.
    proposal: a PostToolUse check that flags float literals in money code (autonomy-4 post_edit_check.py)

  Enforce: run-test-before  ->  hook   [3 sessions: s1-bulk-discount, s2-save5, s7-receipt]
    why: CLAUDE.md already says "Add or update a test for every behavior change, and run the suite before finishing." and it was still corrected in 3 session(s): an adherence gap. Make it mechanical.
    proposal: a Stop gate that runs the tests itself and keeps its own budget (autonomy-1 goal_gate), with CI as the real gate; autonomy-4 stop_check is only a one-time nudge

  Rule: pass-test-change  ->  .claude/rules/tests.md   [2 sessions: s6-rounding, s7-receipt]
    why: Not in CLAUDE.md, and every edit it followed was under tests/: a path-scoped rule loads only when Claude works there.
    proposal: Don't change the tests to make them pass. Fix the code; Don't edit the tests so they pass
    draft: out/transcript_miner/drafts/.claude/rules/tests.md

  Map fix: tinyapp/discounts.py  ->  CLAUDE.md (Layout)   [2 sessions: s2-save5, s3-currency]
    why: The same failed Read in 2 sessions; one line of map saves a wasted turn each time.
    proposal: There is no `tinyapp/discounts.py`; the code it's looking for is in `tinyapp/pricing.py`.

  Skill: /release  ->  .claude/skills/release/SKILL.md   [2 sessions: s4-release-0.3.1, s5-release-0.3.2]
    why: A multi-step procedure repeated across sessions; a skill makes it one command (user-only, because it runs `git tag`).
    proposal: 5 steps
    draft: out/transcript_miner/drafts/.claude/skills/release/SKILL.md
[4] Watching (below --min-sessions 2)
  Enforce: add-dependency-library: s3-currency: "Don't add third-party dependencies. Use the standard library."
  CLAUDE.md line: changelog-heading: s5-release-0.3.2: "Use the same changelog headings as last time."

wrote autonomy-5/out/transcript_miner/proposals.md, proposals.json and 2 draft file(s)
next: test a proposal with python3 autonomy-5/config_eval.py before anyone commits it
  1. CLAUDE.md already says it, and people still corrected it. That's an adherence gap, so the fix is mechanical: a hook, not another sentence.
  2. For "run the tests first", the right hook is a Stop gate that runs the tests itself and keeps its own budget, with CI as the real gate. A one-time nudge isn't enough.
  3. Not in CLAUDE.md, and every edit it followed was under tests/. So it becomes a path-scoped rule, which loads only when Claude works there.
  4. The same failed Read in two sessions: Claude keeps looking for a file that doesn't exist. One line of codebase map saves a wasted turn every time.
  5. Two release sessions ran the same five steps, so it becomes a skill. It's user-only because it runs git tag.
  6. Corrected once is a watch item, not a proposal. --min-sessions sets the bar.

The drafts land under out/transcript_miner/drafts/, next to proposals.md and proposals.json. The skill draft:

cat autonomy-5/out/transcript_miner/drafts/.claude/skills/release/SKILL.md
---
name: release
description: Run the release procedure recorded in 2 sessions (Run git log, Edit CHANGELOG.md, Edit tinyapp/__init__.py, Run python3 -m unittest, Run git tag). Use when the user asks for a release.
disable-model-invocation: true
argument-hint: "[version]"
---

# Release $ARGUMENTS

The same sequence ran in s4-release-0.3.1, s5-release-0.3.2:

1. Run `git log ...`
2. Edit `CHANGELOG.md`
3. Edit `tinyapp/__init__.py`
4. Run `python3 -m unittest ...`
5. Run `git tag ...`

Stop if `python3 -m unittest ...` fails. Show the user what changed before running `git tag`.
  1. The description names the recorded steps and when to use it. Descriptions are what stays in Claude's context, so they carry the matching.
  2. disable-model-invocation: true makes it user-only: Claude can't decide on its own to tag a release.
  3. The evidence travels with the draft: the sessions it came from.
  4. A stop condition and a human checkpoint before the irreversible step. Review and edit the draft before anyone commits it.

To use a proposal, review it, test it with config_eval.py (the next lab), and commit it through a normal PR. The run's last line says the same.

  • --min-sessions 3 keeps only "run-test-before", which three sessions corrected. The float, tests, dependency and changelog corrections move to the watch list, while the map fix and the /release skill drop out entirely, since the watch list holds only corrections, and no drafts are written. --min-sessions 1 promotes the dependency correction too, as a permissions.deny for Bash(pip install *) and Bash(npm install *).
  • Break it (exercise 2): lower --cluster-threshold from the default 0.25 to 0.1. "Don't edit the tests so they pass" merges into "run the tests before", giving one 4-session group, and the tests.md rule proposal disappears. Two different asks now get one fix. At 0.15 nothing merges yet.
  • Mine your own sessions: save a few claude -p --output-format stream-json --verbose runs into a folder and pass --transcripts DIR --claude-md ./CLAUDE.md. Which proposal would you actually ship?
  • The kind of fix follows the evidence. Already in CLAUDE.md and still corrected: a hook or a permission. Not written down, and tied to one folder: a path-scoped rule. A procedure repeated: a skill. A failed lookup: a map line.
  • CLAUDE.md instructions are advisory; hooks are deterministic. A CLAUDE.md line that people keep enforcing by hand is the signal to move it into a hook or a permission.
  • Every proposal carries its sessions and quotes, so a reviewer can check it without rereading the transcripts.
  • Nothing is applied. Mining proposes; an eval and a person decide.

Config eval: one promotion gate for three configs

Compare three versions of a project's config (CLAUDE.md, rules, skills) on five tasks with outcome graders. See what each one loads before the first task, catch a regression even when the pass rate matches the baseline, and apply a written promotion gate that also refuses incomplete or too-small evaluations. Session background: baselines, regression checks, CLAUDE.md pruning and approving.

  • Python 3.9+
  • standard library only
  • offline: configs/, eval/tasks.json and eval/runs/
ConfigWhat changed
AThe baseline: the sample repo's CLAUDE.md as it is, 27 lines.
BA rewrite: a shorter CLAUDE.md that states the test rule as a must, plus an add-discount-code skill. It dropped the "integer cents" convention by accident.
CB plus .claude/rules/money.md, a path-scoped rule (paths: "tinyapp/**/*.py") that carries the money convention.

The graders check outcomes in each run's transcript, such as a passing test run after the last edit, or no float literals in tinyapp/. The recorded runs are lab-made, one trial per task and config, and their costs come from each run's usage at the list prices in common/llm.py.

python3 autonomy-5/config_eval.py
┌───────────────────────────────────────────────────────────────┐
│ Config eval: same tasks, different CLAUDE.md / rules / skills │
└───────────────────────────────────────────────────────────────┘
[1] What each config loads before the first task
config  CLAUDE.md lines  words  skills             path-scoped rules  always-loaded tokens  on demand
──────  ───────────────  ─────  ─────────────────  ─────────────────  ────────────────────  ─────────
A       27               162    -                  -                  ~440                  ~0       
B       9                66     add-discount-code  -                  ~229                  ~0       
C       9                66     add-discount-code  money.md           ~229                  ~90      
  token counts are estimates (characters / 2.5); the skill listing holds descriptions, not bodies.
[2] Replay the recorded runs in autonomy-5/eval/runs/ (one trial per task and config)
[3] Results by task
task            A               B               C             
──────────────  ──────────────  ──────────────  ──────────────
add-code        FAIL 7t $0.047  pass 5t $0.040  pass 5t $0.040
explain-tax     pass 2t $0.030  pass 2t $0.030  pass 2t $0.030
add-dependency  pass 2t $0.030  pass 2t $0.030  pass 2t $0.030
bulk-discount   pass 5t $0.040  FAIL 5t $0.040  pass 5t $0.040
tax-change      pass 2t $0.030  pass 2t $0.030  pass 2t $0.030
  A/add-code: tests_after_last_edit: a passing test run after the last edit
  B/bulk-discount: no_float_literal: no float literals in tinyapp/ (found 0.1 in tinyapp/cart.py)
[4] Summary and the promotion gate
config  passed  cost    mean turns  fixed vs baseline  broke vs baseline  decision                              
──────  ──────  ──────  ──────────  ─────────────────  ─────────────────  ──────────────────────────────────────
A       4/5     $0.179  3.6         -                  -                  baseline                              
B       4/5     $0.168  3.2         add-code           bulk-discount      rejected: regresses bulk-discount     
C       5/5     $0.168  3.2         add-code           -                  ships: no regressions, better, cheaper
  gate: every task complete for both; at least 3 tasks; no regressions vs A; pass rate >= A's; cost <= 1.10x A's unless the pass rate went up; and a gain (a fixed task or a lower cost)
  recommendation: ship C (open a PR with its diff; a person approves)
  recorded runs, one trial each: rerun real evals several times before trusting a single pass/fail flip.

wrote autonomy-5/out/config_eval/report.md and report.json
  1. What each version costs before the first task. C keeps the money rule out of the always-loaded context: it loads on demand, when Claude works on a Python file under tinyapp/. The token counts are estimates: characters divided by 2.5, the course-wide ratio.
  2. A fails add-code on an outcome, not a vibe: no passing test run after its last edit. B's add-discount-code skill, which ends by running the suite, fixes that.
  3. B's regression: dropping the integer-cents line let a float into tinyapp/cart.py.
  4. B passes 4/5, the same as the baseline, and is still rejected. An equal pass rate hides a fix and a break; compare task by task.
  5. C clears every clause of the written gate: complete runs, at least 3 tasks, no regressions, a pass rate at least A's, cost within 1.10× of A's unless the pass rate went up, and a real gain.
  6. Even a pass ends with a person approving a PR. One recorded trial per task is a demo, not evidence.
  • Judge from too little: --configs A,C --tasks explain-tax. C passes its one task and is still "rejected: insufficient evidence (1 task(s), one trial each)", and the recommendation is to keep A.
  • --configs C --tasks explain-tax,add-code,bulk-discount leaves out the baseline, and the lab adds it back: a candidate is only judged against A, on the same tasks. C ships on those three.
  • Break it: make one of C's runs a refusal, then grade the copy. C/bulk-discount turns INCOMPLETE ("stop_reason=refusal: the model declined"), isn't graded, and blocks the gate: "rejected: incomplete evaluation (no complete run for bulk-discount)". The result line still says subtype: "success", so stop_reason has to be checked first.
    rm -rf /tmp/runs && cp -R autonomy-5/eval/runs /tmp/runs
    sed -i.bak 's/"stop_reason": "end_turn"/"stop_reason": "refusal"/' /tmp/runs/C/bulk-discount.jsonl
    python3 autonomy-5/config_eval.py --runs /tmp/runs
  • --runs pointing at a folder that doesn't exist exits 2 ("no such folder"), and no report is written.

Run the read-only tasks for real against your Claude Code: one claude -p per config and task, in a temp copy of the sample repo with that config copied in, with Read, Grep and Glob in dontAsk mode. Each run is capped at --max-turns 4 and --max-budget-usd 0.05 by default, and the total cap is printed before anything runs:

python3 autonomy-5/config_eval.py --real --configs A,C --tasks explain-tax --model haiku

The raw stream-json is saved to out/config_eval/real-runs/, so you can re-grade it offline after changing a grader, without paying again: --runs autonomy-5/out/config_eval/real-runs --configs A,C --tasks explain-tax. With only Read, Grep and Glob there's no Skill tool, so a real run measures CLAUDE.md and rules only. Your own ~/.claude/CLAUDE.md loads too (the same for every config), --repo is refused, and empty ~/.claude/projects/<temp dir>/memory/ folders may be left behind. A single task can never ship a candidate: the gate wants at least 3. The one real run recorded while building the labs (config C, v2.1.303 on Bedrock) cost $0.002 and failed only because the grader wanted the words "basis points" where the right answer said TAX_BPS. The grader changed, not the config.

  • Grade outcomes you can check in the transcript, and compare task by task against a baseline. A pass rate alone hides regressions.
  • Shorter isn't automatically better. B saved context and lost a convention; C moved the convention into a rule that loads only where it applies.
  • The gate is written down and refuses to judge incomplete or too-small evidence. Refusals and runs that didn't finish block it rather than count as passes.
  • A grader can be wrong too. Save raw runs so you can fix the grader and re-grade without new model calls.