Sep 27, 2026 • 5 min read
Recording and Replaying Terminal Sessions with asciinema
The Problem
Screen recordings of terminal workflows often turn into bulky video files with fuzzy text, awkward window cropping, and no way for readers to pause, copy commands, or resize cleanly. When you are writing technical documentation, tutorials, or bug reports, capturing pixels instead of terminal text makes demos harder to maintain and harder to read.
Instead of recording your screen with a video capture tool, asciinema records terminal input and output as lightweight, plain-text .cast files that can be replayed directly in any terminal, embedded as an interactive web player, or converted into GIFs with tools like agg.
flowchart LR
subgraph Recording["1. Capture Session"]
Term["Terminal Session"] -->|"asciinema rec"| CastFile["session-demo.cast"]
end
subgraph Sharing["2. Replay & Share"]
CastFile -->|"asciinema play"| Replay["Terminal Playback"]
CastFile -->|"asciinema upload"| Web["asciinema.org / Embed"]
end
- The walkthrough below includes a self-contained
session-demo.castsample so you can test playback and flags right away without recording a live session first.
Technical Solution Overview
Getting clean, repeatable terminal recordings works best as a two-step workflow: start with a small session-demo.cast recording to verify playback and timing controls, then record real sessions with clean pacing, metadata, and sharing options.
flowchart LR
Step1["Step 1: Sample session-demo.cast
& Terminal Playback"] --> Step2["Step 2: Recording, Pacing
& Sharing Workflows"]
- Save the following sample
asciinemarecording assession-demo.cast:
{"version": 2, "width": 80, "height": 18, "title": "asciinema demo"}
[0.2, "o", "\u001b[1;32muser@host\u001b[0m:\u001b[1;34m~\u001b[0m$ "]
[0.9, "o", "echo \"Hello from asciinema\"\r\n"]
[1.1, "o", "Hello from asciinema\r\n"]
[1.5, "o", "\u001b[1;32muser@host\u001b[0m:\u001b[1;34m~\u001b[0m$ "]
[2.4, "o", "uname -s\r\n"]
[2.6, "o", "\u001b[36mLinux\u001b[0m\r\n"]
[3.0, "o", "\u001b[1;32muser@host\u001b[0m:\u001b[1;34m~\u001b[0m$ "]Pro-Tip: Piping and Remote Recordings
- You can pass a local
.castfile, read from standard input (-), or replay a remote recording directly by URL in your terminal:
cat session-demo.cast | asciinema play -- Because
.castfiles store real terminal text and escape sequences rather than video frames, viewers can select and copy text directly from an embedded player.
Step 1: Sample session-demo.cast and Terminal Playback
An asciinema recording is newline-delimited JSON: the first line is a JSON header describing terminal dimensions and metadata, and each subsequent line is an event array [time, event_code, data].
flowchart LR
Cast["session-demo.cast
(header + 'o' events)"] -->|"asciinema play"| TermOut["Live Terminal Replay
(Space: pause, Ctrl+C: exit)"]
- Confirm
asciinemais installed and inspect available subcommands:
asciinema --help- Replay
session-demo.castdirectly inside your terminal (pressSpaceto pause/resume orCtrl+Cto stop early):
asciinema play session-demo.castExpected Input & Output
- Input (
session-demo.cast): An 80x18 recording spanning roughly 3 seconds with ANSI color escape sequences (\u001b[1;32m,\u001b[1;34m,\u001b[36m) and"o"(output) events. - Output (Terminal Playback): Replays the prompt,
echo "Hello from asciinema",Hello from asciinema,uname -s, andLinuxwith color formatting preserved.
Step 2: Recording Sessions, Trimming Idle Time, and Sharing
Once you know how playback behaves, use asciinema rec to capture your own commands, trim long pauses, and decide whether to keep files local, share them online, or stream live.
flowchart LR
Rec["asciinema rec
(-i, -c, -t)"] --> File["my-guide.cast"]
File --> Share["asciinema upload
or asciinema stream"]
- Record an Interactive Shell or Single Command (
asciinema rec): Runasciinema recwith a filename to record your shell until you pressCtrl+Dor typeexit, or pass-c/--commandto record a single command and exit automatically when it finishes:
asciinema rec -c "uname -a" command-demo.cast- Trim Long Pauses with Idle Time Limits (
-i/--idle-time-limit): Long pauses while thinking or waiting on a command can slow down a demo. Pass-i(in seconds) during recording or playback to cap inactivity gaps:
asciinema rec -i 2 -t "Quick CLI Walkthrough" paced-demo.cast- Adjust Playback Speed (
-s/--speed): Speed up or slow down a recording during local replay without altering the original.castfile:
asciinema play -s 1.5 -i 2 session-demo.cast- Upload or Live Stream (
asciinema uploadandasciinema stream): Upload a.castfile to get a shareable web link (and runasciinema authto link recordings to yourasciinema.orgaccount), or stream a session live:
asciinema upload paced-demo.castNote: Recordings uploaded anonymously without linking your CLI via
asciinema authmay only be retained temporarily onasciinema.org(for example, unlinked uploads are removed after 7 days), so authenticate if you want long-term account management. Also, keep your terminal window at least as wide and tall as the recorded dimensions for clean playback.
Key asciinema Commands and Options Reference
| Command / Option | Purpose | Example / Notes |
|---|---|---|
asciinema rec <file> |
Records a terminal session to a .cast file |
Ends with Ctrl+D or exit |
-c, --command |
Runs and records a specific command instead of $SHELL |
asciinema rec -c "htop" top.cast |
-i, --idle-time-limit |
Caps recorded or replayed pauses to <sec> seconds |
asciinema rec -i 2 demo.cast |
-t, --title |
Sets a title metadata field in the recording | asciinema rec -t "Setup Demo" demo.cast |
asciinema play <file> |
Replays a local .cast file or URL in the terminal |
Supports -s (--speed) and -i |
asciinema upload <file> |
Uploads a .cast file and prints a web URL |
Pair with asciinema auth to keep ownership |
asciinema stream |
Streams a terminal session live (-r remote, -l local) |
Available in asciinema CLI 3.0+ |
Conclusion
Using asciinema lets you capture terminal workflows as small, editable text recordings rather than heavy video files, giving readers crisp playback and copyable terminal output. Combining asciinema rec with -i idle-time limits and asciinema play makes it easy to test and refine command demos before publishing them to your docs or blog.
Whether you are documenting a CLI tool, walking teammates through a deployment, or preparing a .cast file to render into a GIF with agg, asciinema gives you a fast, scriptable foundation for terminal demos.