@@ -78,14 +78,15 @@ type TmuxSession struct {
7878
7979// TmuxMetrics holds information about all tmux sessions
8080type TmuxMetrics struct {
81- Sessions []TmuxSession `json:"sessions"`
82- Total int `json:"total"`
83- Available bool `json:"available"`
84- Error string `json:"error,omitempty"`
85- LastUpdate time.Time `json:"last_update"`
86- HooksAvailable bool `json:"hooks_available"` // Whether hook-based tracking is active
87- HooksInstalled bool `json:"hooks_installed"` // Whether hooks are installed
88- Source string `json:"source"` // "hooks", "tmux", or "hybrid"
81+ Sessions []TmuxSession `json:"sessions"`
82+ Total int `json:"total"`
83+ Available bool `json:"available"`
84+ Error string `json:"error,omitempty"`
85+ LastUpdate time.Time `json:"last_update"`
86+ HooksAvailable bool `json:"hooks_available"` // Whether hook-based tracking is active
87+ HooksInstalled bool `json:"hooks_installed"` // Whether hooks are installed
88+ Source string `json:"source"` // "hooks", "tmux", or "hybrid"
89+ RunningProcesses int `json:"running_processes"` // Number of running claude processes
8990}
9091
9192// TmuxCollector collects metrics about tmux sessions
@@ -227,6 +228,7 @@ func (tc *TmuxCollector) Collect() *TmuxMetrics {
227228
228229 metrics .Available = hasTmux || hasHooks
229230 metrics .Total = len (metrics .Sessions )
231+ metrics .RunningProcesses = tc .countRunningClaudeProcesses ()
230232
231233 if ! metrics .Available && ! tc .isTmuxAvailable () {
232234 metrics .Error = "tmux is not installed or not available in PATH"
@@ -572,6 +574,28 @@ func (tc *TmuxCollector) fallbackStatus(session TmuxSession, now time.Time) Sess
572574 return StatusReady
573575}
574576
577+ // countRunningClaudeProcesses counts the number of running claude processes
578+ // This provides a reliable count independent of hooks or tmux
579+ func (tc * TmuxCollector ) countRunningClaudeProcesses () int {
580+ ctx , cancel := context .WithTimeout (context .Background (), tmuxCommandTimeout )
581+ defer cancel ()
582+
583+ // Use pgrep to count claude processes (exact match to avoid false positives)
584+ cmd := exec .CommandContext (ctx , "pgrep" , "-x" , "claude" )
585+ var stdout bytes.Buffer
586+ cmd .Stdout = & stdout
587+
588+ _ = cmd .Run () // Ignore error - pgrep returns 1 if no matches
589+
590+ output := strings .TrimSpace (stdout .String ())
591+ if output == "" {
592+ return 0
593+ }
594+
595+ // Count lines (each line is a PID)
596+ return len (strings .Split (output , "\n " ))
597+ }
598+
575599// GetMetrics is a convenience method that returns the collected metrics
576600func (tc * TmuxCollector ) GetMetrics () * TmuxMetrics {
577601 return tc .Collect ()
0 commit comments