SLOPSHOPPER

replay-theater

Replay Theater: step through the file edits Claude made in the last turn, one diff at a time.

newpanebandguardcommandtoast
A shopper browsing a rack in a slop shop
Preview · a replayed session in a sandbox
claude · ~/work/app · replay-theater
│ ┃ Replay Theater ✕ › fix the failing auth test and add an audit log call │ ┃ ╭──────────────────────────────────────────╮ │ ┃ │ ▶ Replay Theater step 1 of 3 │ ⏺ Read(src/auth.ts) │ ┃ │ 1 2 3 │ ⎿ Read 6 lines │ ┃ │ src/auth.ts │ ⏺ Update(src/auth.ts) │ ┃ │ Edit +2 -1 │ ⎿ Added 2 lines, removed 1 line │ ┃ │ │ ⏺ Bash(bun test) │ ┃ │ - if (!claims) throw new Error('invalid… │ ⎿ 3 pass, 1 fail │ ┃ │ + if (!claims || claims.exp < Date.now(… │ │ ┃ │ + await audit('refresh', claims.sub) │ ● Done. refresh now rejects expired claims and logs an audit event. │ ┃ │ │ │ ┃ │ [ ◀ Prev ] [ Next ▶ ] [ Close ] │ ✻ Worked for 42s · done 4:20 PM │ ┃ ╰──────────────────────────────────────────╯ │ › /replay │ ⎿ replay-theater: Replay Theater: 3 edits │ │ ⟨Claude Code's own drawing⟩ ▶ Replay: 3 edits (press r) [ Replay ] ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts

Draws

Band
⟨Claude Code's own drawing⟩ ▶ Replay: 3 edits (press r) [ Replay ]
Pane · Replay Theater
╭──────────────────────────────────────────────────────────╮ │ ▶ Replay Theater step 1 of 3 │ │ 1 2 3 │ │ src/auth.ts │ │ Edit +2 -1 │ │ │ │ - if (!claims) throw new Error('invalid token') │ │ + if (!claims || claims.exp < Date.now() / 1000) throw … │ │ + await audit('refresh', claims.sub) │ │ │ │ [ ◀ Prev ] [ Next ▶ ] [ Close ] │ ╰──────────────────────────────────────────────────────────╯
README

Replay Theater

Anthropic's sample mod from anthropics/claude-code-playground, Apache License 2.0 (see LICENSE). Ben AI added one change: the /mods switchboard can turn it off or hide it.

A Claude Code mod that lets you step through the file edits Claude made in the last turn, one diff at a time. We're sharing it as an example of a mod that records tool calls without changing them and gives you a pane with buttons to review them afterwards.

What this shows

While a turn runs, Replay Theater records each file edit Claude makes (the Edit, Write and MultiEdit tool calls): the file, and the text before and after. When the turn ends, a hint appears above the prompt:

▶ Replay: 5 edits (press r)  [ Replay ]

Open it, and a pane shows one edit at a time: the file, the tool, a count of added and removed lines, and a short diff in red and green. A strip of numbered cells shows every step, with the current one highlighted, and the header reads "step 2 of 5". Prev, Next and Close buttons move through the steps.

Replay Theater only watches. It never blocks, changes or delays an edit.

The patterns it demonstrates:

  • Recording from tool.call and always passing the call on with next(e).
  • Grouping work by turn with turn.start and turn.complete, and skipping subagent turns.
  • A slash command (/replay) registered from session.start and handled in command.run.
  • A Pane with Button elements and hotkeys, with a fallback to the AbovePrompt band.

Demo

After a rename, the hint above the prompt:

The Replay hint above the prompt after a turn with five edits

The pane, on step 1 of 5:

The Replay Theater pane showing step 1 of 5

A Write step for a new file, capped at 12 lines:

A Write step for a new file, with the diff capped at 12 lines

Inline above the prompt in an 80-column terminal:

The pane drawn inline in an 80-column terminal

How it was built

  • Model: built with Claude in Claude Code. The test runs and screenshots used Claude Sonnet 5. The mod itself doesn't call a model.
  • Prompt(s): the mod started as one of ten ideas Claude wrote for mods. This is the idea as written:

Replay Theater. Scrub through what Claude just did. After a turn, a pane opens with a timeline of every edit. Buttons step forward and back, and each step shows its diff. It uses ui.render on Pane, with Button elements, and it records each edit from tool.call. It builds on the built-in diff mod. A developer would install it to review a long run in a minute, and it makes a strong demo clip. A bigger project, because the timeline needs its own state.

The build prompt, which picked this idea and two others by number:

implement 1,2,7. give me zips for them. test them in claude code and get me screenshots of what they look like when used.

  • Transcript: not shared. The build ran in an internal workspace.
  • Iterations:
  • The idea had the pane open by itself after each turn. The built mod shows a one-line hint above the prompt instead, and opens the pane when you ask for it with /replay or the Replay button.
  • A pane only takes the keyboard while nothing else holds it. When the band's Replay button is pressed, the band holds the keys, so the mod hides the band and waits briefly before it opens the pane.
  • A Write can replace a whole file, so the diff keeps only one line of context around each change, and caps each step at 12 lines.
  • Tested in Claude Code: a rename across three files made 5 edits, and the pane stepped through all of them with Prev, Next and Close. A Write of a new file showed as one step.

Run it

Requirements:

  • Claude Code 2.1.287 or later, where mods load by default. The mod was built and tested on 2.1.280, and claude plugin validate passes on 2.1.285.
  • A terminal. The pane is placed inline above the prompt, or docked to the right in the fullscreen layout.

No environment variables or configuration.

Steps:

  1. Clone this repository and go to this folder's parent:
   git clone https://github.com/anthropics/claude-code-playground.git
   cd claude-code-playground/claude-code/mods
  1. Check the plugin:
   claude plugin validate ./replay-theater
  1. Try it for one session:
   claude --plugin-dir ./replay-theater

Or install it, with the other mods here, from the local marketplace in this folder (see the mods README):

   claude plugin marketplace add ./
   claude plugin install replay-theater@claude-code-playground-mods --scope user
  1. Ask Claude for a change that edits files, for example "rename the function greet to welcome everywhere".
  2. When the turn ends, open the replay in one of two ways:
  3. Type /replay and press Enter.
  4. Press ctrl+x then Tab to focus the band above the prompt, then press r (or Enter on the Replay button).
  5. In the pane:
KeyDoes
nNext step
pPrevious step
c or EscapeClose the pane

Mouse clicks on the buttons work too. The replay stays available until the next turn that edits files. A turn with no edits keeps the previous replay.

Notes / limitations

  • The diff shows up to 12 lines per step, then "… N more lines". Unchanged lines are kept only next to a change, and a skipped run shows as "⋯".
  • For Edit, the diff is between old_string and new_string, not the whole file. The file's line numbers aren't shown.
  • For Write, the old text is read from disk just before the write. Files over 400 lines are shown as all removed, then all added, with no line matching.
  • Edits are recorded when the tool is called. An edit that you then deny, or that fails, still shows in the replay.
  • The replay is kept in memory for the current session only. It is lost when Claude Code restarts, or when the plugin reloads.
  • Edits made by subagents are included in the main turn's replay.
  • Claude Code 2.1.280 has no MultiEdit tool. The mod handles MultiEdit, one step per edit, for builds that have it. That path is untested.
  • If the terminal can't place a pane, the replay is drawn in the band above the prompt instead. That fallback is untested, because every width we tried (80 and 120 columns) placed the pane.
  • The band above the prompt is shared. If another mod also draws there, only one of them shows.

Dependencies

NameVersionLicense (SPDX)Source
None

Third-party notices

None.


Shared as-is as part of claude-code-playground. Not an official Anthropic product; no support or maintenance is implied. See the root README and LICENSE.

Source 1 files
hooks/replay-theater.mjs 331 lines
1// Copyright 2026 Anthropic PBC
2// SPDX-License-Identifier: Apache-2.0
3//
4// Replay Theater: records the file edits Claude makes in a turn, then lets you
5// step through them in a pane, one diff at a time.
6//
7// Claude Code 2.1.280 function hooks. Load with --plugin-dir.
8//
9// Changed by Ben AI (2026-10): added the /mods switchboard support below
10// (turn off and hide via ~/.claude/mods/switches.json). The rest is Anthropic's original.
11
12const PANE_ID = "replay-theater";
13const MAX_DIFF_LINES = 12;
14const MAX_LCS_LINES = 400;
15const EDIT_TOOLS = new Set(["Edit", "Write", "MultiEdit"]);
16
17// Module state. `pending` fills during a turn; `replay` is the last finished
18// turn's steps, the ones the pane shows.
19const state = { pending: [], replay: [], index: 0, isOpen: false, inBand: false, turns: 0 };
20
21// The /mods switchboard turns this mod off in every chat with switches.json.
22// "replay-theater:hidden": true in the same file hides the hint band and closes the pane.
23const NAME = "replay-theater";
24const HIDE_KEY = `${NAME}:hidden`;
25const POLL_MS = 3000;
26const sw = { off: false, hidden: false, sid: "" };
27
28const homeOf = ($) => $.plugin.root.split("/.claude/")[0] || "";
29const switchesPath = ($) => `${homeOf($)}/.claude/mods/switches.json`;
30
31async function readSwitches($) {
32  const path = switchesPath($);
33  if (!(await $.fs.exists(path))) return {};
34  const json = JSON.parse(String(await $.fs.read(path)));
35  return json && typeof json === "object" && !Array.isArray(json) ? json : {};
36}
37
38async function readSwitch($) {
39  let nowOff = sw.off, nowHidden = sw.hidden;
40  try {
41    const json = await readSwitches($);
42    nowOff = json[NAME] === false;
43    nowHidden = json[HIDE_KEY] === true;
44  } catch { /* a broken or missing file changes nothing */ }
45  if (nowOff === sw.off && nowHidden === sw.hidden) return;
46  const closing = (nowOff && !sw.off) || (nowHidden && !sw.hidden);
47  sw.off = nowOff;
48  sw.hidden = nowHidden;
49  if (closing && state.isOpen) {
50    state.isOpen = false;
51    state.inBand = false;
52    await Promise.resolve($.ui.close({ id: PANE_ID })).catch(() => undefined);
53  }
54  $.ui.invalidate("ui.render");
55}
56
57// Read, change, write the whole file, so every chat sees the choice within 3 s.
58async function setHidden($, value) {
59  try {
60    const json = await readSwitches($).catch(() => ({}));
61    if (value) json[HIDE_KEY] = true;
62    else delete json[HIDE_KEY];
63    await $.process.run(["mkdir", "-p", `${homeOf($)}/.claude/mods`]);
64    await $.fs.write(switchesPath($), `${JSON.stringify(json, null, 2)}\n`);
65  } catch { /* the in-memory flag still changes */ }
66  sw.hidden = value;
67}
68
69// The /mods switchboard asks for the pane by leaving an empty file for this chat.
70async function checkOpen($) {
71  if (!sw.sid) return;
72  const path = `${homeOf($)}/.claude/mods/.open-${NAME}-${sw.sid}`;
73  try {
74    if (!(await $.fs.exists(path))) return;
75    await $.process.run(["rm", "-f", path]);
76    if (sw.off) return;
77    const opened = await openReplay($);
78    if (!opened) $.ui.toast("Replay Theater: no edits in the last turn yet.");
79  } catch { /* try again on the next poll */ }
80}
81
82async function poll($) {
83  await readSwitch($);
84  await checkOpen($);
85}
86
87function relPath(cwd, path) {
88  if (!path) return "(unknown file)";
89  if (cwd && path.startsWith(cwd + "/")) return path.slice(cwd.length + 1);
90  return path;
91}
92
93function splitLines(text) {
94  if (text === undefined || text === null || text === "") return [];
95  const lines = String(text).split("\n");
96  if (lines.length > 1 && lines[lines.length - 1] === "") lines.pop();
97  return lines;
98}
99
100// A line diff. Small inputs get an LCS diff, so unchanged lines show as
101// context; large ones fall back to all-removed then all-added.
102function diffLines(oldText, newText) {
103  const a = splitLines(oldText);
104  const b = splitLines(newText);
105  if (a.length > MAX_LCS_LINES || b.length > MAX_LCS_LINES) {
106    return [...a.map((t) => ({ op: "-", t })), ...b.map((t) => ({ op: "+", t }))];
107  }
108  const n = a.length, m = b.length;
109  const dp = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));
110  for (let i = n - 1; i >= 0; i--)
111    for (let j = m - 1; j >= 0; j--)
112      dp[i][j] = a[i] === b[j] ? dp[i + 1][j + 1] + 1 : Math.max(dp[i + 1][j], dp[i][j + 1]);
113  const out = [];
114  let i = 0, j = 0;
115  while (i < n && j < m) {
116    if (a[i] === b[j]) { out.push({ op: " ", t: a[i] }); i++; j++; }
117    else if (dp[i + 1][j] >= dp[i][j + 1]) out.push({ op: "-", t: a[i++] });
118    else out.push({ op: "+", t: b[j++] });
119  }
120  while (i < n) out.push({ op: "-", t: a[i++] });
121  while (j < m) out.push({ op: "+", t: b[j++] });
122  return trimContext(out);
123}
124
125// Keep one line of context around each change, so a long file's Write shows
126// the changed lines, not the whole file.
127function trimContext(lines) {
128  if (!lines.some((l) => l.op !== " ")) return lines.slice(0, MAX_DIFF_LINES);
129  const keep = lines.map((l, k) =>
130    l.op !== " " || lines[k - 1]?.op && lines[k - 1].op !== " " || lines[k + 1]?.op && lines[k + 1].op !== " ");
131  const out = [];
132  let skipped = false;
133  lines.forEach((l, k) => {
134    if (keep[k]) { if (skipped && out.length) out.push({ op: "~", t: "⋯" }); out.push(l); skipped = false; }
135    else skipped = true;
136  });
137  return out;
138}
139
140function countChanges(diff) {
141  let add = 0, del = 0;
142  for (const l of diff) { if (l.op === "+") add++; else if (l.op === "-") del++; }
143  return { add, del };
144}
145
146// Turns one tool call into one or more steps.
147async function stepsFor($, e) {
148  let cwd = "";
149  try { cwd = await $.session.cwd(); } catch { /* keep the full path */ }
150  const file = relPath(cwd, e.file_path);
151  if (e.tool === "Edit") {
152    return [{ tool: "Edit", file, diff: diffLines(e.old_string, e.new_string), note: e.replace_all ? "replace all" : "" }];
153  }
154  if (e.tool === "MultiEdit" && Array.isArray(e.edits)) {
155    return e.edits.map((ed, k) => ({
156      tool: "MultiEdit", file, diff: diffLines(ed.old_string, ed.new_string), note: `edit ${k + 1} of ${e.edits.length}`,
157    }));
158  }
159  if (e.tool === "Write") {
160    let before = "";
161    let isNew = true;
162    try {
163      if (e.file_path && (await $.fs.exists(e.file_path))) {
164        before = await $.fs.read(e.file_path);
165        isNew = false;
166      }
167    } catch { /* unreadable: show it as a new file */ }
168    return [{ tool: "Write", file, diff: diffLines(before, e.content), note: isNew ? "new file" : "rewrite" }];
169  }
170  return [];
171}
172
173function hintText() {
174  const n = state.replay.length;
175  return `▶ Replay: ${n} edit${n === 1 ? "" : "s"} (press r)`;
176}
177
178async function openReplay($) {
179  if (!state.replay.length) return false;
180  state.index = 0;
181  state.isOpen = true;
182  // The pane only takes the keyboard while nothing else holds it. Hide the
183  // band first (it held the keys if its button was pressed), then open.
184  $.ui.invalidate("ui.render");
185  await $.clock.sleep(200);
186  const rows = Math.min(MAX_DIFF_LINES + 8, 22);
187  const placed = await $.ui.open({ id: PANE_ID, title: "Replay Theater", focus: true, closeOnEscape: true, rows, columns: 58 });
188  // No room for a pane (a narrow terminal): draw the replay in the band.
189  state.inBand = placed?.isPlaced === false;
190  $.ui.invalidate("ui.render");
191  return true;
192}
193
194// The replay view: one step at a time. Drawn in the Pane, or in the band
195// above the prompt when the surface can't place a pane.
196function replayView($, e, inBand) {
197    const { Box, Text, Button } = $.ui.resolve(e);
198    const maxDiff = inBand ? Math.max(3, Math.min(MAX_DIFF_LINES, (e.maxRows || 20) - 7)) : MAX_DIFF_LINES;
199    const total = state.replay.length;
200    if (!total) return Text({ dimColor: true, children: "No edits to replay." });
201    const k = Math.max(0, Math.min(state.index, total - 1));
202    const step = state.replay[k];
203    const width = Math.max(40, (e.bodyColumns || 100) - 4);
204    const { add, del } = countChanges(step.diff);
205    const shown = step.diff.slice(0, maxDiff);
206
207    const diffRows = shown.map((l, n) => {
208      const color = l.op === "+" ? "green" : l.op === "-" ? "red" : undefined;
209      const line = `${l.op === "~" ? " " : l.op} ${l.t}`.slice(0, width);
210      return Text({ key: `d${n}`, color, dimColor: l.op === " " || l.op === "~", wrap: "truncate-end", children: line });
211    });
212    if (step.diff.length > maxDiff) diffRows.push(Text({ key: "more", dimColor: true, children: `  … ${step.diff.length - maxDiff} more lines` }));
213    if (!shown.length) diffRows.push(Text({ key: "empty", dimColor: true, children: "  (no line changes)" }));
214
215    // The step list: one cell per step, the current one highlighted.
216    const strip = state.replay.map((s, n) =>
217      Text({ key: `s${n}`, inverse: n === k, color: n === k ? "cyan" : undefined, dimColor: n !== k, children: ` ${n + 1} ` }));
218
219    const go = (to) => { state.index = Math.max(0, Math.min(to, total - 1)); $.ui.invalidate("ui.render"); };
220    const close = () => {
221      state.isOpen = false;
222      if (!state.inBand) $.ui.close({ id: PANE_ID });
223      state.inBand = false;
224      $.ui.invalidate("ui.render");
225    };
226
227    return Box({
228      flexDirection: "column", borderStyle: "round", borderColor: "magenta", paddingX: 1,
229      children: [
230        Box({ flexDirection: "row", justifyContent: "space-between", children: [
231          Text({ bold: true, color: "magenta", children: "▶ Replay Theater" }),
232          Text({ bold: true, children: `step ${k + 1} of ${total}` }),
233        ] }),
234        Box({ flexDirection: "row", children: strip }),
235        Text({ bold: true, color: "cyan", wrap: "truncate-start", children: step.file }),
236        Box({ flexDirection: "row", gap: 2, children: [
237          Text({ dimColor: true, children: `${step.tool}${step.note ? " · " + step.note : ""}` }),
238          Text({ color: "green", children: `+${add}` }),
239          Text({ color: "red", children: `-${del}` }),
240        ] }),
241        Box({ flexDirection: "column", marginTop: 1, children: diffRows }),
242        Box({ flexDirection: "row", gap: 2, marginTop: 1, children: [
243          Button({ key: "prev", label: "◀ Prev", hotkey: "p", onPress: () => go(k - 1) }),
244          Button({ key: "next", label: "Next ▶", hotkey: "n", autoFocus: true, onPress: () => go(k + 1) }),
245          Button({ key: "close", label: "Close", hotkey: "c", onPress: close }),
246        ] }),
247      ],
248    });
249}
250
251export function register(on, options) {
252  // Slash command: /replay opens the pane.
253  on("session.start", async ($, e, next) => {
254    const r = await next(e);
255    try {
256      sw.sid = await $.session.id();
257      await $.command.register({ name: "replay", description: "Replay Theater: step through the last turn's file edits" });
258      await poll($).catch(() => undefined);
259      $.clock.every(POLL_MS, () => { void poll($).catch(() => undefined); });
260    } catch { /* the mod still records */ }
261    return r;
262  });
263
264  on("command.run", { command: "replay" }, async ($, e) => {
265    if (sw.off) return { text: "Replay Theater is off. Turn it on with /mods." };
266    if (sw.hidden) await setHidden($, false);
267    const opened = await openReplay($);
268    return { text: opened ? `Replay Theater: ${state.replay.length} edits` : "Replay Theater: no edits in the last turn." };
269  });
270
271  // Record each edit, then let it run. Never blocks the call.
272  on("tool.call", async ($, e, next) => {
273    if (!sw.off && EDIT_TOOLS.has(e.tool)) {
274      try {
275        const steps = await stepsFor($, e);
276        state.pending.push(...steps);
277      } catch { /* recording must never stop the edit */ }
278    }
279    return next(e);
280  });
281
282  on("turn.start", ($, e, next) => {
283    if (!e.agentId) state.pending = [];
284    return next(e);
285  });
286
287  // At the end of a main-loop turn, the pending edits become the replay.
288  on("turn.complete", async ($, e, next) => {
289    const r = await next(e);
290    if (sw.off || e.agentId || !state.pending.length) return r;
291    state.replay = state.pending;
292    state.pending = [];
293    state.index = 0;
294    state.turns++;
295    $.ui.invalidate("ui.render");
296    return r;
297  });
298
299  // The band above the prompt: the hint and a button that opens the pane.
300  // Local change (Ben AI, 2026-10-16): draw the other mods' bands first, so
301  // this band sits under them instead of replacing them.
302  on("ui.render", { component: "AbovePrompt" }, async ($, e, next) => {
303    if (sw.off || sw.hidden) return next(e);
304    if (state.isOpen && state.inBand) return replayView($, e, true);
305    if (!state.replay.length || state.isOpen) return next(e);
306    const rest = await next(e);
307    const { Box, Text, Button } = $.ui.resolve(e);
308    const band = Box({
309      key: "replay-band", flexDirection: "row", gap: 2, paddingX: 1,
310      children: [
311        Text({ color: "magenta", bold: true, children: hintText() }),
312        Button({ key: "open-replay", label: "Replay", hotkey: "r", onPress: () => openReplay($) }),
313      ],
314    });
315    return rest ? Box({ flexDirection: "column", children: [rest, band] }) : band;
316  });
317
318  // The pane.
319  on("ui.render", { component: "Pane" }, ($, e, next) => {
320    if (e.requestId !== PANE_ID || sw.off) return next(e);
321    return replayView($, e, false);
322  });
323
324  // The person closed the pane (Escape): keep our flag in step.
325  on("ui.close", ($, e, next) => {
326    if (e.id === PANE_ID || e.requestId === PANE_ID) state.isOpen = false;
327    $.ui.invalidate("ui.render");
328    return next(e);
329  });
330}
331