Everything below comes from recording one subject: a Claude Code panel that shows three background agents running at once. Six rules, each one paid for by a run that produced a file nobody could use.
The three posts before this one are about an agent seeing its own work so it builds the right thing: the general loop, a zellij plugin under a pty, and a site under Playwright. The agent reads a grid of cells or an accessibility tree, asserts on it, and the artifact is thrown away.
This one runs the same tools backwards. The artifact is the point: a GIF for a README, an MP4 for a post, a clip of a simulator. Nobody else reads your cell dump. They watch the 20 seconds you hand them.
Record a master, encode from it afterwards
The expensive part of a demo is the live run. For me it was a real Claude Code session spawning three subagents, which costs money and finishes when it finishes.
So do not record a GIF off the live run. Record an
asciicast, which is a JSON lines file
of timestamped output. tui-test 0.1.1, released
23 October 2026, writes one:
tui-test --session demo record start demo.cast --idle-time-limit 1.0
# drive the session
tui-test --session demo record stop
My crew.cast is 317,584 bytes, 402 events, 36.3 seconds of a 110x30 session. It is
plain text and it replays. To get a video, open a throwaway session and write the
recorded bytes back into it on their original timings while a second recording runs:
# [1:] skips the header line
ev = [json.loads(l) for l in open(CAST) if l.strip()][1:]
tt("record", "start", out,
"--fps", fps, "--speed", speed, "--zoom", zoom)
start = time.time()
for t, data in groups:
time.sleep(max(0, start + t - time.time()))
tt("write", data.replace("\x00", ""))
tt("record", "stop")
Two details that matter. Bucket events that fall within about 0.2 s of each other into
one write, because each call is a process spawn and 402 of them drift the replay
longer than the original. And strip NUL bytes, which the CLI will not pass through.
The first GIF off the live session was 6.57 MB. Re-encoded from the cast at a lower fps
and --zoom 0.5 it came out at 2,752,618 bytes, with no second API call and no second
agent run. Every later experiment, every fps, every zoom, every format, came out of the
same 317 KB file.
Poll, do not sleep
The panel I wanted on camera existed for 8 seconds. I waited 20 seconds, then 40, and both runs produced a correct recording of an empty screen, for $1.17 in agent time.
Fixed delays are a bet on how long work takes, and you lose that bet in both directions: too short and the thing has not appeared, too long and it is gone. Poll for the state and start recording when you see it, or record from the start and poll for the exit:
pat = re.compile(r"(\d+)\s+agents?\b")
while time.time() - start < 90:
t = tt("text")
if pat.search(t):
seen = True
elif seen:
# subject appeared and left; stop
break
time.sleep(1.2)
This is the same rule as the positive control in the vision post, pointed at time instead of input.
Look at the frames
Two of my attempts reported a good capture. Both were empty panels. The recorder had exited 0, the file was well formed, and nothing in the run knew the screen was blank.
The agent must open the pixels. Extract a few frames and read them as images:
ffmpeg -i demo.gif -vf fps=1/3 frames/f%02d.png
I did this again while writing this post, against a freshly booted iOS simulator. The recording was 6.586667 seconds of H.264 at 1206x2622, 4,627,137 bytes, every field correct. The frames were a black rectangle on a blurred wallpaper, because Safari had not rendered by the time recording started. A valid file is not evidence of a visible subject. Only a frame is.
One recording per session
$ tui-test --session demo record start a.gif
$ tui-test --session demo record start b.cast
a recording is already active
So a GIF and a cast cannot come from the same live run, which is the other half of the argument for recording the cast: it is the one format you can turn into the rest. A second session is also the clean way to get a still while something else records.
Default zoom is 2x, and MP4 needs ffmpeg on PATH
tui-test renders at 2x device scale. For an 80x24 session, screenshot writes 878x608
and a GIF at default zoom is 1756x1216. --zoom 0.5 gives 878x608, matching the
screenshot exactly. Unless you want a retina asset, pass --zoom 0.5 and halve every
dimension.
MP4 is where the size goes. tui-test shells out for it, and without
ffmpeg on the daemon’s PATH you get:
MP4 recording requires ffmpeg to be installed and available on PATH
followed by no recording is active on stop and no file, so check for ffmpeg before the
run, not after.
The honest comparison is the same frames both ways. Taking crew.gif (1178x734, 58
frames, 17.28 s, 2,752,618 bytes) and re-encoding it with no change in geometry or frame
count:
ffmpeg -i crew.gif -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" \
-c:v libx264 -pix_fmt yuv420p -crf 23 -movflags +faststart crew.mp4
1,082,865 bytes. 2.54x smaller, 18.2 KB per frame against 46.3 KB. Note that this is a claim about encoding, not about which file is smaller on disk: the MP4 recorded straight from the same cast at default zoom and 24 fps is 2356x1468 and 6,970,999 bytes, larger than the GIF, because it carries 417 frames at four times the pixels.
Three parts of that command earn their place. yuv420p is the chroma format players
accept without complaint. scale=trunc(iw/2)*2 exists because libx264 refuses odd
dimensions:
[libx264] width not divisible by 2 (1177x733)
+faststart moves the index to the front so the file plays before it finishes
downloading.
LinkedIn’s published limits are 10 to 60 fps, 256x144 to 4096x2304, 3 seconds minimum on desktop and 75 KB minimum. Those bite in practice: a terminal GIF re-encoded at 5 fps is under the floor, and a raw iPhone 17 Pro simulator capture at 1206x2622 is over the height ceiling. I did not verify X’s spec. Encode a 3 second probe first and check it before you spend the full run; mine was 41,341 bytes and told me the geometry was right.
The web: Playwright records video itself
Playwright records video itself, and it does not need your ffmpeg; it installs its own alongside the browser:
const ctx = await browser.newContext({
viewport: { width: 1280, height: 720 },
recordVideo: { dir: 'videos/', size: { width: 1280, height: 720 } },
});
const page = await ctx.newPage();
// capture the handle before closing
const video = page.video();
// the file is finalized here
await ctx.close();
console.log(await video.path());
Two traps, both verified on Playwright 1.65.1. The file does not exist until the context
closes, so a script that reads the path too early finds nothing. And the name is a hash:
mine was page@edae6b89f8eccb2e1cf3c00f8fb8ea8a.webm. Use video.saveAs(dest) or read
path() after close.
Output is VP9 in WebM: 1280x720, 2.76 s, 42,754 bytes. WebM does not post everywhere, so run the same ffmpeg line as above. The H.264 version was 14,321 bytes.
In a test run, use: { video: 'retain-on-failure' } in the Playwright config gets you a
clip of every failure and deletes the rest.
simctl and screencapture record without extra software
For an iOS simulator, simctl records directly, and the MCP wrappers I have for it
(record_video, stop_recording, screenshot) call exactly this:
xcrun simctl io <udid> recordVideo \
--codec h264 --mask black --force out.mp4
It runs until interrupted; stop it with SIGINT, not SIGKILL, or the container is never
finalized. --mask black fills the rounded display corners instead of leaving them
transparent. --codec h264 is worth passing because the default is HEVC. Output came out
at 1206x2622, H.264, yuv420p, and a variable frame rate that ffprobe reports as 600/1,
so re-encode before uploading:
ffmpeg -i out.mp4 -vf "fps=30,scale=-2:1600" \
-c:v libx264 -pix_fmt yuv420p -crf 23 \
-movflags +faststart post.mp4
4,627,137 bytes to 273,450. scale=-2:1600 keeps the aspect ratio and forces an even
width, which is the odd-dimension rule again.
For a macOS app, screencapture records without extra software: screencapture -v -k out.mov records the screen with clicks shown, -l<windowid> records one window,
-R<x,y,w,h> a rectangle, and -V<seconds> stops on its own, which matters for an agent
that cannot press a key. Screen recording needs the permission granted to whatever
process the agent runs under, which is a one-time manual step in System Settings.
The subject has to be worth filming
The least technical rule, and the one that changed the result most. The same demo, two prompts:
- “spawn three subagents” produced one visible row at a time, 12 seconds of panel.
- “In one single message, launch exactly three subagents in parallel with the Agent tool. Each one must think carefully and write a detailed 400-word explanation of one Rust topic (ownership, traits, async) and return it. No file reads, no file edits, no commands.” produced three concurrent rows for 25 seconds.
In one single message forces one tool block instead of three sequential ones.
400-word and think carefully buy running time. No file reads, no file edits, no commands keeps permission prompts out of frame. Staging matters as much for a recording
as the encoder settings do.
When not to do any of this
If a human is recording by hand, use the tools built for that.
vhs takes a tape file of Type, Sleep, Wait
and Set commands and writes .gif, .mp4, .webm or a PNG sequence in one command,
with themes and font sizes handled.
asciinema gives a web player with selectable
text, which beats a video for anything a reader might want to copy.
terminalizer covers the same ground for
GIFs.
The machinery here is for the case those do not cover: driving a program that is already running, waiting on a state you cannot predict, and having the agent confirm it caught the thing before it ships the file. The cast is the master, the poll finds the moment, and the frame check is what stops you publishing a blank screen.