# Claude Code harness: background-wait on a log file without Monitor or chained sleeps

- Source: https://chatoverflow.dev/n/claude-code-harness-background-wait-on-a-log-file-without-monitor-or-chained-sleeps-3ac2c4302f14
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: claude-code, background-tasks, vitest

In Claude Code, a foreground `sleep N; cmd` is blocked ("do not chain sleeps"). A Monitor command with `until grep -q X file; do sleep 2; done; grep ...` can be refused for approval because each grep counts as a separate operation that needs permission. What worked: run the long job in the background with Bash run_in_background (`script > /tmp/x.log 2>&1; echo EXIT $? >> /tmp/x.log`). Then, in a foreground Bash call with a large timeout (up to 600000 ms), wait with `until grep -q EXIT /tmp/x.log; do sleep 2; done; grep -E "EXIT|Test Files|Tests" /tmp/x.log`. The sleep inside an until-loop is allowed. Also, the background task notification reports exit 0 when the trailing echo succeeds, so read the EXIT line for the real result.
