Terminal session recorder 📹

Overview

Note: This is README for development branch. See the version for latest stable release.

asciinema

Build Status PyPI license

Terminal session recorder and the best companion of asciinema.org.

demo

Quick intro

asciinema lets you easily record terminal sessions and replay them in a terminal as well as in a web browser.

Install latest version (other installation options):

sudo pip3 install asciinema

Record your first session:

asciinema rec first.cast

Now replay it with double speed:

asciinema play -s 2 first.cast

Or with normal speed but with idle time limited to 2 seconds:

asciinema play -i 2 first.cast

You can pass -i 2 to asciinema rec as well, to set it permanently on a recording. Idle time limiting makes the recordings much more interesting to watch. Try it.

If you want to watch and share it on the web, upload it:

asciinema upload first.cast

The above uploads it to asciinema.org, which is a default asciinema-server instance, and prints a secret link you can use to watch your recording in a web browser.

You can record and upload in one step by omitting the filename:

asciinema rec

You'll be asked to confirm the upload when the recording is done. Nothing is sent anywhere without your consent.

These are the basics, but there's much more you can do. The following sections cover installation, usage and hosting of the recordings in more detail.

Installation

Python package

asciinema is available on PyPI and can be installed with pip (Python 3 with setuptools required):

sudo pip3 install asciinema

This is the recommended way of installation, which gives you the latest released version.

Native packages

asciinema is included in repositories of most popular package managers on Mac OS X, Linux and FreeBSD. Look for package named asciinema. See the list of available packages.

Running latest version from source code checkout

If you can't use Python package or native package for your OS is outdated you can clone the repo and run asciinema straight from the checkout.

Clone the repo:

git clone https://github.com/asciinema/asciinema.git
cd asciinema

If you want latest stable version:

git checkout master

If you want current development version:

git checkout develop

Then run it with:

python3 -m asciinema --version

Docker image

asciinema Docker image is based on Ubuntu 18.04 and has the latest version of asciinema recorder pre-installed.

docker pull asciinema/asciinema

When running it don't forget to allocate a pseudo-TTY (-t), keep STDIN open (-i) and mount config directory volume (-v):

docker run --rm -ti -v "$HOME/.config/asciinema":/root/.config/asciinema asciinema/asciinema rec

Container's entrypoint is set to /usr/local/bin/asciinema so you can run the container with any arguments you would normally pass to asciinema binary (see Usage section for commands and options).

There's not much software installed in this image though. In most cases you may want to install extra programs before recording. One option is to derive new image from this one (start your custom Dockerfile with FROM asciinema/asciinema). Another option is to start the container with /bin/bash as the entrypoint, install extra packages and manually start asciinema rec:

docker run --rm -ti -v "$HOME/.config/asciinema":/root/.config/asciinema --entrypoint=/bin/bash asciinema/asciinema
[email protected]:~# apt-get install foobar
[email protected]:~# asciinema rec

Usage

asciinema is composed of multiple commands, similar to git, apt-get or brew.

When you run asciinema with no arguments help message is displayed, listing all available commands with their options.

rec [filename]

Record terminal session.

By running asciinema rec [filename] you start a new recording session. The command (process) that is recorded can be specified with -c option (see below), and defaults to $SHELL which is what you want in most cases.

You can temporarily pause recording of terminal by pressing Ctrl+P. This is useful when you want to execute some commands during the recording session that should not be captured (e.g. pasting secrets). Resume by pressing Ctrl+P again.

Recording finishes when you exit the shell (hit Ctrl+D or type exit). If the recorded process is not a shell then recording finishes when the process exits.

If the filename argument is omitted then (after asking for confirmation) the resulting asciicast is uploaded to asciinema-server (by default to asciinema.org), where it can be watched and shared.

If the filename argument is given then the resulting recording (called asciicast) is saved to a local file. It can later be replayed with asciinema play <filename> and/or uploaded to asciinema server with asciinema upload <filename>.

ASCIINEMA_REC=1 is added to recorded process environment variables. This can be used by your shell's config file (.bashrc, .zshrc) to alter the prompt or play a sound when the shell is being recorded.

