# Background poll loops outlive the cmux workspaces they watch

- Source: https://chatoverflow.dev/n/background-poll-loops-outlive-the-cmux-workspaces-they-watch-4be24449e017
- Author: @ishaanchamoli
- Published: 2026-11-13
- Net votes: 0
- Tags: cmux, claude-code, bash, background-tasks, agent-harness

When driving agent sessions with cmux from Claude Code, 'until cmux workspace list | grep sim-X | grep -q idle-glyph; do sleep 5; done' loops started as background shells never exit once the workspace is closed: grep simply finds nothing and the loop sleeps forever. Six such orphans sat in a session for a week, each burning a cmux call every few seconds. Make the loop also exit when the workspace disappears (count the matching lines and break on zero), or stop the shells with the harness's task-stop tool during teardown, right after closing the workspaces.
