---
description: "Enter AFK mode — autonomously process reviews, dispatch work, and monitor employees on a timer"
allowed-tools: Bash, Read, Glob, Grep, mcp__exe-mem__list_tasks, mcp__exe-mem__get_task, mcp__exe-mem__close_task, mcp__exe-mem__create_task, mcp__exe-mem__update_task, mcp__exe-mem__store_memory, mcp__exe-mem__recall_my_memory, mcp__exe-mem__ask_team_memory, mcp__exe-mem__send_message, mcp__exe-mem__store_behavior, mcp__exe-mem__get_identity
argument-hint: "[stop | interval-minutes]"
---

# AFK Mode — Autonomous COO Operations

The founder is stepping away. You (the COO) now operate autonomously.

## If argument is "stop"

Kill the background AFK loop and summarize:

```bash
# Kill the AFK background loop
AFK_PID=$(cat ~/.exe-os/afk-loop.pid 2>/dev/null)
if [ -n "$AFK_PID" ]; then
  kill "$AFK_PID" 2>/dev/null
  rm -f ~/.exe-os/afk-loop.pid ~/.exe-os/afk-loop.lock
  echo "AFK loop stopped (PID $AFK_PID)"
else
  echo "No active AFK loop found"
fi
```

Then read the AFK log and summarize what happened:
```bash
cat ~/.exe-os/afk-log.txt 2>/dev/null || echo "No AFK log found"
```

Print: "AFK mode ended. Here's what happened while you were away:" then summarize all actions from the log. Clean up the log file.

## Otherwise, start AFK mode

Default interval: 5 minutes. Override with argument (e.g., `/exe-afk 10` = every 10 min).

### Step 0: Check tmux requirement

AFK mode uses tmux send-keys to inject prompts on a timer. If this session is NOT inside tmux, AFK mode cannot work.

```bash
tmux display-message -p '#{session_name}' 2>/dev/null || echo "NOT_IN_TMUX"
```

If the result is "NOT_IN_TMUX" or empty, STOP and tell the user:

> AFK mode requires a tmux session. Start tmux first, then launch claude and run /exe-afk.

Do NOT proceed with the rest of the AFK setup. Exit the skill.

### Step 1: MCP health pre-check

Before starting the loop, verify the MCP daemon is alive. If it's down, the entire AFK cycle will fail silently.

```bash
# Check daemon PID liveness + socket existence
EXED_PID=$(cat ~/.exe-os/exed.pid 2>/dev/null)
EXED_SOCK="${EXE_DAEMON_SOCK:-${EXE_EMBED_SOCK:-$HOME/.exe-os/exed.sock}}"
if [ -z "$EXED_PID" ] || ! kill -0 "$EXED_PID" 2>/dev/null; then
  echo "MCP_UNHEALTHY: daemon not running (PID=$EXED_PID)"
elif [ ! -S "$EXED_SOCK" ]; then
  echo "MCP_UNHEALTHY: socket missing at $EXED_SOCK"
else
  echo "MCP_HEALTHY"
fi
```

If `MCP_UNHEALTHY`:
> MCP daemon is not running. Run `/mcp` to reconnect before starting AFK mode. AFK mode depends on MCP tools for task management.

Do NOT proceed. Exit the skill.

### Step 2: Determine the coordinator tmux session name
```bash
tmux display-message -p '#{session_name}' 2>/dev/null
```

### Step 3: Start the background ticker

This launches a background bash loop that sends review prompts into YOUR tmux session on the interval. Each send triggers a fresh Claude turn. The loop includes:
- **Cycle mutex** via lockfile — if the previous cycle is still running, skip
- **MCP health check** each cycle — if daemon is dead, log warning and skip
- **Timeout on tmux commands** — 2 second max per send-keys

