Skip to main content
The session command provides granular control over agent sessions, including listing, terminating, cleaning up completed work, and restoring crashed sessions.

Overview

Session management commands:

ao session ls

List all sessions with branch and activity information.

Syntax

Options

string
Filter by project ID

Basic Usage

Output Example

Field Descriptions

  • Session ID - Session name (green)
  • Age - Time since last activity (dim)
  • Branch - Current git branch (cyan)
  • Status - Session status in brackets (dim)
  • PR URL - Pull request link if created (blue)
The branch shown is the live branch from the worktree, not the cached value. If the agent switched branches, you’ll see the updated branch name.

ao session kill

Kill a session and remove its worktree.

Syntax

Arguments

string
required
Session name to kill

Basic Usage

What Gets Removed

  1. Runtime Session - tmux session is killed
  2. Worktree - Git worktree is removed
  3. Session Metadata - Session file is updated (status set to “killed”)
This is a destructive operation. Any uncommitted changes in the worktree will be lost.

Output Example

Before Killing

Check if there are uncommitted changes:

ao session cleanup

Automatically kill sessions where the PR is merged or the issue is closed.

Syntax

Options

string
Filter by project ID
flag
Show what would be cleaned up without doing it

Basic Usage

Cleanup Criteria

A session is considered completed if any of these are true:
  1. PR Merged - Pull request state is “merged”
  2. Issue Closed - Issue state is “closed” in the tracker
  3. Runtime Dead - tmux session no longer exists
Sessions with status “killed”, “done”, or “exited” are skipped. The cleanup only targets active sessions that have completed work.

Dry Run Example

Actual Cleanup Example

Error Handling

If cleanup fails for some sessions:
Run cleanup regularly to free disk space and keep your worktree directory tidy:

ao session restore

Restore a terminated or crashed session in-place.

Syntax

Arguments

string
required
Session name to restore

When to Use Restore

Use restore when:
  • tmux session crashed or was accidentally killed
  • Terminal disconnected and session was lost
  • Machine rebooted with sessions still registered
Restore recreates the runtime session (tmux) while preserving the workspace and session metadata. It’s like “respawning” without creating a new worktree.

Basic Usage

Output Example

What Happens During Restore

  1. Validation - Checks if session can be restored
  2. Workspace Check - Verifies worktree still exists
  3. Runtime Recreation - Creates new tmux session
  4. Agent Relaunch - Starts the agent in the existing workspace
  5. Metadata Update - Updates session status to “working”

Restore Errors

Session Not Restorable

Solution: Kill the session first if you want to restart it:

Workspace Missing

Solution: The worktree was deleted. Create a new session:
Restore only works if the worktree still exists. If you deleted the worktree, you must create a new session instead.

Common Issues

No Config Found

Solution: Create a configuration:

Unknown Project

Solution: Use a valid project ID:

Session Not Found

Solution: List sessions to find the correct name:

Examples

List All Sessions

List Filtered Sessions

Kill Session

Safe Cleanup

Restore Workflow

Batch Kill

Cleanup Script

Exit Codes

  • 0 - Success
  • 1 - Error (session not found, invalid project, restore failed)

Next Steps

Status

Monitor session activity and PR status

Send Messages

Interact with active sessions

Spawn

Create new sessions