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
- Runtime Session - tmux session is killed
- Worktree - Git worktree is removed
- Session Metadata - Session file is updated (status set to “killed”)
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:- PR Merged - Pull request state is “merged”
- Issue Closed - Issue state is “closed” in the tracker
- 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: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
- Validation - Checks if session can be restored
- Workspace Check - Verifies worktree still exists
- Runtime Recreation - Creates new tmux session
- Agent Relaunch - Starts the agent in the existing workspace
- Metadata Update - Updates session status to “working”
Restore Errors
Session Not Restorable
Workspace Missing
Common Issues
No Config Found
Unknown Project
Session Not Found
Examples
List All Sessions
List Filtered Sessions
Kill Session
Safe Cleanup
Restore Workflow
Batch Kill
Cleanup Script
Exit Codes
0- Success1- 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
