|
| 1 | +--- |
| 2 | +description: Debug Agent Tracker session tracking issues with a systematic diagnostic workflow |
| 3 | +proactive: false |
| 4 | +--- |
| 5 | + |
| 6 | +# Debug Agent Tracker |
| 7 | + |
| 8 | +You are helping debug Agent Tracker session tracking issues. Use this systematic workflow to diagnose problems. |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +Agent Tracker tracks Claude Code sessions via hooks that write events to `~/.agent-tracker/sessions.jsonl`. The TUI reads this file and displays sessions in real-time. |
| 13 | + |
| 14 | +## Quick Diagnosis Workflow |
| 15 | + |
| 16 | +When a session isn't showing up or behaving correctly, follow these steps: |
| 17 | + |
| 18 | +### Step 1: Check if Events are Being Written |
| 19 | + |
| 20 | +First, verify that events are being captured: |
| 21 | + |
| 22 | +```bash |
| 23 | +# Watch for new events in real-time |
| 24 | +tail -f ~/.agent-tracker/sessions.jsonl |
| 25 | +``` |
| 26 | + |
| 27 | +**Expected**: You should see JSON events appearing as Claude activity happens. |
| 28 | + |
| 29 | +**If no events appear**: |
| 30 | +- Hooks may not be installed or enabled |
| 31 | +- Check `.claude/settings.json` for enabled plugins |
| 32 | +- Verify plugin installation with `claude plugin list` |
| 33 | + |
| 34 | +### Step 2: View Event Timeline for the Session |
| 35 | + |
| 36 | +Check the chronological sequence of events: |
| 37 | + |
| 38 | +```bash |
| 39 | +# View timeline for specific session |
| 40 | +npm run debug:timeline -- --session-id <SESSION_ID> --limit 30 |
| 41 | + |
| 42 | +# Or filter by project directory |
| 43 | +npm run debug:timeline -- --cwd /path/to/project |
| 44 | +``` |
| 45 | + |
| 46 | +**Look for:** |
| 47 | +- ✓ `session_start` event exists |
| 48 | +- ✓ Activity events (tool_use, prompt_submit, stop) |
| 49 | +- ⚠️ `session_end` followed by more activity → **Session was re-opened** |
| 50 | +- ⚠️ Large gaps in activity → **Hooks may have stopped firing** |
| 51 | +- ⚠️ No `session_start` → **Hook didn't fire on session start** |
| 52 | + |
| 53 | +**Common patterns:** |
| 54 | +``` |
| 55 | +12:30:48 session_start |
| 56 | +12:31:15 tool_use Read |
| 57 | +12:45:54 session_end |
| 58 | +12:50:15 tool_use Read ← Activity after end = reopened session |
| 59 | +``` |
| 60 | + |
| 61 | +### Step 3: Check Current Session State |
| 62 | + |
| 63 | +View exactly what the TUI sees: |
| 64 | + |
| 65 | +```bash |
| 66 | +# View specific session state |
| 67 | +npm run debug:sessions -- --session-id <SESSION_ID> |
| 68 | + |
| 69 | +# View all sessions |
| 70 | +npm run debug:sessions |
| 71 | +``` |
| 72 | + |
| 73 | +**Key fields to check:** |
| 74 | + |
| 75 | +```json |
| 76 | +{ |
| 77 | + "status": "active", // Should be "active" for running sessions |
| 78 | + "isPhantom": false, // Should be false for real sessions |
| 79 | + "awaitingInput": true, // True = waiting for user, false = Claude working |
| 80 | + "lastActivityTime": "...", // Should match recent activity |
| 81 | + "endTime": null, // Should be null/undefined for active sessions |
| 82 | + "workSummary": "..." // Current work description |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +### Step 4: Diagnose Common Issues |
| 87 | + |
| 88 | +#### Issue: Session showing as "ended" but is still active |
| 89 | + |
| 90 | +**Symptoms:** |
| 91 | +- Timeline shows activity after `session_end` |
| 92 | +- Session state shows `status: "ended"` |
| 93 | + |
| 94 | +**Cause:** Session was ended and then re-opened. Activity events should re-activate the session. |
| 95 | + |
| 96 | +**Fix:** Session re-activation logic should handle this automatically (fixed in recent versions). If not working, check ActivityStore reducer. |
| 97 | + |
| 98 | +#### Issue: Session marked as phantom (`isPhantom: true`) |
| 99 | + |
| 100 | +**Symptoms:** |
| 101 | +- Session exists but doesn't appear in TUI |
| 102 | +- `isPhantom: true` in session state |
| 103 | + |
| 104 | +**Cause:** Transcript file appears to be a phantom (very small, not modified after creation) |
| 105 | + |
| 106 | +**Check:** |
| 107 | +```bash |
| 108 | +# Check transcript file size and times |
| 109 | +ls -lh ~/.claude/projects/.../SESSION_ID.jsonl |
| 110 | +stat -f "size=%z birthtime=%SB mtime=%Sm" ~/.claude/projects/.../SESSION_ID.jsonl |
| 111 | +``` |
| 112 | + |
| 113 | +**Criteria for phantom:** |
| 114 | +- File size < 50KB AND |
| 115 | +- Modified time - birth time < 60 seconds |
| 116 | + |
| 117 | +#### Issue: Missing session (not in output at all) |
| 118 | + |
| 119 | +**Symptoms:** |
| 120 | +- No session found in `debug:sessions` output |
| 121 | +- Timeline shows no events for session |
| 122 | + |
| 123 | +**Debugging steps:** |
| 124 | +1. Check if session_start event was written to sessions.jsonl |
| 125 | +2. Verify hooks are enabled for this project |
| 126 | +3. Check if session was started before hooks were installed |
| 127 | +4. Look for errors in hook scripts |
| 128 | + |
| 129 | +#### Issue: `lastActivityTime` is old but timeline shows recent activity |
| 130 | + |
| 131 | +**Symptoms:** |
| 132 | +- Timeline has recent events |
| 133 | +- Session state shows old `lastActivityTime` |
| 134 | + |
| 135 | +**Cause:** Activity events aren't updating session state, or transcript polling isn't working |
| 136 | + |
| 137 | +**Check:** |
| 138 | +- Are activity events being dispatched to ActivityStore? |
| 139 | +- Is transcript polling enabled in App.tsx? |
| 140 | + |
| 141 | +## Debug Tool Reference |
| 142 | + |
| 143 | +### `npm run debug:sessions` |
| 144 | + |
| 145 | +**Purpose:** Dump current session state as JSON |
| 146 | + |
| 147 | +**Options:** |
| 148 | +- `--session-id <id>` - View single session |
| 149 | +- `--format pretty|compact` - Output formatting (default: pretty) |
| 150 | +- `--no-counts` - Exclude session counts |
| 151 | +- `--no-stats` - Exclude activity statistics |
| 152 | + |
| 153 | +**Output includes:** |
| 154 | +- All session metadata |
| 155 | +- Session status and states |
| 156 | +- Activity counts and statistics |
| 157 | +- Recent activity events |
| 158 | + |
| 159 | +### `npm run debug:timeline` |
| 160 | + |
| 161 | +**Purpose:** Show chronological event timeline |
| 162 | + |
| 163 | +**Options:** |
| 164 | +- `--session-id <id>` - Filter by session |
| 165 | +- `--cwd <path>` - Filter by project directory |
| 166 | +- `--limit <n>` - Number of events to show (default: 50) |
| 167 | +- `--format table|json` - Output format (default: table) |
| 168 | + |
| 169 | +**Event types shown:** |
| 170 | +- `session_start` - Session began |
| 171 | +- `session_end` - Session ended |
| 172 | +- `tool_use` - Claude used a tool (shows tool name) |
| 173 | +- `prompt_submit` - User submitted input |
| 174 | +- `stop` - Claude finished responding |
| 175 | +- `notification` - System notification |
| 176 | +- `subagent_stop` - Subagent finished |
| 177 | + |
| 178 | +## Advanced Debugging |
| 179 | + |
| 180 | +### Check Raw Event Structure |
| 181 | + |
| 182 | +If you need to see the exact event format: |
| 183 | + |
| 184 | +```bash |
| 185 | +# View specific event types |
| 186 | +grep "session_start" ~/.agent-tracker/sessions.jsonl | tail -1 | jq . |
| 187 | + |
| 188 | +# View events for a session |
| 189 | +grep "SESSION_ID" ~/.agent-tracker/sessions.jsonl | jq . |
| 190 | +``` |
| 191 | + |
| 192 | +### Test Hook Installation |
| 193 | + |
| 194 | +Create a test session to verify hooks fire: |
| 195 | + |
| 196 | +```bash |
| 197 | +# In a separate terminal |
| 198 | +cd /tmp && claude "echo test" |
| 199 | +``` |
| 200 | + |
| 201 | +Check if events appear in `~/.agent-tracker/sessions.jsonl`. |
| 202 | + |
| 203 | +### Monitor in Real-Time |
| 204 | + |
| 205 | +Set up multi-terminal debugging: |
| 206 | + |
| 207 | +**Terminal 1:** Run Agent Tracker TUI |
| 208 | +```bash |
| 209 | +npm run dev |
| 210 | +``` |
| 211 | + |
| 212 | +**Terminal 2:** Watch events |
| 213 | +```bash |
| 214 | +tail -f ~/.agent-tracker/sessions.jsonl |
| 215 | +``` |
| 216 | + |
| 217 | +**Terminal 3:** Start test Claude session |
| 218 | +```bash |
| 219 | +claude "list files" |
| 220 | +``` |
| 221 | + |
| 222 | +You should see events in Terminal 2 and session in Terminal 1 immediately. |
| 223 | + |
| 224 | +## Key Architecture Points |
| 225 | + |
| 226 | +- **Redux-style state**: ActivityStore uses pure reducers |
| 227 | +- **Event-driven**: Everything flows from JSONL events |
| 228 | +- **Session re-activation**: Activity events re-activate ended sessions |
| 229 | +- **Phantom detection**: Based on transcript file size and timestamps |
| 230 | +- **Transcript polling**: Fallback for when hooks don't fire |
| 231 | + |
| 232 | +## Quick Fixes |
| 233 | + |
| 234 | +### Hooks not firing |
| 235 | +```bash |
| 236 | +# Reinstall plugin |
| 237 | +claude plugin uninstall agent-tracker |
| 238 | +claude plugin install agent-tracker |
| 239 | +``` |
| 240 | + |
| 241 | +### Session state incorrect |
| 242 | +```bash |
| 243 | +# Check if ActivityStore reducer is handling events |
| 244 | +npm run debug:timeline -- --session-id <ID> |
| 245 | +npm run debug:sessions -- --session-id <ID> |
| 246 | +# Compare timestamps - should match |
| 247 | +``` |
| 248 | + |
| 249 | +### Phantom session issue |
| 250 | +Check transcript file - if it's actually large and actively used, the phantom detection threshold may need adjustment in ActivityStore.ts:50. |
| 251 | + |
| 252 | +## When to Escalate |
| 253 | + |
| 254 | +If after following this workflow you can't identify the issue: |
| 255 | + |
| 256 | +1. Gather diagnostics: |
| 257 | + ```bash |
| 258 | + npm run debug:sessions -- --format compact > session-state.json |
| 259 | + npm run debug:timeline -- --session-id <ID> --format json > timeline.json |
| 260 | + ``` |
| 261 | + |
| 262 | +2. Check for console errors in the TUI |
| 263 | + |
| 264 | +3. Review recent changes to ActivityStore, SessionTrackerService, or event processing |
| 265 | + |
| 266 | +4. File an issue with diagnostics attached |
0 commit comments