[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M75WFZG03JV15GRC83GFJWW4":3,"skill-same:01M75WFZG03JV15GRC83GFJWW4":45},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":25,"commitSha":26,"skillDirectory":27,"forksCount":14,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":30,"updatedAt":31,"install":32,"resources":44},"01M75WFZG03JV15GRC83GFJWW4","spawn-agent",null,"Spawn Claude Agent in tmux Session","stevengonsalvez\u002Fainb-toolkit","stevengonsalvez","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F9320602?v=4","01M75W59QRYZYANWY3XG8CJB1P","Steven Gonsalvez","01M75W59RD5YW1RT67BDV0EAZF",1,"MIT","https:\u002F\u002Fgithub.com\u002Fstevengonsalvez\u002Fainb-toolkit\u002Fblob\u002Fmain\u002Fskills\u002Fspawn-agent\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: spawn-agent\ndescription: Spawn Claude Agent in tmux Session\nuser-invocable: true\n---\n\n# \u002Fspawn-agent - Spawn Claude Agent in tmux Session\n\nSpawn a Claude Code agent in a separate tmux session with optional handover context.\n\n> **Prefer `ainb run` for coding work in a git repo.** See `\u002Fcoding-agent`\n> Pattern 1 (or `\u002Fainb-fleet:ainb-spawn`): those sessions get an isolated\n> worktree, a correct workspace name, and fleet\u002FATC visibility, which raw tmux\n> sessions do not. Use `\u002Fspawn-agent` when `ainb` is not on PATH, the target is\n> not a git repo, or you specifically need the `--with-handover` contract and\n> the `agent-{timestamp}` registry that `\u002Frecover-sessions` and `\u002Ftmux-monitor`\n> read.\n\n## Usage\n\n```bash\n\u002Fspawn-agent \"implement user authentication\"\n\u002Fspawn-agent \"refactor the API layer\" --with-handover\n\u002Fspawn-agent \"implement feature X\" --with-worktree\n\u002Fspawn-agent \"review the PR\" --with-worktree --with-handover\n```\n\n## Implementation\n\n```bash\n#!\u002Fbin\u002Fbash\n\n# Function: Wait for Claude Code to be ready for input\nwait_for_claude_ready() {\n    local SESSION=$1\n    local TIMEOUT=30\n    local START=$(date +%s)\n\n    echo \"Waiting for Claude to initialize...\"\n\n    while true; do\n        # Capture pane output (suppress errors if session not ready)\n        PANE_OUTPUT=$(tmux capture-pane -t \"$SESSION\" -p 2>\u002Fdev\u002Fnull)\n\n        # Check for Claude prompt\u002Fsplash (any of these indicates readiness)\n        if echo \"$PANE_OUTPUT\" | grep -qE \"Claude Code|Welcome back|------|Style:|bypass permissions\"; then\n            # Verify not in error state\n            if ! echo \"$PANE_OUTPUT\" | grep -qiE \"error|crash|failed|command not found\"; then\n                echo \"Claude initialized successfully\"\n                return 0\n            fi\n        fi\n\n        # Timeout check\n        local ELAPSED=$(($(date +%s) - START))\n        if [ $ELAPSED -gt $TIMEOUT ]; then\n            echo \"Timeout: Claude did not initialize within ${TIMEOUT}s\"\n            echo \"Capturing debug output...\"\n            tmux capture-pane -t \"$SESSION\" -p > \"\u002Ftmp\u002Fspawn-agent-${SESSION}-failure.log\" 2>&1\n            echo \"Debug output saved to \u002Ftmp\u002Fspawn-agent-${SESSION}-failure.log\"\n            return 1\n        fi\n\n        sleep 0.2\n    done\n}\n\n# Parse arguments\nTASK=\"$1\"\nWITH_HANDOVER=false\nWITH_WORKTREE=false\nshift\n\n# Parse flags\nwhile [[ $# -gt 0 ]]; do\n    case $1 in\n        --with-handover)\n            WITH_HANDOVER=true\n            shift\n            ;;\n        --with-worktree)\n            WITH_WORKTREE=true\n            shift\n            ;;\n        *)\n            shift\n            ;;\n    esac\ndone\n\nif [ -z \"$TASK\" ]; then\n    echo \"Task description required\"\n    echo \"Usage: \u002Fspawn-agent \\\"task description\\\" [--with-handover] [--with-worktree]\"\n    exit 1\nfi\n\n# Generate session info\nTASK_ID=$(date +%s)\nSESSION=\"agent-${TASK_ID}\"\n\n# Setup working directory (worktree or current)\nif [ \"$WITH_WORKTREE\" = true ]; then\n    # Detect transcrypt (informational only - works transparently with worktrees)\n    if git config --get-regexp '^transcrypt\\.' >\u002Fdev\u002Fnull 2>&1; then\n        echo \"Transcrypt detected - worktree will inherit encryption config automatically\"\n        echo \"\"\n    fi\n\n    # Get current branch as base\n    CURRENT_BRANCH=$(git branch --show-current 2>\u002Fdev\u002Fnull || echo \"HEAD\")\n\n    # Generate task slug from task description\n    TASK_SLUG=$(echo \"$TASK\" | tr '[:upper:]' '[:lower:]' | sed 's\u002F[^a-z0-9 -]\u002F\u002Fg' | tr -s ' ' '-' | cut -c1-40 | sed 's\u002F-$\u002F\u002F')\n\n    # Source worktree utilities\n    SCRIPT_DIR=\"$(cd \"$(dirname \"${BASH_SOURCE[0]}\")\" && pwd)\"\n    source \"$SCRIPT_DIR\u002F..\u002Futils\u002Fgit-worktree-utils.sh\"\n\n    # Create worktree with task slug\n    echo \"Creating isolated git worktree...\"\n    WORK_DIR=$(create_agent_worktree \"$TASK_ID\" \"$CURRENT_BRANCH\" \"$TASK_SLUG\")\n    AGENT_BRANCH=\"agent\u002Fagent-${TASK_ID}\"\n\n    echo \"Worktree created:\"\n    echo \"   Directory: $WORK_DIR\"\n    echo \"   Branch: $AGENT_BRANCH\"\n    echo \"   Base: $CURRENT_BRANCH\"\n    echo \"\"\nelse\n    WORK_DIR=$(pwd)\n    AGENT_BRANCH=\"\"\nfi\n\necho \"Spawning Claude agent in tmux session...\"\necho \"\"\n\n# Generate handover if requested\nHANDOVER_CONTENT=\"\"\nif [ \"$WITH_HANDOVER\" = true ]; then\n    echo \"Generating handover context...\"\n\n    # Get current branch and recent commits\n    CURRENT_BRANCH=$(git branch --show-current 2>\u002Fdev\u002Fnull || echo \"unknown\")\n    RECENT_COMMITS=$(git log --oneline -5 2>\u002Fdev\u002Fnull || echo \"No git history\")\n    GIT_STATUS=$(git status -sb 2>\u002Fdev\u002Fnull || echo \"Not a git repo\")\n\n    # Create handover content\n    HANDOVER_CONTENT=$(cat \u003C\u003C EOF\n\n# Handover Context\n\n## Current State\n- Branch: $CURRENT_BRANCH\n- Directory: $WORK_DIR\n- Time: $(date)\n\n## Recent Commits\n$RECENT_COMMITS\n\n## Git Status\n$GIT_STATUS\n\n## Your Task\n$TASK\n\n---\nPlease review the above context and proceed with the task.\nEOF\n)\n\n    echo \"Handover generated\"\n    echo \"\"\nfi\n\n# Create tmux session\ntmux new-session -d -s \"$SESSION\" -c \"$WORK_DIR\"\n\n# Verify session creation\nif ! tmux has-session -t \"$SESSION\" 2>\u002Fdev\u002Fnull; then\n    echo \"Failed to create tmux session\"\n    exit 1\nfi\n\necho \"Created tmux session: $SESSION\"\necho \"\"\n\n# Start Claude Code in the session\ntmux send-keys -t \"$SESSION\" \"claude --dangerously-skip-permissions\" C-m\n\n# Wait for Claude to be ready (not just sleep!)\nif ! wait_for_claude_ready \"$SESSION\"; then\n    echo \"Failed to start Claude agent - cleaning up...\"\n    tmux kill-session -t \"$SESSION\" 2>\u002Fdev\u002Fnull\n    exit 1\nfi\n\n# Additional small delay for UI stabilization\nsleep 0.5\n\n# Send handover context if generated (line-by-line to handle newlines)\nif [ \"$WITH_HANDOVER\" = true ]; then\n    echo \"Sending handover context to agent...\"\n\n    # Send line-by-line to handle multi-line content properly\n    echo \"$HANDOVER_CONTENT\" | while IFS= read -r LINE || [ -n \"$LINE\" ]; do\n        # Use -l flag to send literal text (handles special characters)\n        tmux send-keys -t \"$SESSION\" -l \"$LINE\"\n        tmux send-keys -t \"$SESSION\" C-m\n        sleep 0.05  # Small delay between lines\n    done\n\n    # Final Enter to submit\n    tmux send-keys -t \"$SESSION\" C-m\n    sleep 0.5\nfi\n\n# Send the task (use literal mode for safety with special characters)\necho \"Sending task to agent...\"\ntmux send-keys -t \"$SESSION\" -l \"$TASK\"\ntmux send-keys -t \"$SESSION\" C-m\n\n# Small delay for Claude to start processing\nsleep 1\n\n# Verify task was received by checking if Claude is processing\nCURRENT_OUTPUT=$(tmux capture-pane -t \"$SESSION\" -p 2>\u002Fdev\u002Fnull)\nif echo \"$CURRENT_OUTPUT\" | grep -qE \"Thought for|Forming|Creating|Implement|*|~\"; then\n    echo \"Task received and processing\"\nelif echo \"$CURRENT_OUTPUT\" | grep -qE \"error|failed|crash\"; then\n    echo \"Warning: Detected error in agent output\"\n    echo \"Last 10 lines of output:\"\n    tmux capture-pane -t \"$SESSION\" -p | tail -10\nelse\n    echo \"Task sent (unable to confirm receipt - agent may still be starting)\"\nfi\n\necho \"\"\necho \"----------------------------------------------------------------\"\necho \"Agent spawned successfully!\"\necho \"----------------------------------------------------------------\"\necho \"\"\necho \"Session: $SESSION\"\necho \"Task: $TASK\"\necho \"Directory: $WORK_DIR\"\necho \"\"\necho \"To monitor:\"\necho \"  tmux attach -t $SESSION\"\necho \"\"\necho \"To send more commands:\"\necho \"  tmux send-keys -t $SESSION \\\"your command\\\" C-m\"\necho \"\"\necho \"To kill session:\"\necho \"  tmux kill-session -t $SESSION\"\necho \"\"\n\n# Source spawn-agent-lib for enhanced metadata functions\nSCRIPT_DIR=\"$(cd \"$(dirname \"${BASH_SOURCE[0]}\")\" && pwd)\"\nif [ -f \"$SCRIPT_DIR\u002F..\u002Futils\u002Fspawn-agent-lib.sh\" ]; then\n    source \"$SCRIPT_DIR\u002F..\u002Futils\u002Fspawn-agent-lib.sh\"\n\n    # Save enhanced metadata with transcript path support\n    save_agent_metadata \"$SESSION\" \"$TASK\" \"$WORK_DIR\" \"$WITH_HANDOVER\" \"$WITH_WORKTREE\" \"$AGENT_BRANCH\"\n\n    # Try to update transcript path after a brief delay (transcript may not exist immediately)\n    (sleep 5 && update_agent_transcript \"$SESSION\" \"$WORK_DIR\" 2>\u002Fdev\u002Fnull) &\nelse\n    # Fallback: save basic metadata if library not found\n    mkdir -p \u002F.claude\u002Fagents\n    cat > \u002F.claude\u002Fagents\u002F${SESSION}.json \u003C\u003CEOF\n{\n  \"session\": \"$SESSION\",\n  \"task\": \"$TASK\",\n  \"directory\": \"$WORK_DIR\",\n  \"created\": \"$(date -Iseconds)\",\n  \"status\": \"running\",\n  \"with_handover\": $WITH_HANDOVER,\n  \"with_worktree\": $WITH_WORKTREE,\n  \"worktree_branch\": \"$AGENT_BRANCH\"\n}\nEOF\nfi\n\nexit 0\n```\n\n## Multi-Tool Fallback\n\nDon't waste time debugging tool limits — switch immediately.\n\n```\nClaude Code (primary)\n    ↓ capped \u002F erroring \u002F stuck after 3 retries\nCodex CLI (secondary)\n    ↓ erroring \u002F unavailable\nManual intervention\n```\n\n### Pre-Spawn Availability Check\n\n```bash\n# Check Claude Code\nclaude --print \"reply with OK\" --dangerously-skip-permissions 2>&1 | \\\n  grep -qi \"rate.limit\\|capped\\|exceeded\\|429\" && echo \"CC_CAPPED\" || echo \"CC_OK\"\n\n# Check Codex\ncodex --help &>\u002Fdev\u002Fnull && echo \"CODEX_OK\" || echo \"CODEX_MISSING\"\n```\n\n### Fallback Spawning\n\nIf Claude Code is unavailable, spawn with Codex instead:\n\n```bash\n# Instead of: claude --dangerously-skip-permissions\n# Use:        codex --yolo -m gpt-5.3-codex\n\ntmux new-session -d -s \"$SESSION\" -c \"$WORK_DIR\"\ntmux send-keys -t \"$SESSION\" \"codex --yolo -m gpt-5.3-codex\" C-m\nsleep 2\ntmux send-keys -t \"$SESSION\" -l \"$TASK\"\ntmux send-keys -t \"$SESSION\" C-m\n```\n\n### Mid-Session Fallback\n\nIf Claude Code hits rate limits during a session:\n\n```bash\n# Kill the stuck session\ntmux kill-session -t \"$SESSION\"\n\n# Respawn with Codex, same worktree\nSESSION=\"codex-${SESSION#agent-}\"  # rename prefix to match spawn convention\ntmux new-session -d -s \"$SESSION\" -c \"$WORK_DIR\"\ntmux send-keys -t \"$SESSION\" \"codex --yolo -m gpt-5.3-codex\" C-m\nsleep 2\ntmux send-keys -t \"$SESSION\" -l \"$TASK\"\ntmux send-keys -t \"$SESSION\" C-m\n```\n\n---\n\n## Notes\n\n- Default agent is Claude Code with `--dangerously-skip-permissions`\n- Agent runs in tmux session named `agent-{timestamp}`\n- Use `tmux attach -t agent-{timestamp}` to monitor\n- Use `tmux send-keys` to send additional prompts\n- Metadata saved to `{{HOME_TOOL_DIR}}\u002Fagents\u002Fagent-{timestamp}.json`\n- **Session Recovery**: If tmux dies (crash\u002Fshutdown), use `\u002Frecover-sessions` to resume\n- Transcript path tracked for `--resume` capability\n- Session events logged to `{{HOME_TOOL_DIR}}\u002Fagents\u002Fregistry.jsonl`\n- Robust readiness detection with 30s timeout\n- Multi-line input handled correctly via line-by-line sending\n- Verification that task was received and processing started\n- Debug logs saved to `\u002Ftmp\u002Fspawn-agent-{session}-failure.log` on failures\n\n## Worktree Isolation\n\n- Use `--with-worktree` flag for isolated git workspace\n- Creates worktree in `worktrees\u002Fagent-{timestamp}-{task-slug}`\n  - Example: `worktrees\u002Fagent-1763250000-implement-user-auth`\n- Creates branch `agent\u002Fagent-{timestamp}` based on current branch\n- Transcrypt encryption inherited automatically (no special setup needed)\n- Use `\u002Flist-agent-worktrees` to see all worktrees\n- Use `\u002Fcleanup-agent-worktree {timestamp}` to remove when done\n\n## Troubleshooting\n\nIf spawn-agent fails:\n1. Check debug log: `\u002Ftmp\u002Fspawn-agent-{session}-failure.log`\n2. Verify Claude Code is installed: `which claude`\n3. Verify tmux is installed: `which tmux`\n4. Check existing sessions: `tmux list-sessions`\n5. Manually attach to debug: `tmux attach -t agent-{timestamp}`\n","# \u002Fspawn-agent - Spawn Claude Agent in tmux Session\n\nSpawn a Claude Code agent in a separate tmux session with optional handover context.\n\n> **Prefer `ainb run` for coding work in a git repo.** See `\u002Fcoding-agent`\n> Pattern 1 (or `\u002Fainb-fleet:ainb-spawn`): those sessions get an isolated\n> worktree, a correct workspace name, and fleet\u002FATC visibility, which raw tmux\n> sessions do not. Use `\u002Fspawn-agent` when `ainb` is not on PATH, the target is\n> not a git repo, or you specifically need the `--with-handover` contract and\n> the `agent-{timestamp}` registry that `\u002Frecover-sessions` and `\u002Ftmux-monitor`\n> read.\n\n## Usage\n\n```bash\n\u002Fspawn-agent \"implement user authentication\"\n\u002Fspawn-agent \"refactor the API layer\" --with-handover\n\u002Fspawn-agent \"implement feature X\" --with-worktree\n\u002Fspawn-agent \"review the PR\" --with-worktree --with-handover\n```\n\n## Implementation\n\n```bash\n#!\u002Fbin\u002Fbash\n\n# Function: Wait for Claude Code to be ready for input\nwait_for_claude_ready() {\n    local SESSION=$1\n    local TIMEOUT=30\n    local START=$(date +%s)\n\n    echo \"Waiting for Claude to initialize...\"\n\n    while true; do\n        # Capture pane output (suppress errors if session not ready)\n        PANE_OUTPUT=$(tmux capture-pane -t \"$SESSION\" -p 2>\u002Fdev\u002Fnull)\n\n        # Check for Claude prompt\u002Fsplash (any of these indicates readiness)\n        if echo \"$PANE_OUTPUT\" | grep -qE \"Claude Code|Welcome back|------|Style:|bypass permissions\"; then\n            # Verify not in error state\n            if ! echo \"$PANE_OUTPUT\" | grep -qiE \"error|crash|failed|command not found\"; then\n                echo \"Claude initialized successfully\"\n                return 0\n            fi\n        fi\n\n        # Timeout check\n        local ELAPSED=$(($(date +%s) - START))\n        if [ $ELAPSED -gt $TIMEOUT ]; then\n            echo \"Timeout: Claude did not initialize within ${TIMEOUT}s\"\n            echo \"Capturing debug output...\"\n            tmux capture-pane -t \"$SESSION\" -p > \"\u002Ftmp\u002Fspawn-agent-${SESSION}-failure.log\" 2>&1\n            echo \"Debug output saved to \u002Ftmp\u002Fspawn-agent-${SESSION}-failure.log\"\n            return 1\n        fi\n\n        sleep 0.2\n    done\n}\n\n# Parse arguments\nTASK=\"$1\"\nWITH_HANDOVER=false\nWITH_WORKTREE=false\nshift\n\n# Parse flags\nwhile [[ $# -gt 0 ]]; do\n    case $1 in\n        --with-handover)\n            WITH_HANDOVER=true\n            shift\n            ;;\n        --with-worktree)\n            WITH_WORKTREE=true\n            shift\n            ;;\n        *)\n            shift\n            ;;\n    esac\ndone\n\nif [ -z \"$TASK\" ]; then\n    echo \"Task description required\"\n    echo \"Usage: \u002Fspawn-agent \\\"task description\\\" [--with-handover] [--with-worktree]\"\n    exit 1\nfi\n\n# Generate session info\nTASK_ID=$(date +%s)\nSESSION=\"agent-${TASK_ID}\"\n\n# Setup working directory (worktree or current)\nif [ \"$WITH_WORKTREE\" = true ]; then\n    # Detect transcrypt (informational only - works transparently with worktrees)\n    if git config --get-regexp '^transcrypt\\.' >\u002Fdev\u002Fnull 2>&1; then\n        echo \"Transcrypt detected - worktree will inherit encryption config automatically\"\n        echo \"\"\n    fi\n\n    # Get current branch as base\n    CURRENT_BRANCH=$(git branch --show-current 2>\u002Fdev\u002Fnull || echo \"HEAD\")\n\n    # Generate task slug from task description\n    TASK_SLUG=$(echo \"$TASK\" | tr '[:upper:]' '[:lower:]' | sed 's\u002F[^a-z0-9 -]\u002F\u002Fg' | tr -s ' ' '-' | cut -c1-40 | sed 's\u002F-$\u002F\u002F')\n\n    # Source worktree utilities\n    SCRIPT_DIR=\"$(cd \"$(dirname \"${BASH_SOURCE[0]}\")\" && pwd)\"\n    source \"$SCRIPT_DIR\u002F..\u002Futils\u002Fgit-worktree-utils.sh\"\n\n    # Create worktree with task slug\n    echo \"Creating isolated git worktree...\"\n    WORK_DIR=$(create_agent_worktree \"$TASK_ID\" \"$CURRENT_BRANCH\" \"$TASK_SLUG\")\n    AGENT_BRANCH=\"agent\u002Fagent-${TASK_ID}\"\n\n    echo \"Worktree created:\"\n    echo \"   Directory: $WORK_DIR\"\n    echo \"   Branch: $AGENT_BRANCH\"\n    echo \"   Base: $CURRENT_BRANCH\"\n    echo \"\"\nelse\n    WORK_DIR=$(pwd)\n    AGENT_BRANCH=\"\"\nfi\n\necho \"Spawning Claude agent in tmux session...\"\necho \"\"\n\n# Generate handover if requested\nHANDOVER_CONTENT=\"\"\nif [ \"$WITH_HANDOVER\" = true ]; then\n    echo \"Generating handover context...\"\n\n    # Get current branch and recent commits\n    CURRENT_BRANCH=$(git branch --show-current 2>\u002Fdev\u002Fnull || echo \"unknown\")\n    RECENT_COMMITS=$(git log --oneline -5 2>\u002Fdev\u002Fnull || echo \"No git history\")\n    GIT_STATUS=$(git status -sb 2>\u002Fdev\u002Fnull || echo \"Not a git repo\")\n\n    # Create handover content\n    HANDOVER_CONTENT=$(cat \u003C\u003C EOF\n\n# Handover Context\n\n## Current State\n- Branch: $CURRENT_BRANCH\n- Directory: $WORK_DIR\n- Time: $(date)\n\n## Recent Commits\n$RECENT_COMMITS\n\n## Git Status\n$GIT_STATUS\n\n## Your Task\n$TASK\n\n---\nPlease review the above context and proceed with the task.\nEOF\n)\n\n    echo \"Handover generated\"\n    echo \"\"\nfi\n\n# Create tmux session\ntmux new-session -d -s \"$SESSION\" -c \"$WORK_DIR\"\n\n# Verify session creation\nif ! tmux has-session -t \"$SESSION\" 2>\u002Fdev\u002Fnull; then\n    echo \"Failed to create tmux session\"\n    exit 1\nfi\n\necho \"Created tmux session: $SESSION\"\necho \"\"\n\n# Start Claude Code in the session\ntmux send-keys -t \"$SESSION\" \"claude --dangerously-skip-permissions\" C-m\n\n# Wait for Claude to be ready (not just sleep!)\nif ! wait_for_claude_ready \"$SESSION\"; then\n    echo \"Failed to start Claude agent - cleaning up...\"\n    tmux kill-session -t \"$SESSION\" 2>\u002Fdev\u002Fnull\n    exit 1\nfi\n\n# Additional small delay for UI stabilization\nsleep 0.5\n\n# Send handover context if generated (line-by-line to handle newlines)\nif [ \"$WITH_HANDOVER\" = true ]; then\n    echo \"Sending handover context to agent...\"\n\n    # Send line-by-line to handle multi-line content properly\n    echo \"$HANDOVER_CONTENT\" | while IFS= read -r LINE || [ -n \"$LINE\" ]; do\n        # Use -l flag to send literal text (handles special characters)\n        tmux send-keys -t \"$SESSION\" -l \"$LINE\"\n        tmux send-keys -t \"$SESSION\" C-m\n        sleep 0.05  # Small delay between lines\n    done\n\n    # Final Enter to submit\n    tmux send-keys -t \"$SESSION\" C-m\n    sleep 0.5\nfi\n\n# Send the task (use literal mode for safety with special characters)\necho \"Sending task to agent...\"\ntmux send-keys -t \"$SESSION\" -l \"$TASK\"\ntmux send-keys -t \"$SESSION\" C-m\n\n# Small delay for Claude to start processing\nsleep 1\n\n# Verify task was received by checking if Claude is processing\nCURRENT_OUTPUT=$(tmux capture-pane -t \"$SESSION\" -p 2>\u002Fdev\u002Fnull)\nif echo \"$CURRENT_OUTPUT\" | grep -qE \"Thought for|Forming|Creating|Implement|*|~\"; then\n    echo \"Task received and processing\"\nelif echo \"$CURRENT_OUTPUT\" | grep -qE \"error|failed|crash\"; then\n    echo \"Warning: Detected error in agent output\"\n    echo \"Last 10 lines of output:\"\n    tmux capture-pane -t \"$SESSION\" -p | tail -10\nelse\n    echo \"Task sent (unable to confirm receipt - agent may still be starting)\"\nfi\n\necho \"\"\necho \"----------------------------------------------------------------\"\necho \"Agent spawned successfully!\"\necho \"----------------------------------------------------------------\"\necho \"\"\necho \"Session: $SESSION\"\necho \"Task: $TASK\"\necho \"Directory: $WORK_DIR\"\necho \"\"\necho \"To monitor:\"\necho \"  tmux attach -t $SESSION\"\necho \"\"\necho \"To send more commands:\"\necho \"  tmux send-keys -t $SESSION \\\"your command\\\" C-m\"\necho \"\"\necho \"To kill session:\"\necho \"  tmux kill-session -t $SESSION\"\necho \"\"\n\n# Source spawn-agent-lib for enhanced metadata functions\nSCRIPT_DIR=\"$(cd \"$(dirname \"${BASH_SOURCE[0]}\")\" && pwd)\"\nif [ -f \"$SCRIPT_DIR\u002F..\u002Futils\u002Fspawn-agent-lib.sh\" ]; then\n    source \"$SCRIPT_DIR\u002F..\u002Futils\u002Fspawn-agent-lib.sh\"\n\n    # Save enhanced metadata with transcript path support\n    save_agent_metadata \"$SESSION\" \"$TASK\" \"$WORK_DIR\" \"$WITH_HANDOVER\" \"$WITH_WORKTREE\" \"$AGENT_BRANCH\"\n\n    # Try to update transcript path after a brief delay (transcript may not exist immediately)\n    (sleep 5 && update_agent_transcript \"$SESSION\" \"$WORK_DIR\" 2>\u002Fdev\u002Fnull) &\nelse\n    # Fallback: save basic metadata if library not found\n    mkdir -p \u002F.claude\u002Fagents\n    cat > \u002F.claude\u002Fagents\u002F${SESSION}.json \u003C\u003CEOF\n{\n  \"session\": \"$SESSION\",\n  \"task\": \"$TASK\",\n  \"directory\": \"$WORK_DIR\",\n  \"created\": \"$(date -Iseconds)\",\n  \"status\": \"running\",\n  \"with_handover\": $WITH_HANDOVER,\n  \"with_worktree\": $WITH_WORKTREE,\n  \"worktree_branch\": \"$AGENT_BRANCH\"\n}\nEOF\nfi\n\nexit 0\n```\n\n## Multi-Tool Fallback\n\nDon't waste time debugging tool limits — switch immediately.\n\n```\nClaude Code (primary)\n    ↓ capped \u002F erroring \u002F stuck after 3 retries\nCodex CLI (secondary)\n    ↓ erroring \u002F unavailable\nManual intervention\n```\n\n### Pre-Spawn Availability Check\n\n```bash\n# Check Claude Code\nclaude --print \"reply with OK\" --dangerously-skip-permissions 2>&1 | \\\n  grep -qi \"rate.limit\\|capped\\|exceeded\\|429\" && echo \"CC_CAPPED\" || echo \"CC_OK\"\n\n# Check Codex\ncodex --help &>\u002Fdev\u002Fnull && echo \"CODEX_OK\" || echo \"CODEX_MISSING\"\n```\n\n### Fallback Spawning\n\nIf Claude Code is unavailable, spawn with Codex instead:\n\n```bash\n# Instead of: claude --dangerously-skip-permissions\n# Use:        codex --yolo -m gpt-5.3-codex\n\ntmux new-session -d -s \"$SESSION\" -c \"$WORK_DIR\"\ntmux send-keys -t \"$SESSION\" \"codex --yolo -m gpt-5.3-codex\" C-m\nsleep 2\ntmux send-keys -t \"$SESSION\" -l \"$TASK\"\ntmux send-keys -t \"$SESSION\" C-m\n```\n\n### Mid-Session Fallback\n\nIf Claude Code hits rate limits during a session:\n\n```bash\n# Kill the stuck session\ntmux kill-session -t \"$SESSION\"\n\n# Respawn with Codex, same worktree\nSESSION=\"codex-${SESSION#agent-}\"  # rename prefix to match spawn convention\ntmux new-session -d -s \"$SESSION\" -c \"$WORK_DIR\"\ntmux send-keys -t \"$SESSION\" \"codex --yolo -m gpt-5.3-codex\" C-m\nsleep 2\ntmux send-keys -t \"$SESSION\" -l \"$TASK\"\ntmux send-keys -t \"$SESSION\" C-m\n```\n\n---\n\n## Notes\n\n- Default agent is Claude Code with `--dangerously-skip-permissions`\n- Agent runs in tmux session named `agent-{timestamp}`\n- Use `tmux attach -t agent-{timestamp}` to monitor\n- Use `tmux send-keys` to send additional prompts\n- Metadata saved to `{{HOME_TOOL_DIR}}\u002Fagents\u002Fagent-{timestamp}.json`\n- **Session Recovery**: If tmux dies (crash\u002Fshutdown), use `\u002Frecover-sessions` to resume\n- Transcript path tracked for `--resume` capability\n- Session events logged to `{{HOME_TOOL_DIR}}\u002Fagents\u002Fregistry.jsonl`\n- Robust readiness detection with 30s timeout\n- Multi-line input handled correctly via line-by-line sending\n- Verification that task was received and processing started\n- Debug logs saved to `\u002Ftmp\u002Fspawn-agent-{session}-failure.log` on failures\n\n## Worktree Isolation\n\n- Use `--with-worktree` flag for isolated git workspace\n- Creates worktree in `worktrees\u002Fagent-{timestamp}-{task-slug}`\n  - Example: `worktrees\u002Fagent-1763250000-implement-user-auth`\n- Creates branch `agent\u002Fagent-{timestamp}` based on current branch\n- Transcrypt encryption inherited automatically (no special setup needed)\n- Use `\u002Flist-agent-worktrees` to see all worktrees\n- Use `\u002Fcleanup-agent-worktree {timestamp}` to remove when done\n\n## Troubleshooting\n\nIf spawn-agent fails:\n1. Check debug log: `\u002Ftmp\u002Fspawn-agent-{session}-failure.log`\n2. Verify Claude Code is installed: `which claude`\n3. Verify tmux is installed: `which tmux`\n4. Check existing sessions: `tmux list-sessions`\n5. Manually attach to debug: `tmux attach -t agent-{timestamp}`\n",{"name":5,"description":7,"user-invocable":24},true,"main","9cf32d1e636db09530158af14ba301bfa5d401e9","skills\u002Fspawn-agent","https:\u002F\u002Fgithub.com\u002Fstevengonsalvez\u002Fainb-toolkit","https:\u002F\u002Fgithub.com\u002Fstevengonsalvez","stevengonsalvez.com","2026-11-12 00:50:59",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":24},[34,37,40],{"tool":35,"command":36},"npx","npx skills add stevengonsalvez\u002Fainb-toolkit --skill spawn-agent",{"tool":38,"command":39},"bunx","bunx skills add stevengonsalvez\u002Fainb-toolkit --skill spawn-agent",{"tool":41,"command":42},"pnpm","pnpm dlx skills add stevengonsalvez\u002Fainb-toolkit --skill spawn-agent","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fstevengonsalvez\u002Fainb-toolkit\u002Fblob\u002Fmain\u002Fskills\u002Fspawn-agent\u002FSKILL.md",[],[46,53,60,66,73,80],{"skillNo":47,"name":48,"nameZh":6,"description":49,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":50,"categories":51,"keywords":52,"publishedAt":19},"01M75WK9B8DKVJBJJ4CX2QMJMX","well-formed","Fixture skill that satisfies every mechanical rule, used to prove the conformance check passes a clean tree instead of failing everything.","https:\u002F\u002Fgithub.com\u002Fstevengonsalvez\u002Fainb-toolkit\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fagentskills\u002Fclean\u002Fwell-formed\u002FSKILL.md",[],[],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M75WK6ZGDXJJN8879K49QEYG","underscore-tools","Fixture skill that spells the tool allowlist key with an underscore instead of the hyphen the spec requires.","https:\u002F\u002Fgithub.com\u002Fstevengonsalvez\u002Fainb-toolkit\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fagentskills\u002Fbroken\u002Funderscore-tools\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":19},"01M75WK524MVT2H9E27ZCEA3HR","no-frontmatter","https:\u002F\u002Fgithub.com\u002Fstevengonsalvez\u002Fainb-toolkit\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fagentskills\u002Fbroken\u002Fno-frontmatter\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":19},"01M75WJWZBMKR8R60PG3T3MCCC","long-description","Fixture skill with a deliberately oversized description used to prove the conformance check rejects anything past the 1024 character ceiling. Fixture skill with a deliberately oversized description used to prove the conformance check rejects anything past the 1024 character ceiling. Fixture skill with a deliberately oversized description used to prove the conformance check rejects anything past the 1024 character ceiling. Fixture skill with a deliberately oversized description used to prove the conformance check rejects anything past the 1024 character ceiling. Fixture skill with a deliberately oversized description used to prove the conformance check rejects anything past the 1024 character ceiling. Fixture skill with a deliberately oversized description used to prove the conformance check rejects anything past the 1024 character ceiling. Fixture skill with a deliberately oversized description used to prove the conformance check rejects anything past the 1024 character ceiling. Fixture skill with a deliberately oversized description used to prove the conformance check rejects anything past the 1024 character ceiling. Fixture skill with a deliberately oversized description used to prove the conformance check rejects anything past the 1024 character ceiling. Fixture skill with a deliberately oversized description used to prove the conformance check rejects anything past the 1024 character ceiling. Fixture skill with a deliberately oversized description used to prove the conformance check rejects anything past the 1024 character ceiling. Fixture skill with a deliberately oversized description used to prove the conformance check rejects anything past the 1024 character ceiling.","https:\u002F\u002Fgithub.com\u002Fstevengonsalvez\u002Fainb-toolkit\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fagentskills\u002Fbroken\u002Flong-description\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":19},"01M75WJVRH3J22WKED7E5D01S8","some-other-name","Fixture skill whose frontmatter name does not match its parent directory name.","https:\u002F\u002Fgithub.com\u002Fstevengonsalvez\u002Fainb-toolkit\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fagentskills\u002Fbroken\u002Fdir-mismatch\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":19},"01M75WJTC7H5FRP6S129VBSMZC","bad_Name","Fixture skill whose name uses an underscore and a capital letter, so it violates the agentskills.io name pattern.","https:\u002F\u002Fgithub.com\u002Fstevengonsalvez\u002Fainb-toolkit\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fagentskills\u002Fbroken\u002Fbad_Name\u002FSKILL.md",[],[]]