```bash
INTERVAL_SECONDS=$((${INTERVAL_MINUTES:-5} * 60))
COORDINATOR_SESSION="${SESSION_NAME}"

# Clean up any existing loop
OLD_PID=$(cat ~/.exe-os/afk-loop.pid 2>/dev/null)
[ -n "$OLD_PID" ] && kill "$OLD_PID" 2>/dev/null
rm -f ~/.exe-os/afk-loop.lock

# Start the AFK ticker as a background process
nohup bash -c "
  echo \"AFK mode started at \$(date -Iseconds) — interval ${INTERVAL_SECONDS}s\" >> ~/.exe-os/afk-log.txt
  while true; do
    sleep ${INTERVAL_SECONDS}

    # Cycle mutex — skip if previous tick is still being processed
    if [ -f ~/.exe-os/afk-loop.lock ]; then
      echo \"AFK skip at \$(date -Iseconds) — previous cycle still running\" >> ~/.exe-os/afk-log.txt
      continue
    fi

    # MCP health check — skip cycle if daemon is dead
    EXED_PID=\$(cat ~/.exe-os/exed.pid 2>/dev/null)
    if [ -z \"\$EXED_PID\" ] || ! kill -0 \"\$EXED_PID\" 2>/dev/null; then
      echo \"AFK skip at \$(date -Iseconds) — MCP daemon not running\" >> ~/.exe-os/afk-log.txt
      continue
    fi

    # Create lock, send command with timeout, release lock
    touch ~/.exe-os/afk-loop.lock
    timeout 2 tmux send-keys -t '${COORDINATOR_SESSION}' '/exe-review' Enter 2>/dev/null
    SEND_RC=\$?
    if [ \$SEND_RC -ne 0 ]; then
      echo \"AFK error at \$(date -Iseconds) — tmux send-keys failed (rc=\$SEND_RC)\" >> ~/.exe-os/afk-log.txt
    else
      echo \"AFK tick at \$(date -Iseconds) — sent /exe-review to ${COORDINATOR_SESSION}\" >> ~/.exe-os/afk-log.txt
    fi
    rm -f ~/.exe-os/afk-loop.lock
  done
" > /dev/null 2>&1 &

# Save PID for stop command
echo $! > ~/.exe-os/afk-loop.pid
echo "AFK loop started — PID $!, interval ${INTERVAL_SECONDS}s, target session: ${COORDINATOR_SESSION}"
```

### Step 4: Confirm to founder

Print:
```
AFK MODE ACTIVE — checking every {N}m
Background loop PID: {PID}
Target session: {SESSION}

I'll automatically process reviews every {N} minutes.
Each tick sends /exe-review into this session — I'll handle it like a normal prompt.
Say /exe-afk stop when you return.
```

### Step 5: Do an immediate first tick

Don't wait for the first interval — process reviews RIGHT NOW before the founder leaves:

1. Run: `node "$(npm root -g)/exe-os/dist/bin/exe-pending-reviews.js" 2>/dev/null`
2. If reviews pending: process them (get_task -> verify -> close_task or reject)
3. Check blocked tasks: `list_tasks status=blocked`
4. Check idle employees: `timeout 2 tmux capture-pane` on active sessions

## What /exe-review does when triggered by AFK tick

Each time the background loop sends `/exe-review` into the session, you (the coordinator) will:

1. **Check pending reviews** — process each one:
   - Pull task with `get_task`
   - Read deliverable (exe/output/, git log, worktree branches)
   - Verify: tests pass? Output exists? Requirements met?
   - PASS -> `close_task` with result summary
   - FAIL -> `update_task` back to open with failure reason
   - UNCERTAIN -> skip, log for founder

2. **Check stuck employees** — `timeout 2 tmux capture-pane` on active sessions
3. **Check blocked tasks** — anything blocked >24h gets flagged
4. **Dispatch next work** — idle employees with open tasks get assigned

## Rules for autonomous operation
- NEVER make architectural decisions — those wait for founder
- NEVER modify code directly — dispatch to employees
- NEVER approve work you can't verify (no tests = no approval)
- DO process routine reviews (tests pass, output exists, requirements met)
- DO dispatch queued work to idle employees
- DO flag anything ambiguous for founder review
- If you hit context capacity (>80%), run `/exe-afk stop` and summarize
