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

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.
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:
tool.call and always passing the call on with next(e).turn.start and turn.complete, and skipping subagent turns./replay) registered from session.start and handled in command.run.Pane with Button elements and hotkeys, with a fallback to the AbovePrompt band.After a rename, the hint above the prompt:

The pane, on step 1 of 5:

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

Inline above the prompt in an 80-column terminal:

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.renderonPane, withButtonelements, and it records each edit fromtool.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.
/replay or the Replay button.Requirements:
claude plugin validate passes on 2.1.285.No environment variables or configuration.
Steps:
git clone https://github.com/anthropics/claude-code-playground.git
cd claude-code-playground/claude-code/mods
claude plugin validate ./replay-theater
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
/replay and press Enter.ctrl+x then Tab to focus the band above the prompt, then press r (or Enter on the Replay button).| Key | Does |
|---|---|
n | Next step |
p | Previous step |
c or Escape | Close 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.
old_string and new_string, not the whole file. The file's line numbers aren't shown.| Name | Version | License (SPDX) | Source |
|---|---|---|---|
| None |
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.
anthropics/claude-code-playground의 claude-code/mods/replay-theater를 수정한 버전입니다. Copyright 2026 Anthropic PBC, Apache License 2.0. 변경 내역은 저장소 루트의 NOTICE를 참고하세요. Anthropic 공식 배포물이 아닙니다.
hooks/replay-theater.mjs 260 lines1// Copyright 2026 Anthropic PBC
2// SPDX-License-Identifier: Apache-2.0
3// Modified 2026 by suhoon (Windows port / display changes). Original: https://github.com/anthropics/claude-code-playground — see NOTICE.
4//
5// Replay Theater: records the file edits Claude makes in a turn, then lets you
6// step through them in a pane, one diff at a time.
7//
8// Claude Code 2.1.280 function hooks. Load with --plugin-dir.
9
10const PANE_ID = "replay-theater";
11const MAX_DIFF_LINES = 12;
12const MAX_LCS_LINES = 400;
13const EDIT_TOOLS = new Set(["Edit", "Write", "MultiEdit"]);
14
15// Module state. `pending` fills during a turn; `replay` is the last finished
16// turn's steps, the ones the pane shows.
17const state = { pending: [], replay: [], index: 0, isOpen: false, inBand: false, turns: 0 };
18
19function relPath(cwd, path) {
20 if (!path) return "(unknown file)";
21 const normalized = String(path).replaceAll("\\", "/");
22 const base = String(cwd || "").replaceAll("\\", "/").replace(/\/$/, "");
23 const isWindows = /^[a-z]:\//i.test(base);
24 const candidate = isWindows ? normalized.toLowerCase() : normalized;
25 const prefix = isWindows ? base.toLowerCase() : base;
26 if (base && candidate.startsWith(prefix + "/")) return normalized.slice(base.length + 1);
27 return normalized;
28}
29
30function splitLines(text) {
31 if (text === undefined || text === null || text === "") return [];
32 const lines = String(text).split(/\r?\n/);
33 if (lines.length > 1 && lines[lines.length - 1] === "") lines.pop();
34 return lines;
35}
36
37// A line diff. Small inputs get an LCS diff, so unchanged lines show as
38// context; large ones fall back to all-removed then all-added.
39function diffLines(oldText, newText) {
40 const a = splitLines(oldText);
41 const b = splitLines(newText);
42 if (a.length > MAX_LCS_LINES || b.length > MAX_LCS_LINES) {
43 return [...a.map((t) => ({ op: "-", t })), ...b.map((t) => ({ op: "+", t }))];
44 }
45 const n = a.length, m = b.length;
46 const dp = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));
47 for (let i = n - 1; i >= 0; i--)
48 for (let j = m - 1; j >= 0; j--)
49 dp[i][j] = a[i] === b[j] ? dp[i + 1][j + 1] + 1 : Math.max(dp[i + 1][j], dp[i][j + 1]);
50 const out = [];
51 let i = 0, j = 0;
52 while (i < n && j < m) {
53 if (a[i] === b[j]) { out.push({ op: " ", t: a[i] }); i++; j++; }
54 else if (dp[i + 1][j] >= dp[i][j + 1]) out.push({ op: "-", t: a[i++] });
55 else out.push({ op: "+", t: b[j++] });
56 }
57 while (i < n) out.push({ op: "-", t: a[i++] });
58 while (j < m) out.push({ op: "+", t: b[j++] });
59 return trimContext(out);
60}
61
62// Keep one line of context around each change, so a long file's Write shows
63// the changed lines, not the whole file.
64function trimContext(lines) {
65 if (!lines.some((l) => l.op !== " ")) return lines.slice(0, MAX_DIFF_LINES);
66 const keep = lines.map((l, k) =>
67 l.op !== " " || lines[k - 1]?.op && lines[k - 1].op !== " " || lines[k + 1]?.op && lines[k + 1].op !== " ");
68 const out = [];
69 let skipped = false;
70 lines.forEach((l, k) => {
71 if (keep[k]) { if (skipped && out.length) out.push({ op: "~", t: "⋯" }); out.push(l); skipped = false; }
72 else skipped = true;
73 });
74 return out;
75}
76
77function countChanges(diff) {
78 let add = 0, del = 0;
79 for (const l of diff) { if (l.op === "+") add++; else if (l.op === "-") del++; }
80 return { add, del };
81}
82
83// Turns one tool call into one or more steps.
84async function stepsFor($, e) {
85 let cwd = "";
86 try { cwd = await $.session.cwd(); } catch { /* keep the full path */ }
87 const file = relPath(cwd, e.file_path);
88 if (e.tool === "Edit") {
89 return [{ tool: "Edit", file, diff: diffLines(e.old_string, e.new_string), note: e.replace_all ? "replace all" : "" }];
90 }
91 if (e.tool === "MultiEdit" && Array.isArray(e.edits)) {
92 return e.edits.map((ed, k) => ({
93 tool: "MultiEdit", file, diff: diffLines(ed.old_string, ed.new_string), note: `edit ${k + 1} of ${e.edits.length}`,
94 }));
95 }
96 if (e.tool === "Write") {
97 let before = "";
98 let isNew = true;
99 try {
100 if (e.file_path && (await $.fs.exists(e.file_path))) {
101 before = await $.fs.read(e.file_path);
102 isNew = false;
103 }
104 } catch { /* unreadable: show it as a new file */ }
105 return [{ tool: "Write", file, diff: diffLines(before, e.content), note: isNew ? "new file" : "rewrite" }];
106 }
107 return [];
108}
109
110function hintText() {
111 const n = state.replay.length;
112 return `▶ Replay: ${n} edit${n === 1 ? "" : "s"} (press r)`;
113}
114
115async function openReplay($) {
116 if (!state.replay.length) return false;
117 state.index = 0;
118 state.isOpen = true;
119 // The pane only takes the keyboard while nothing else holds it. Hide the
120 // band first (it held the keys if its button was pressed), then open.
121 $.ui.invalidate("ui.render");
122 await $.clock.sleep(200);
123 const rows = Math.min(MAX_DIFF_LINES + 8, 22);
124 const placed = await $.ui.open({ id: PANE_ID, title: "Replay Theater", focus: true, closeOnEscape: true, rows, columns: 58 });
125 // No room for a pane (a narrow terminal): draw the replay in the band.
126 state.inBand = placed?.isPlaced === false;
127 $.ui.invalidate("ui.render");
128 return true;
129}
130
131// The replay view: one step at a time. Drawn in the Pane, or in the band
132// above the prompt when the surface can't place a pane.
133function replayView($, e, inBand) {
134 const { Box, Text, Button } = $.ui.resolve(e);
135 const maxDiff = inBand ? Math.max(3, Math.min(MAX_DIFF_LINES, (e.maxRows || 20) - 7)) : MAX_DIFF_LINES;
136 const total = state.replay.length;
137 if (!total) return Text({ dimColor: true, children: "No edits to replay." });
138 const k = Math.max(0, Math.min(state.index, total - 1));
139 const step = state.replay[k];
140 const width = Math.max(40, (e.bodyColumns || 100) - 4);
141 const { add, del } = countChanges(step.diff);
142 const shown = step.diff.slice(0, maxDiff);
143
144 const diffRows = shown.map((l, n) => {
145 const color = l.op === "+" ? "green" : l.op === "-" ? "red" : undefined;
146 const line = `${l.op === "~" ? " " : l.op} ${l.t}`.slice(0, width);
147 return Text({ key: `d${n}`, color, dimColor: l.op === " " || l.op === "~", wrap: "truncate-end", children: line });
148 });
149 if (step.diff.length > maxDiff) diffRows.push(Text({ key: "more", dimColor: true, children: ` … ${step.diff.length - maxDiff} more lines` }));
150 if (!shown.length) diffRows.push(Text({ key: "empty", dimColor: true, children: " (no line changes)" }));
151
152 // The step list: one cell per step, the current one highlighted.
153 const strip = state.replay.map((s, n) =>
154 Text({ key: `s${n}`, inverse: n === k, color: n === k ? "cyan" : undefined, dimColor: n !== k, children: ` ${n + 1} ` }));
155
156 const go = (to) => { state.index = Math.max(0, Math.min(to, total - 1)); $.ui.invalidate("ui.render"); };
157 const close = () => {
158 state.isOpen = false;
159 if (!state.inBand) $.ui.close({ id: PANE_ID });
160 state.inBand = false;
161 $.ui.invalidate("ui.render");
162 };
163
164 return Box({
165 flexDirection: "column", borderStyle: "round", borderColor: "magenta", paddingX: 1,
166 children: [
167 Box({ flexDirection: "row", justifyContent: "space-between", children: [
168 Text({ bold: true, color: "magenta", children: "▶ Replay Theater" }),
169 Text({ bold: true, children: `step ${k + 1} of ${total}` }),
170 ] }),
171 Box({ flexDirection: "row", children: strip }),
172 Text({ bold: true, color: "cyan", wrap: "truncate-start", children: step.file }),
173 Box({ flexDirection: "row", gap: 2, children: [
174 Text({ dimColor: true, children: `${step.tool}${step.note ? " · " + step.note : ""}` }),
175 Text({ color: "green", children: `+${add}` }),
176 Text({ color: "red", children: `-${del}` }),
177 ] }),
178 Box({ flexDirection: "column", marginTop: 1, children: diffRows }),
179 Box({ flexDirection: "row", gap: 2, marginTop: 1, children: [
180 Button({ key: "prev", label: "◀ Prev", hotkey: "p", onPress: () => go(k - 1) }),
181 Button({ key: "next", label: "Next ▶", hotkey: "n", autoFocus: true, onPress: () => go(k + 1) }),
182 Button({ key: "close", label: "Close", hotkey: "c", onPress: close }),
183 ] }),
184 ],
185 });
186}
187
188export function register(on, options) {
189 // Slash command: /replay opens the pane.
190 on("session.start", async ($, e, next) => {
191 const r = await next(e);
192 await $.command.register({ name: "replay", description: "Replay Theater: step through the last turn's file edits" });
193 return r;
194 });
195
196 on("command.run", { command: "replay" }, async ($, e) => {
197 const opened = await openReplay($);
198 return { text: opened ? `Replay Theater: ${state.replay.length} edits` : "Replay Theater: no edits in the last turn." };
199 });
200
201 // Record each edit, then let it run. Never blocks the call.
202 on("tool.call", async ($, e, next) => {
203 if (EDIT_TOOLS.has(e.tool)) {
204 try {
205 const steps = await stepsFor($, e);
206 state.pending.push(...steps);
207 } catch { /* recording must never stop the edit */ }
208 }
209 return next(e);
210 });
211
212 on("turn.start", ($, e, next) => {
213 if (!e.agentId) state.pending = [];
214 return next(e);
215 });
216
217 // At the end of a main-loop turn, the pending edits become the replay.
218 on("turn.complete", async ($, e, next) => {
219 const r = await next(e);
220 if (e.agentId || !state.pending.length) return r;
221 state.replay = state.pending;
222 state.pending = [];
223 state.index = 0;
224 state.turns++;
225 $.ui.invalidate("ui.render");
226 return r;
227 });
228
229 // The band above the prompt: the hint and a button that opens the pane,
230 // stacked over what the plugins beneath draw (token-weather's light) so the
231 // hint never hides another mod's row.
232 on("ui.render", { component: "AbovePrompt" }, async ($, e, next) => {
233 if (state.isOpen && state.inBand) return replayView($, e, true);
234 if (!state.replay.length || state.isOpen) return next(e);
235 const { Box, Text, Button } = $.ui.resolve(e);
236 const below = await next(e);
237 const hint = Box({
238 flexDirection: "row", gap: 2, paddingX: 1,
239 children: [
240 Text({ color: "magenta", bold: true, children: hintText() }),
241 Button({ key: "open-replay", label: "Replay", hotkey: "r", onPress: () => openReplay($) }),
242 ],
243 });
244 return below ? Box({ flexDirection: "column", children: [hint, below] }) : hint;
245 });
246
247 // The pane.
248 on("ui.render", { component: "Pane" }, ($, e, next) => {
249 if (e.requestId !== PANE_ID) return next(e);
250 return replayView($, e, false);
251 });
252
253 // The person closed the pane (Escape): keep our flag in step.
254 on("ui.close", ($, e, next) => {
255 if (e.id === PANE_ID || e.requestId === PANE_ID) state.isOpen = false;
256 $.ui.invalidate("ui.render");
257 return next(e);
258 });
259}
260