|
| 1 | +# Claude Sessions Monitor - Project Kickoff |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Build a CLI tool in Go called `csm` (Claude Sessions Monitor) that monitors Claude Code sessions and displays their status in the terminal. The tool should have zero external dependencies (standard library only) for easy distribution as a single binary. |
| 6 | + |
| 7 | +## Problem Being Solved |
| 8 | + |
| 9 | +When running multiple Claude Code sessions in different terminal tabs/windows, it's hard to keep track of which sessions are: |
| 10 | +- Actively working |
| 11 | +- Waiting for user input/approval |
| 12 | +- Idle or finished |
| 13 | + |
| 14 | +This tool watches `~/.claude/projects/` and provides a live dashboard showing all sessions and their current status. |
| 15 | + |
| 16 | +## Core Features |
| 17 | + |
| 18 | +### 1. Session Discovery |
| 19 | +- Scan `~/.claude/projects/` directory |
| 20 | +- Each subdirectory is a project (URL-encoded path like `%2Fhome%2Fuser%2Fproject`) |
| 21 | +- Find the most recent `.jsonl` log file in each project |
| 22 | +- Parse JSONL to determine session state |
| 23 | + |
| 24 | +### 2. Status Detection |
| 25 | +Parse the JSONL log entries to determine status: |
| 26 | + |
| 27 | +| Status | Condition | |
| 28 | +|--------|-----------| |
| 29 | +| **Working** | Recent assistant message, still streaming/processing | |
| 30 | +| **Needs Approval** | Last entry is assistant with `tool_use`, waiting for user to approve | |
| 31 | +| **Waiting** | Turn ended, waiting for user's next prompt | |
| 32 | +| **Idle** | No activity for 5+ minutes | |
| 33 | + |
| 34 | +Log entry types to look for: |
| 35 | +- `type: "assistant"` with `content[].type: "tool_use"` → tool requested |
| 36 | +- `type: "user"` with `content[].type: "tool_result"` → tool approved/executed |
| 37 | +- `type: "system"` with `turn_duration` → turn completed |
| 38 | +- Timestamps for activity tracking |
| 39 | + |
| 40 | +### 3. CLI Modes |
| 41 | + |
| 42 | +``` |
| 43 | +csm # Live view (default) - auto-updating dashboard |
| 44 | +csm -l # List once and exit |
| 45 | +csm -l -json # List as JSON |
| 46 | +csm -v # Version |
| 47 | +csm -interval 5s # Custom refresh interval (default 2s) |
| 48 | +``` |
| 49 | + |
| 50 | +### 4. Live View Display |
| 51 | + |
| 52 | +``` |
| 53 | +🤖 Claude Code Sessions |
| 54 | +
|
| 55 | +● Working: 2 ⚠ Needs Input: 1 ◉ Waiting: 0 ○ Idle: 3 |
| 56 | +
|
| 57 | + STATUS PROJECT LAST ACTIVITY CURRENT TASK |
| 58 | + ──────────────────────────────────────────────────────────────────────────────── |
| 59 | + ● Working myorg/api-server 5s ago Implementing auth middleware... |
| 60 | + ● Working myorg/frontend 12s ago Using: Edit |
| 61 | + ⚠ Needs Input personal/side-project 45s ago Using: Bash |
| 62 | + ○ Idle work/legacy-app 15m ago - |
| 63 | +
|
| 64 | + Press Ctrl+C to quit |
| 65 | +``` |
| 66 | + |
| 67 | +Use ANSI colors: |
| 68 | +- Green for Working |
| 69 | +- Yellow/Orange for Needs Input |
| 70 | +- Blue for Waiting |
| 71 | +- Gray for Idle |
| 72 | + |
| 73 | +### 5. List Mode Output |
| 74 | + |
| 75 | +``` |
| 76 | +STATUS PROJECT LAST ACTIVITY TASK |
| 77 | +──────────────────────────────────────────────────────────────────────────────── |
| 78 | +● Working myorg/api-server 5s ago Implementing auth... |
| 79 | +⚠ Needs Input personal/side-project 45s ago Using: Bash |
| 80 | +``` |
| 81 | + |
| 82 | +### 6. JSON Output |
| 83 | + |
| 84 | +```json |
| 85 | +[ |
| 86 | + {"project": "myorg/api-server", "status": "Working", "last_activity": "2024-01-15T10:30:00Z", "task": "Implementing..."}, |
| 87 | + {"project": "personal/side-project", "status": "Needs Approval", "last_activity": "2024-01-15T10:29:15Z", "task": "Using: Bash"} |
| 88 | +] |
| 89 | +``` |
| 90 | + |
| 91 | +## Project Structure |
| 92 | + |
| 93 | +``` |
| 94 | +claude-sessions-monitor/ |
| 95 | +├── main.go # CLI entry point, flag parsing |
| 96 | +├── internal/ |
| 97 | +│ ├── session/ |
| 98 | +│ │ └── session.go # Session discovery and JSONL parsing |
| 99 | +│ ├── watcher/ |
| 100 | +│ │ └── watcher.go # File system watching for changes |
| 101 | +│ └── ui/ |
| 102 | +│ └── ui.go # Terminal rendering (ANSI) |
| 103 | +├── go.mod |
| 104 | +├── README.md |
| 105 | +├── CHANGELOG.md |
| 106 | +└── Makefile # Build targets for multiple platforms |
| 107 | +``` |
| 108 | + |
| 109 | +## Technical Requirements |
| 110 | + |
| 111 | +1. **Zero external dependencies** - use only Go standard library |
| 112 | +2. **Cross-platform** - must work on macOS and Linux |
| 113 | +3. **Single binary** - easy to distribute |
| 114 | +4. **Efficient** - poll filesystem changes, don't hammer CPU |
| 115 | +5. **Graceful** - handle Ctrl+C cleanly, restore cursor |
| 116 | + |
| 117 | +## Build & Distribution |
| 118 | + |
| 119 | +Makefile should support: |
| 120 | +```makefile |
| 121 | +build: # Build for current platform |
| 122 | +build-all: # Build for linux/darwin, amd64/arm64 |
| 123 | +install: # Install to ~/.local/bin |
| 124 | +``` |
| 125 | + |
| 126 | +## JSONL Log Format Reference |
| 127 | + |
| 128 | +Each line in the log file is a JSON object: |
| 129 | + |
| 130 | +```json |
| 131 | +{"type": "user", "message": {"role": "user", "content": [{"type": "text", "text": "..."}]}, "timestamp": "..."} |
| 132 | +{"type": "assistant", "message": {"role": "assistant", "content": [{"type": "text", "text": "..."}]}, "timestamp": "..."} |
| 133 | +{"type": "assistant", "message": {"role": "assistant", "content": [{"type": "tool_use", "name": "Edit", "id": "..."}]}, "timestamp": "..."} |
| 134 | +{"type": "user", "message": {"role": "user", "content": [{"type": "tool_result", "tool_use_id": "..."}]}, "timestamp": "..."} |
| 135 | +{"type": "system", "message": {"turn_duration": 5.2}, "timestamp": "..."} |
| 136 | +``` |
| 137 | + |
| 138 | +## Getting Started |
| 139 | + |
| 140 | +1. Initialize the Go module |
| 141 | +2. Create the directory structure |
| 142 | +3. Implement session discovery first (can test with -l flag) |
| 143 | +4. Add the watcher for live updates |
| 144 | +5. Implement the terminal UI |
| 145 | +6. Add Makefile for builds |
| 146 | +7. Write README with installation instructions |
| 147 | + |
| 148 | +Start by exploring `~/.claude/projects/` to understand the actual structure, then implement session parsing. |
0 commit comments