Skip to content

Session Recording

Record and replay remote session operations for auditing and training.

Overview

Session recording captures commands executed on remote hosts and their output in asciinema v2 format. Recordings are stored compressed and can be replayed later in the terminal.

How Recording Works

Commands executed during a session are automatically recorded:

  1. A .cast.gz file is created when the session starts
  2. Each command execution and its output are recorded with timestamps
  3. Includes prompt lines, stdout, stderr (in red), and exit codes
  4. A .meta.json metadata file is generated when the session ends

Configuration

Session recording can be enabled with the default settings:

yaml
defaults:
  recording:
    enabled: true

CLI Commands

List Recordings

bash
nefia recording list
nefia recording list --limit 10

Displays metadata (session ID, host ID, user, command count, duration, size).

Replay a Recording

bash
nefia recording replay <session-id>
FlagDescriptionDefault
--speedPlayback speed1 (real-time)
Speed ValueBehavior
0Instant playback (no timing)
1Real-time playback
55x speed playback

Playback can be canceled with Ctrl+C.

Export a Recording

bash
nefia recording export <session-id>
nefia recording export <session-id> --out recording.cast

Decompresses the .cast.gz file and outputs it as a .cast file. Can be used with asciinema players and other tools.

Delete a Recording

bash
nefia recording delete <session-id>

Deletes the recording file after a confirmation prompt.

Storage Format

.cast.gz File

asciinema v2 format (gzip compressed):

jsonl
{"version": 2, "width": 120, "height": 40, "timestamp": 1709000000, "title": "session-abc123"}
[0.0, "o", "$ whoami\r\n"]
[0.1, "o", "root\r\n"]
[0.5, "o", "$ systemctl status nginx\r\n"]
[0.8, "o", "● nginx.service - A high performance web server\r\n"]

.meta.json File

json
{
  "session_id": "abc123...",
  "host_id": "web-01",
  "user": "admin",
  "shell": "/bin/bash",
  "start_time": "2026-03-10T10:00:00Z",
  "end_time": "2026-03-10T10:15:00Z",
  "command_count": 12,
  "duration_ms": 900000,
  "size_bytes": 45678,
  "payload_bytes": 123456,
  "truncated": false
}
FieldDescription
session_idUnique session identifier
host_idTarget host ID
userSSH user
shellRemote shell path
start_timeSession start time (RFC 3339)
end_timeSession end time (RFC 3339)
command_countNumber of commands executed
duration_msSession duration in milliseconds
size_bytesCompressed .cast.gz file size
payload_bytesUncompressed payload size (omitted if zero)
truncatedWhether the recording was truncated due to the size limit (omitted if false)

Storage and Retention

ItemValue
Storage location<state-dir>/recordings/
File naming<session-id>.cast.gz + <session-id>.meta.json
File permissions0o600 (owner read/write only)
Default retention period90 days
Uncompressed size limit50 MB
Export decompression limit512 MB (zip bomb protection)

Recordings that exceed the retention period are automatically deleted during cleanup.

Recorded Output Contents

ElementRepresentation
Prompt$ <command>\r\n
Standard outputRecorded as-is
Standard errorWith ANSI red color codes (\x1b[31m...\x1b[0m)
Non-zero exit code[exit <code>]

MCP Tools

Session recordings can be managed by AI agents via MCP:

ToolDescription
nefia.recording.listList all session recordings with metadata.
nefia.recording.showShow detailed metadata for a specific recording.
nefia.recording.deleteDelete a recording (subject to retention policy).
nefia.recording.exportExport a recording in a specified format.