What is a Session?
A session encapsulates everything needed for an agent to work independently:- Unique identifier — e.g.,
app-1,backend-12 - Isolated workspace — Git worktree or clone with its own branch
- Runtime environment — Tmux session, Docker container, or process
- Running agent — Claude Code, Codex, Aider, or other AI coding tool
- Task context — Issue ID, branch name, PR information
- Metadata — State, timestamps, agent info, custom fields
Session Naming
Sessions use a two-tier naming system: User-facing names (clean and simple):The hash is derived from the config file location using SHA-256, ensuring multiple orchestrator instances never collide.
Session Lifecycle States
Sessions progress through a well-defined state machine:Active States
spawning
spawning
Session is being created. The orchestrator is:
- Creating the workspace (git worktree)
- Setting up the runtime environment
- Launching the agent
working once agent is running.working
working
Agent is actively working on the task:
- Reading code and documentation
- Writing and testing code
- Making commits
pr_open when agent creates a pull request.pr_open
pr_open
Pull request has been created and is awaiting CI or review.Transitions to:
ci_failed— CI checks failedreview_pending— CI passed, awaiting reviewmerged— PR was merged
ci_failed
ci_failed
CI checks failed on the PR. If reactions are enabled, the orchestrator automatically:
- Fetches CI logs
- Sends logs to agent
- Agent fixes the issue
- Pushes new commit
pr_open after fix is pushed.review_pending
review_pending
PR passed CI and is awaiting human review.Transitions to:
approved— Reviewer approvedchanges_requested— Reviewer requested changes
changes_requested
changes_requested
Reviewer requested changes. With auto-reactions:
- Review comments are fetched
- Comments sent to agent
- Agent addresses feedback
- New commits pushed
pr_open after updates.approved
approved
PR has been approved but not yet mergeable (might have minor CI pending).Transitions to
mergeable when ready to merge.mergeable
mergeable
PR is approved with passing CI and no conflicts — ready to merge.With
approved-and-green reaction:auto: false— Human gets notification to mergeauto: true— Automatic merge
merged after merge.Terminal States
merged
merged
PR was successfully merged. Session work is complete.This state cannot be restored — the work is done.
killed
killed
Session was terminated (either by user or because runtime died).Can be restored with
ao session restore <session-id>.done
done
Session completed successfully without PR (e.g., exploration task).
terminated
terminated
Session was force-stopped by user.
cleanup
cleanup
Session is being cleaned up (workspace deletion, etc.).
errored
errored
Session encountered a fatal error and cannot continue.
Intervention States
needs_input
needs_input
Agent is waiting for user input (e.g., permission prompt, question).Send a message to the agent:Transitions back to
working after input is provided.stuck
stuck
Agent has been inactive for longer than the configured threshold (default: 5 minutes).With auto-reactions, the orchestrator can:
- Send a nudge message
- Notify human for intervention
- Auto-restart the agent
ao send to provide guidance.Activity Detection
In addition to lifecycle states, each session has an activity state that reflects what the agent is currently doing:| Activity State | Description |
|---|---|
active | Agent is processing (thinking, writing code) |
ready | Agent finished its turn, waiting for next input |
idle | Agent inactive beyond threshold (becomes stuck in lifecycle) |
waiting_input | Agent asking a question or waiting for permission |
blocked | Agent hit an error or is stuck on a problem |
exited | Agent process is no longer running |
Activity detection is handled by the Agent plugin, which reads agent-native telemetry (JSONL files, SQLite, etc.) rather than parsing terminal output.
Activity Detection Methods
Agent plugins use two methods: Preferred:getActivityState()
- Reads agent’s native session files (JSONL, SQLite, etc.)
- Runtime-agnostic (works even if tmux session is dead)
- More reliable and accurate
- Used by claude-code, codex plugins
detectActivity()
- Parses terminal output from runtime
- Less reliable (depends on output patterns)
- Used when native detection unavailable
Session Management Operations
Spawn a Session
Create a new session for an issue:List Sessions
View all sessions or filter by project:- Session ID
- Status
- Activity state
- Branch name
- Issue ID
- PR URL (if created)
- Summary (agent-generated)
Attach to Session
Connect to a running session:- iTerm2 tab (macOS)
- Web terminal (browser)
- Direct tmux attach
Send Message
Send instructions to a running agent:Kill Session
Terminate a running session:- Agent process is terminated
- Runtime environment is destroyed
- Session status set to
killed - Workspace preserved (can be restored)
Restore Session
Revive a killed or crashed session:- Session must be in a terminal state (
killed,done, etc.) - Session must NOT be
merged(cannot restore completed work) - Workspace must still exist (or be restorable)
- Checks if workspace exists
- If missing, attempts to recreate workspace (for worktree plugin)
- Determines if agent can resume previous session
- If yes, uses
getRestoreCommand()to resume - If no, launches fresh agent with original prompt
- Updates
restoredAttimestamp in metadata
Cleanup Sessions
Remove completed or stale sessions:- Status is
merged,done, orkilled - Issue is closed (if Tracker plugin supports it)
- PR is merged or closed
- Runtime terminated
- Workspace deleted
- Metadata moved to
archive/with timestamp
Session Metadata
Metadata is stored as flat key=value files for backwards compatibility:Key Fields
| Field | Description |
|---|---|
project | Project ID (config key) |
issue | Issue identifier (GitHub #, Linear ID, etc.) |
branch | Git branch name |
status | Current lifecycle status |
tmuxName | Globally unique tmux session name |
worktree | Absolute path to workspace |
createdAt | ISO 8601 timestamp |
restoredAt | When session was last restored (if applicable) |
runtimeHandle | JSON-encoded runtime handle |
pr | Pull request URL |
summary | Agent-generated task summary |
agent | Agent plugin name used for this session |
Metadata files are located at
~/.agent-orchestrator/{hash}-{project}/sessions/{session-id}.Session Restoration
When a session crashes or is killed, you can restore it:Restorable States
killed— Session terminateddone— Completed without PRterminated— Force-stoppedcleanup— Being cleaned uperrored— Error occurred
Non-Restorable States
merged— Work complete, cannot continue
Restoration Process
Claude Code: Looks for
.claude/sessions/<hash> directory.
Other agents: May not support resume, will start fresh.getRestoreCommand() returns launch command with session ID.getLaunchCommand() with prompt.Agent Resume Support:
- claude-code: Full session resume (preserves conversation history)
- codex, aider, opencode: Fresh start with original prompt
Best Practices
Session Naming
- Use descriptive session prefixes in project config
- Keep prefixes short (2-4 characters):
app,api,web - Avoid prefixes that conflict with common commands
Activity Monitoring
- Set appropriate
readyThresholdMsin config (default: 5 minutes) - Monitor
stucksessions — they may need human guidance - Use
ao sendto nudge idle agents back into action
Cleanup Strategy
- Run cleanup periodically to free disk space
- Archive metadata is preserved for audit trail
- Completed sessions (
merged,done) can be cleaned immediately - Keep
killedsessions until you verify work wasn’t lost
Session Restoration
- Restore sessions after system crashes or accidental kills
- Check workspace before restoring — missing worktrees can often be recreated
- Use agent resume when available (preserves context)
- For failed restores, check logs:
ao session restore session-1 --verbose
Next Steps
Architecture
Understand the plugin architecture and component interactions
Plugins
Learn about the 8 plugin slots and how to use them
Workflows
See how sessions progress through typical workflows
