Streaming Sessions

Everything you need to know about streaming terminal sessions.

Basic Usage

The afk stream command wraps any terminal command and streams it:

afk stream <your-command>

Whatever you'd normally run in your terminal, just prefix it with afk stream.

Common Examples

Interactive Shell

Stream a bash or zsh session for general use:

afk stream bash

Claude Code

Monitor and interact with Claude Code sessions:

afk stream claude

Long-running Processes

Monitor builds, tests, or deploys:

afk stream npm run build

afk stream cargo test

afk stream kubectl logs -f deployment/api

Development Servers

Keep an eye on server logs from your phone:

afk stream npm run dev

afk stream python manage.py runserver

How It Works

  1. 1
    AFK CLI starts

    AFK creates a pseudo-terminal (PTY) and runs your command inside it

  2. 2
    Output captured

    Everything the command outputs is captured by AFK

  3. 3
    Encrypted & streamed

    Output is encrypted with your session key and sent to connected devices

  4. 4
    Input sent back

    When you type on mobile, keystrokes are encrypted and sent back to the PTY

Session Options

# Use a specific session ID (useful for scripting)

afk stream --session-id 550e8400-... bash

 

# Force re-login before streaming

afk stream --login claude

 

# Logout and delete stored tokens

afk stream --logout

Detaching

You can detach from a running session without stopping it. The session continues running in the background.

Escape Sequence: ~.

Press Enter, then ~, then . to detach. The session keeps running and can be reattached later.

# Reconnect to the detached session

afk connect

See Sessions & Connect for more details on reattaching.

Session Lifecycle

Active

Command is running, connected devices can view and interact

Idle

Command waiting for input (e.g., bash prompt)

Detached

You disconnected locally, but the session is still running. Reconnect with afk connect

Sleeping

The session is running but the desktop machine has gone to sleep or is idle. The session will resume when the machine wakes up

Disconnected

The desktop wrapper lost its connection to the backend. This may indicate a network issue or that the desktop went offline

Closed

Command exited, session ends. Mobile clients receive a notification when a session closes

Sessions end when the wrapped command exits (e.g., typing exit in bash).

Tips

  • Use afk stream bash for general shell access - you can run any commands inside
  • Each session gets a unique ID shown when you start it