@@ -427,21 +427,15 @@ func (e *Executor) IsSuspended(taskID int64) bool {
427427 return suspended
428428}
429429
430- // getClaudePID finds the PID of the Claude process for a task.
431- // It first checks the stored daemon session, then searches all sessions for the task window.
432- func (e * Executor ) getClaudePID (taskID int64 ) int {
433- ctx , cancel := context .WithTimeout (context .Background (), 3 * time .Second )
434- defer cancel ()
435-
436- windowName := TmuxWindowName (taskID )
437-
438- // Search all tmux sessions for a window with this task's name
439- out , err := exec .CommandContext (ctx , "tmux" , "list-panes" , "-a" , "-F" , "#{session_name}:#{window_name}:#{pane_index} #{pane_pid}" ).Output ()
440- if err != nil {
441- return 0
442- }
443-
444- for _ , line := range strings .Split (string (out ), "\n " ) {
430+ // findPanesForWindow parses tmux list-panes output and returns PIDs for panes
431+ // in windows matching the given name exactly. The input format is one line per pane:
432+ //
433+ // "session:window:pane pid"
434+ //
435+ // e.g. "task-daemon-123:task-5:0 12345"
436+ func findPanesForWindow (tmuxOutput , windowName string ) []int {
437+ var pids []int
438+ for _ , line := range strings .Split (tmuxOutput , "\n " ) {
445439 line = strings .TrimSpace (line )
446440 if line == "" {
447441 continue
@@ -456,16 +450,39 @@ func (e *Executor) getClaudePID(taskID int64) int {
456450 target := parts [0 ]
457451 pidStr := parts [1 ]
458452
459- // Only match panes in windows named after this task
460- if ! strings .Contains (target , windowName ) {
453+ // Parse target format: "session:window:pane" and match window name exactly
454+ targetParts := strings .SplitN (target , ":" , 3 )
455+ if len (targetParts ) < 2 {
456+ continue
457+ }
458+ if targetParts [1 ] != windowName {
461459 continue
462460 }
463461
464462 pid , err := strconv .Atoi (pidStr )
465463 if err != nil {
466464 continue
467465 }
466+ pids = append (pids , pid )
467+ }
468+ return pids
469+ }
470+
471+ // getClaudePID finds the PID of the Claude process for a task.
472+ // It first checks the stored daemon session, then searches all sessions for the task window.
473+ func (e * Executor ) getClaudePID (taskID int64 ) int {
474+ ctx , cancel := context .WithTimeout (context .Background (), 3 * time .Second )
475+ defer cancel ()
476+
477+ windowName := TmuxWindowName (taskID )
468478
479+ // Search all tmux sessions for a window with this task's name
480+ out , err := exec .CommandContext (ctx , "tmux" , "list-panes" , "-a" , "-F" , "#{session_name}:#{window_name}:#{pane_index} #{pane_pid}" ).Output ()
481+ if err != nil {
482+ return 0
483+ }
484+
485+ for _ , pid := range findPanesForWindow (string (out ), windowName ) {
469486 // Check if this is a Claude process or has Claude as child
470487 cmdOut , _ := exec .CommandContext (ctx , "ps" , "-p" , strconv .Itoa (pid ), "-o" , "comm=" ).Output ()
471488 if strings .Contains (string (cmdOut ), "claude" ) {
@@ -5093,31 +5110,7 @@ func (e *Executor) getPiPID(taskID int64) int {
50935110 return 0
50945111 }
50955112
5096- for _ , line := range strings .Split (string (out ), "\n " ) {
5097- line = strings .TrimSpace (line )
5098- if line == "" {
5099- continue
5100- }
5101-
5102- // Parse "session:window:pane pid"
5103- parts := strings .Fields (line )
5104- if len (parts ) != 2 {
5105- continue
5106- }
5107-
5108- target := parts [0 ]
5109- pidStr := parts [1 ]
5110-
5111- // Only match panes in windows named after this task
5112- if ! strings .Contains (target , windowName ) {
5113- continue
5114- }
5115-
5116- pid , err := strconv .Atoi (pidStr )
5117- if err != nil {
5118- continue
5119- }
5120-
5113+ for _ , pid := range findPanesForWindow (string (out ), windowName ) {
51215114 // Check if this is a Pi process or has Pi as child
51225115 cmdOut , _ := exec .CommandContext (ctx , "ps" , "-p" , strconv .Itoa (pid ), "-o" , "comm=" ).Output ()
51235116 if strings .Contains (string (cmdOut ), "pi" ) || strings .Contains (string (cmdOut ), "node" ) || strings .Contains (string (cmdOut ), "ty" ) {
0 commit comments