Overview
Claude Code is Anthropic’s official CLI for AI-assisted coding. The plugin:- Launches Claude in interactive mode (not one-shot)
- Delivers prompts post-launch via
sendMessage()to keep Claude in conversation mode - Automatically updates session metadata on PR creation and git operations via PostToolUse hooks
- Extracts cost, token usage, and summaries from Claude’s JSONL session files
- Detects activity state by monitoring JSONL file modifications
This plugin requires Claude Code CLI to be installed. Get it from Anthropic’s website.
Installation
Configuration
Configure inagent-orchestrator.yaml:
Configuration Options
Claude model to use (e.g.,
claude-sonnet-4.5, claude-opus-4)Permission mode:
skip: Auto-approve all operations (--dangerously-skip-permissions)suggest: Prompt for untrusted operations (default)ask: Always prompt
Additional instructions appended to Claude’s system prompt
Path to a file containing system prompt (preferred for long prompts)
Automatic Metadata Updates
The plugin installs a PostToolUse hook script (.claude/metadata-updater.sh) that automatically updates session metadata when agents run specific commands:
Tracked Commands
| Command | Metadata Updated |
|---|---|
gh pr create | pr (URL), status (pr_open) |
git checkout -b <branch> | branch |
git switch -c <branch> | branch |
gh pr merge | status (merged) |
How metadata updates work
How metadata updates work
- Claude Code invokes PostToolUse hooks after each Bash tool call
- Hook script receives JSON with tool name, command, and output
- Script parses output for PR URLs or branch names
- Updates
~/.ao-sessions/<project>/<session-id>viaupdate_metadata_key() - Orchestrator reads updated metadata on next refresh
postLaunchSetup().Manual Metadata Updates
If hooks fail or you need custom metadata:Session Introspection
The plugin reads Claude’s JSONL session files from~/.claude/projects/{encoded-path}/ to extract:
Cost Tracking
Token usage and estimated costs from usage events:Cost estimates use Sonnet 4.5 pricing (15/1M output) as a baseline. Actual costs may vary for Opus or Haiku models.
Session Summaries
Auto-generated summaries from Claude’s summary events:Activity Detection
The plugin monitors JSONL file modifications to detect agent state:| Last JSONL Event | Agent State | Condition |
|---|---|---|
user, tool_use, progress | active | Recent (< threshold) |
assistant, result, summary | ready | Recent (< threshold) |
permission_request | waiting_input | Any time |
error | blocked | Any time |
| Any event | idle | Stale (> threshold) |
| No process | exited | Process not running |
Time in milliseconds before an agent is considered idle
Usage Examples
Spawn an Agent
- Creates a workspace (git worktree or clone)
- Launches Claude with the prompt delivered post-launch
- Installs the metadata updater hook
- Monitors JSONL for activity and cost
Resume a Session
View Session Info
- Session summary (from JSONL)
- Estimated cost
- Token usage
- Activity state
Advanced Features
JSONL Path Encoding
Claude stores sessions at~/.claude/projects/{encoded-path}/, where encoded-path is the workspace path with / and . replaced by -:
Long Command Handling
For system prompts exceeding 2000 characters, the plugin uses shell command substitution to avoid tmux truncation:Process Detection
The plugin checks if Claude is running by:- Tmux runtime: Find the pane’s TTY, then search
psoutput forclaudeon that TTY - Process runtime: Check if the PID in
handle.data.pidis alive viaprocess.kill(pid, 0)
Cache Optimization
The plugin cachesps output for 5 seconds to avoid spawning multiple concurrent ps processes when listing many sessions:
Troubleshooting
Hook script not updating metadata
Hook script not updating metadata
Cause: Hook not installed or AO_SESSION not setSolution:
- Check if
.claude/metadata-updater.shexists in workspace - Verify hook is registered in
.claude/settings.json: - Check if
AO_SESSIONenvironment variable is set (should be session ID)
Session introspection returns null
Session introspection returns null
Cause: JSONL file not found or path encoding mismatchSolution:
- Check if
~/.claude/projects/contains a matching directory - Manually encode the workspace path and verify:
- Ensure Claude has created at least one session file (*.jsonl)
Cost estimates seem wrong
Cost estimates seem wrong
Cause: Plugin uses Sonnet 4.5 pricing for all modelsSolution: Cost estimates are approximate. For accurate billing:
- Check Anthropic’s usage dashboard
- Parse the
costUSDfield from JSONL if available (newer Claude versions) - Adjust pricing in plugin source for other models (requires rebuild)
Agent stuck in 'active' state when idle
Agent stuck in 'active' state when idle
Cause:
readyThresholdMs too long, or permission prompt not detectedSolution:- Adjust threshold in config:
- Check terminal output for permission prompts (run
ao status <session>) - Attach to session to manually approve:
tmux attach -t <session-id>
Claude launches in one-shot mode (exits after response)
Claude launches in one-shot mode (exits after response)
Cause: Using
-p flag for prompt deliverySolution: This plugin intentionally avoids -p to keep Claude in interactive mode. Prompts are delivered post-launch via runtime.sendMessage(). Do not modify the launch command to include -p.Comparison with Other Agents
| Feature | Claude Code | Codex | Aider | OpenCode |
|---|---|---|---|---|
| Provider | Anthropic | OpenAI | Aider.chat | OpenCode |
| Session Files | JSONL | JSONL | Markdown | SQLite |
| Cost Tracking | ✅ Full | ✅ Full | ❌ None | ❌ None |
| Auto-metadata | ✅ PostToolUse hooks | ✅ PATH wrappers | ❌ None | ❌ None |
| Resume Support | ✅ Native | ✅ Native | ❌ None | ❌ None |
| Activity Detection | ✅ JSONL events | ✅ File mtime | ⚠️ Git commits only | ❌ None |
Environment Variables
The plugin sets these environment variables for introspection:Session identifier for metadata lookups
Project identifier (set by caller, not the plugin)
Issue/ticket identifier if applicable
Unset to avoid nested agent conflicts
The plugin explicitly unsets
CLAUDECODE to prevent nested Claude instances from interfering with each other.