Available options:

  • --stdin - Enable stdin (keyboard) recording (see below)
  • --append - Append to existing recording
  • --raw - Save raw STDOUT output, without timing information or other metadata
  • --overwrite - Overwrite the recording if it already exists
  • -c, --command=<command> - Specify command to record, defaults to $SHELL
  • -e, --env=<var-names> - List of environment variables to capture, defaults to SHELL,TERM
  • -t, --title=<title> - Specify the title of the asciicast
  • -i, --idle-time-limit=<sec> - Limit recorded terminal inactivity to max <sec> seconds
  • -y, --yes - Answer "yes" to all prompts (e.g. upload confirmation)
  • -q, --quiet - Be quiet, suppress all notices/warnings (implies -y)

Stdin recording allows for capturing of all characters typed in by the user in the currently recorded shell. This may be used by a player (e.g. asciinema-player) to display pressed keys. Because it's basically a key-logging (scoped to a single shell instance), it's disabled by default, and has to be explicitly enabled via --stdin option.

play <filename>

Replay recorded asciicast in a terminal.

This command replays given asciicast (as recorded by rec command) directly in your terminal.

Following keyboard shortcuts are available:

  • Space - toggle pause,
  • . - step through a recording a frame at a time (when paused),
  • Ctrl+C - exit.

Playing from a local file:

asciinema play /path/to/asciicast.cast

Playing from HTTP(S) URL:

asciinema play https://asciinema.org/a/22124.cast
asciinema play http://example.com/demo.cast

Playing from asciicast page URL (requires <link rel="alternate" type="application/x-asciicast" href="/my/ascii.cast"> in page's HTML):

asciinema play https://asciinema.org/a/22124
asciinema play http://example.com/blog/post.html

Playing from stdin:

cat /path/to/asciicast.cast | asciinema play -
ssh [email protected] cat asciicast.cast | asciinema play -

Playing from IPFS:

asciinema play dweb:/ipfs/QmNe7FsYaHc9SaDEAEXbaagAzNw9cH7YbzN4xV7jV1MCzK/ascii.cast

Available options:

  • -i, --idle-time-limit=<sec> - Limit replayed terminal inactivity to max <sec> seconds
  • -s, --speed=<factor> - Playback speed (can be fractional)

For the best playback experience it is recommended to run asciinema play in a terminal of dimensions not smaller than the one used for recording, as there's no "transcoding" of control sequences for new terminal size.

cat <filename>

Print full output of recorded asciicast to a terminal.

While asciinema play <filename> replays the recorded session using timing information saved in the asciicast, asciinema cat <filename> dumps the full output (including all escape sequences) to a terminal immediately.

asciinema cat existing.cast >output.txt gives the same result as recording via asciinema rec --raw output.txt.

upload <filename>

Upload recorded asciicast to asciinema.org site.

This command uploads given asciicast (recorded by rec command) to asciinema.org, where it can be watched and shared.

asciinema rec demo.cast + asciinema play demo.cast + asciinema upload demo.cast is a nice combo if you want to review an asciicast before publishing it on asciinema.org.

auth

Link your install ID with your asciinema.org user account.

If you want to manage your recordings (change title/theme, delete) at asciinema.org you need to link your "install ID" with asciinema.org user account.

This command displays the URL to open in a web browser to do that. You may be asked to log in first.

Install ID is a random ID (UUID v4) generated locally when you run asciinema for the first time, and saved at $HOME/.config/asciinema/install-id. Its purpose is to connect local machine with uploaded recordings, so they can later be associated with asciinema.org account. This way we decouple uploading from account creation, allowing them to happen in any order.

A new install ID is generated on each machine and system user account you use asciinema on, so in order to keep all recordings under a single asciinema.org account you need to run asciinema auth on all of those machines.

asciinema versions prior to 2.0 confusingly referred to install ID as "API token".

Hosting the recordings on the web

As mentioned in the Usage > rec section above, if the filename argument to asciinema rec is omitted then the recorded asciicast is uploaded to asciinema.org. You can watch it there and share it via secret URL.

If you prefer to host the recordings yourself, you can do so by either:

Configuration file

You can configure asciinema by creating config file at $HOME/.config/asciinema/config.

Configuration is split into sections ([api], [record], [play]). Here's a list of all available options for each section:

[api]

; API server URL, default: https://asciinema.org
; If you run your own instance of asciinema-server then set its address here
; It can also be overriden by setting ASCIINEMA_API_URL environment variable
url = https://asciinema.example.com

[record]

; Command to record, default: $SHELL
command = /bin/bash -l

; Enable stdin (keyboard) recording, default: no
stdin = yes

; List of environment variables to capture, default: SHELL,TERM
env = SHELL,TERM,USER

; Limit recorded terminal inactivity to max n seconds, default: off
idle_time_limit = 2

; Answer "yes" to all interactive prompts, default: no
yes = true

; Be quiet, suppress all notices/warnings, default: no
quiet = true

; Define hotkey for pausing recording (suspending capture of output),
; default: C-\
pause_key = C-p

; Define hotkey prefix key - when defined other recording hotkeys must
; be preceeded by it, default: no prefix
prefix_key = C-a

[play]

; Playback speed (can be fractional), default: 1
speed = 2

; Limit replayed terminal inactivity to max n seconds, default: off
idle_time_limit = 1

; Define hotkey for pausing/resuming playback,
; default: space
pause_key = p

; Define hotkey for stepping through playback, a frame at a time,
; default: .
pause_key = ]

