# Codeman Agent Teams Integration — Design (Approach C: Hybrid) > Updated 2026-02-12 with experiment findings. See `experiment-log.md` for raw data. ## Overview Approach C combines filesystem monitoring (for team/task discovery and inbox watching) with the existing subagent-watcher (for live transcript tailing) and adjusted idle detection (to account for active teammates). The key finding from our experiment is that **teammates already appear as standard subagents**, so most infrastructure exists — we mainly need team awareness and idle detection fixes. ## Components ### 1. TeamWatcher (`src/team-watcher.ts`) Monitors `~/.claude/teams/` for team creation/removal and tracks active teams. **Discovery mechanism:** - Poll `~/.claude/teams/` for directories (team names) every 3-5 seconds - When found: parse `config.json` to get: - `leadSessionId` → map to Codeman session - `members` array → teammate names, agentIds, colors, models - Watch for directory deletion (cleanup signal) **CORRECTED from pre-experiment design:** - ~~Each teammate has a separate Claude Code process~~ → Teammates are **in-process threads**, not separate processes - ~~Find via `ps aux` + `/proc` PID matching~~ → Not needed, no separate PIDs - Teammate transcripts are at `subagents/agent-{id}.jsonl` (standard subagent path), NOT separate session transcripts **Association:** - `config.json.leadSessionId` → Codeman session ID (direct match!) - Each member's `agentId` (e.g., `fs-researcher@research-watchers`) → links to subagent files - `agentType: "team-lead"` vs `"general-purpose"` distinguishes lead from teammates **Inbox monitoring:** - Watch `~/.claude/teams/{name}/inboxes/` for new messages - Each teammate has a JSON file with message array - Messages are double-encoded JSON with `from`, `text`, `timestamp`, `read` fields - Message types: `task_assignment`, `shutdown_request`, `shutdown_response` ### 2. Team-Aware Idle Detection (HIGHEST PRIORITY) **Problem (confirmed by experiment):** Lead session shows status "idle" in Codeman while teammates are actively working. Token count continues climbing but Codeman thinks the session is inactive. **Solution:** - Before declaring a session idle, check if it's a team lead - If team lead: check `~/.claude/teams/*/config.json` for this session's `leadSessionId` - If active team exists: check task files in `~/.claude/tasks/{team-name}/` - Any task with `status: "in_progress"` → suppress idle detection - All tasks `completed` AND no non-`_internal` tasks pending → allow idle - Fallback: check subagent-watcher for active subagents on this session **Integration points:** - `src/ai-idle-checker.ts` — add team-awareness check before AI idle analysis - `src/respawn-controller.ts` — consult TeamWatcher before transitioning to idle states - `src/session.ts` — expose `hasActiveTeam()` method **Liveness check (simplified from pre-experiment):** - ~~Check `/proc/{pid}` existence~~ → Not needed (no separate processes) - Check task file status instead (filesystem-based) - Check subagent-watcher for active subagents under this session ### 3. Shared Task List UI **Display:** New panel in web UI showing the team's shared task list. **Data source:** Poll `~/.claude/tasks/{team-name}/` for task JSON files. **Task file structure (verified):** ```json { "id": "1", "subject": "Research Node.js fs.watch", "description": "Full description...", "activeForm": "Researching Node.js fs.watch", "status": "in_progress", // pending | in_progress | completed "blocks": [], "blockedBy": [], "owner": "fs-researcher" // Empty string = unassigned } ``` Internal tracking tasks: `{ "metadata": { "_internal": true } }` — filter these from display. **UI elements:** - Task subject, status badge (color-coded), owner (teammate name with color) - Dependency visualization (blockedBy indicators) - Progress bar (completed / total non-internal tasks) - Real-time updates via SSE **API endpoint:** `GET /api/sessions/:id/team-tasks` → returns parsed task files **Locking:** Respect `.lock.lock` directory lock when reading (skip if locked, retry next poll). ### 4. Teammate Display **Decision: Option A — Enhanced subagent floating windows.** Since teammates already appear as subagents in the existing infrastructure, we enhance rather than replace: - **Badge:** Add "Teammate" badge to subagent windows for agents matching team config - **Color:** Use teammate's `color` field from config.json (blue, green, yellow) - **Name:** Show teammate name instead of agent ID - **Persistence:** Teammate windows should stay open longer (they're longer-lived than regular subagents) - **Status:** Show task assignment and progress from task files **Detection logic:** ``` For each subagent detected by subagent-watcher: 1. Check if description starts with "