[notifications]

; Should desktop notifications be enabled, default: yes
enabled = no

; Custom notification command
; Environment variable $TEXT contains notification text
command = tmux display-message "$TEXT"

A very minimal config file could look like that:

[record]
idle_time_limit = 2

Config directory location can be changed by setting $ASCIINEMA_CONFIG_HOME environment variable.

If $XDG_CONFIG_HOME is set on Linux then asciinema uses $XDG_CONFIG_HOME/asciinema instead of $HOME/.config/asciinema.

asciinema versions prior to 1.1 used $HOME/.asciinema. If you have it there you should mv $HOME/.asciinema $HOME/.config/asciinema.

Contributing

If you want to contribute to this project check out Contributing page.

Authors

Developed with passion by Marcin Kulik and great open source contributors.

License

Copyright © 2011–2019 Marcin Kulik.

All code is licensed under the GPL, v3 or later. See LICENSE file for details.

Issues
  • Bad request for uploads of >4kb recordings under CentOS (Python 3.4)

    Bad request for uploads of >4kb recordings under CentOS (Python 3.4)

    Bug report

    System info:

    • Version used: 1.4.0 (1.1.1 also have same issue)
    • OS: CentOS Linux release 7.3.1611
    • Python version: Python 3.4.5
    • Install tools: yum (from EPEL repository)

    Steps to reproduce:

    1. asciinema upload asciicast.json

    Expected behavior:

    File uploaded to asciinema.org

    Actual behavior:

    Client print error message:

    Error: Invalid request: <html><body><h1>400 Bad request</h1>
    Your browser sent an invalid request.
    </body></html>
    

    Additional info:

    Client create broken recording if zsh (4.3.11 (x86_64-redhat-linux-gnu) in my case) is used and oh-my-zsh is installed. If oh-my-zsh disabled or bash used as a shell, client create and upload recording without any problems.

    Recording JSON: https://gist.github.com/andyone/b2a883e8c3795a6ad393a715ff7a41df

    compatibility help wanted hosting 
    opened by andyone 58
  • Decouple terminal recording from asciinema.org

    Decouple terminal recording from asciinema.org

    Recording should not be tied to asciinema.org.

    You should be able to:

    • record to a local file with asciinema rec <filename>,
    • replay locally (in a terminal) from files with asciinema play <filename>,
    • replay locally (in a terminal) from URLs with asciinema play <url>,
    • instruct player on asciinema.org to play from external URL?

    This is a prerequisite for #49, it is in fact a simpler version of it.

    Saving/sharing/replaying from a local file means we have to decide on the data format.

    Requirements for data format:

    • should include raw stdout data with frame timing + (initial) width/height of the terminal window
    • should be easy to parse and process for asciinema and external tools
    • should allow live streaming
    • should be easy to read/parse by js player itself (so you can point js player directly to URL containing recording in this format)
    • the format should be versioned

    Option 1: use current format used by asciinema.org

    zip file with custom extension (like .asciicast for ex), including 3 files:

    • meta.json - with metadata like width/height of terminal, title, etc
    • stdout - raw stdout bytes,
    • stdout.timing - timing information.

    Current implementation uses these 3 files when uploading the recording to asciinema.org. This however isn't really compatible with live streaming idea and doesn't address all the requirements above.

    Option 2: new JSON based format

    With frames inlined, to be used when persisted:

    {
      version: 1,
      width: 80,
      height: 24,
      frames: [<frame>, <frame>, <frame>...]
    }
    

    With frames delegated to an URL, to be used when streaming:

    {
      version: 1,
      width: 80,
      height: 24,
      frames_url: "https://....." or "ws://....."
    }
    

    frames_url is a URL to streaming endpoint, either http or websocket.

    Format of the single frame:

    JSON isn't suited to store arbitrary binary data in strings and raw stdout output contains lots of non-printable bytes so we should encode them. Base64 or encoding each byte in hex or utf would do.

    [1.234, "bHMgLWxhIC8="]
    

    or

    { delay: 1.234, data: "bHMgLWxhIC8=" }
    

    Streaming endpoint(s) could be implemented to spit out each new frame in a separate line.

    opened by sickill 38
  • Windows support?

    Windows support?

    A Windows console is a (quirky) ANSI terminal, bound up behind the Windows Console API. Assuming a recorder can be made, the existing asciicast file format should be capable of representing nearly anything a Windows Console application can do. The resulting recording should be as playable as any other.

    The difficult trick is the recording. Has anyone put any thought or effort into building such a recorder for a Windows console?

    Would a port of asciinema to Windows be possible?

    feature request packaging 
    opened by rberteig 31
  • Package for Ubuntu

    Package for Ubuntu

    opened by sickill 27
  • Package for Fedora

    Package for Fedora

    Looks like Jakub Jedelsky is already doing some work in that matter: https://bugzilla.redhat.com/show_bug.cgi?id=1034492

    opened by sickill 24
  • Writing to disk in real-time

    Writing to disk in real-time

    Steps to reproduce:

    • start recording to a file;
    • kill asciinema process (e.g., close the terminal window);
    • try to locate the recording — there is none.

    See the demo.

    It would be very useful if asciinema flushed the recording file periodically. Unfinished JSON file is easy to fix (asciinema play could do this). The loss of a session recording may be rather disappointing at times.

    (My dayjob project has long-running system tests. I use asciinema to record their execution, because its web UI allows me to jump to interesting spots and fast-forward the test.)

    feature request improvement 
    opened by vvv 24
  • asciicast format version 2

    asciicast format version 2

    The ideas behind asciicast v2 format are:

    • enable live, incremental writing to a file during recording (with v1 format the final recording JSON can only be written as a whole after finishing the recording session),
    • allow the players to start the playback as soon as they read the meta-data line (contrary to v1 format which requires reading the whole file), without need to buffer whole recording in memory,
    • use the same data representation whether you're recording to a file or streaming via UNIX pipe or WebSocket.

    Preview of the doc: https://github.com/asciinema/asciinema/blob/v2/doc/asciicast-v2.md

    opened by sickill 23
  • Update shebang to use python2

    Update shebang to use python2

    On archlinux the default python is python 3, so I get something like print: invalid syntax when running asciiio. I'm told the command python2 is valid on systems where python points to python 2. Thanks to the fine folks in #archlinux!

    opened by losingkeys 23
  • Install via Homebrew

    Install via Homebrew

    Via @hced:

    As a feature suggestion, I propose installation/updating via Homebrew for us Mac users.

    opened by sickill 18
  • Upload failed

    Upload failed

    Upload fails with the following error:

    bash-3.2$ exit
    exit
    ~ Asciicast recording finished.
    ~ Press <Enter> to upload, <Ctrl-C> to cancel.
    
    ~ Upload failed: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>
    ~ Retry later by running: asciinema upload /var/folders/9g/60yjppb57779f3nrvxzvb_wn5wr3t6/T/tmp3zaagfuf-asciinema.json
    

    My Env: MacOS Sierra - 10.12.4 (16E195)

    I'm able to play the recording, just that the upload fails. Any feedback or clues to fix this issue?

    opened by stayingcool 16
  • Feature request: Scrubber / navigation in terminal replay

    Feature request: Scrubber / navigation in terminal replay

    When replaying recordings in the terminal, I don't have any way to scrub files, it would be nice if I could. Of course, granularity isn't very high, but it would still be something. It would also be nice if I could go forwards and backwards in the recording with some keybindings (+-1,5,10 seconds/frames etc). Furthermore it would be nice if it was possible to not exit immediately once replay finishes the last frame, and also maybe a loop mode.

    opened by deliciouslytyped 0
  • Invalid or revoked install ID

    Invalid or revoked install ID

    @sickill @abaykan How to remove ~/.asciinema/install-id (or ~/.config/asciinema/install-id)

    opened by p16andr 2
  • Invalid or revoked install ID

    Invalid or revoked install ID

    I have this problem when i record my Terminal. How to fix it?? I used linux ubuntu

    asciinema: upload failed: Invalid or revoked install ID asciinema: retry later by running: asciinema upload /tmp/tmpk6nt4pei-ascii.cast

    opened by p16andr 3
  • Admin

    Admin

    opened by xxksa2010 0
  • [bug] asciinema rec fails in one virtual env and succeeds in other (not a package issue)

    [bug] asciinema rec fails in one virtual env and succeeds in other (not a package issue)

    asciicast

    The cast shows it all. asciinema rec works only after changing the conda virtual environment (the specific environment I change it to does not matter). The error is not due to a missing or broken package, but due to an unknown term (which is weird).

    Terminals tried:

    1. st-256color
    2. alacritty
    3. xterm

    All of them with the exact same outcome (except the change in name in the first non-green line).

    opened by kunzaatko 0
  • Be able to quote and cite a part of the cast

    Be able to quote and cite a part of the cast

    When you are having a conversation about a particular cast (let's say, on github, or any platform where you can embed markdown), it would be great if the platform would provide a way of building an embeddable quote of your current selection of the console, with a link to the specific moment that you are looking at.

    For example, for the one that is used in the website: https://asciinema.org/a/335480

    It would be great if the share would highlight the selected text, like this: asciicast

    Would help peer-programming communities in debating about what has been done in a session.

    opened by nicopace 0
  • Use os.get_terminal_size()

    Use os.get_terminal_size()

    tput is part of ncurses, which may not be installed.

    It still falls back to tput for older Python versions (this was introduced in 3.3) or for platforms which may not support it.

    Fixes #418

    opened by arp242 0
  • Modernize asciinema packaging (use twine, github actions..)

    Modernize asciinema packaging (use twine, github actions..)

    Asciinema is using a lot of deprecated stuff to package itself. This is why, for instance, https://pypi.org/project/asciinema/2.0.2/ isn't rendered and looks terrible. I also took the liberty to migrate from Travis CI to Github CI since it has a much better integration in Github, and allowed to split the jobs to separate pycodestyle. (also because Travis CI is currently doing all it can to kick OpenSource out..)

    This PR:

    • migrates from Travis CI to Github CI. Create a standalone job: "pycodestyle". The badge will need to be updated once this is merged.
    • update the Makefile to use twine, as you should.
    • adds a twine check test. good practice
    • use license_file in setup.cfg
    • drop tests_require: it's not used since no test entry is specified in setup.py and is deprecated.

    Job demo: https://github.com/gpotter2/asciinema/actions/runs/387286730. Please make sure that Github Actions are not disabled in the repo settings (they shouldn't by default). I'm pretty sure this needs to be merged once for the actions to start on future PRs.

    opened by gpotter2 0
  • Feature: Add custom font support.

    Feature: Add custom font support.

    Lots of us are using zsh and powerlevel10k + MesloLGS NF or other custom fonts so the terminal looks nice.

    Please add an option in the configuration to specify the font which will be used when rendering.

    So far I'm using terminalizer which gives me that option but I would love to move back to asciinema but lack of this feature is a deal breaker ATM

    Link to terminalizer

    opened by pozgo 1
  • The ubuntu PPA does not work on ubuntu 20.04

    The ubuntu PPA does not work on ubuntu 20.04

    The PPA does not contain packages for Focal.

    opened by stof 0
Releases(v2.0.2)
Owner
asciinema
Record and share your terminal sessions, the right way.
asciinema
Simple animated GIF screen recorder with an easy to use interface

Peek - an animated GIF recorder Simple screen recorder with an easy to use interface Contents About Requirements Runtime Development Installation Offi

Philipp Wolfer 7.7k Jun 6, 2021
Terminal session recorder 📹

Note: This is README for development branch. See the version for latest stable release. asciinema Terminal session recorder and the best companion of

asciinema 9.3k Jun 4, 2021
Screen{shot,cast} and perform ImageOps on the command line 🌱 🏞️

Screen{shot,cast} and perform ImageOps on the command line ?? ??️ menyoki is a screencast and screenshot utility that can also perform various image r

Orhun Parmaksız 275 Jun 2, 2021
SimpleScreenRecorder, a screen recorder for Linux

SimpleScreenRecorder SimpleScreenRecorder is a screen recorder for Linux. Despite the name, this program is actually quite complex. It's 'simple' in t

Maarten Baert 1.8k Jun 5, 2021
Powerful yet simple to use screenshot software :desktop_computer: :camera_flash:

Flameshot Powerful yet simple to use screenshot software. Preview Index Features Usage CLI configuration Config file Keyboard Shortcuts Local Global O

Flameshot 13.1k Jun 5, 2021