claude-code - 💡(How to fix) Fix Bash tool blocks `sleep` as first command — needs opt-out or configurable threshold [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46144Fetched 2026-04-11 06:27:54
View on GitHub
Comments
2
Participants
3
Timeline
5
Reactions
3
Author
Timeline (top)
labeled ×3commented ×2

Root Cause

In automated workflows (e.g., long-running ML training loops), Claude needs to periodically check on remote processes by waiting a fixed interval and then querying status:

sleep 300 && ssh gpu-server 'tail -50 ~/training.log'

Because sleep is blocked as the first command, you must either:

  1. Use run_in_background: true — but this returns immediately, and if the conversation has a stop hook that fires on each response, it creates a cascading problem: each hook trigger spawns another background task, resulting in dozens of orphaned background sleep processes.
  2. Prepend a dummy command like echo "wait" && sleep 300 && ... — this works but is fragile and unintuitive.
  3. Move sleep to the remote side (ssh server 'sleep 300 && ...') — this works but isn't always applicable (e.g., local file watching, waiting for a local build).

Fix Action

Workaround

For SSH-based monitoring, move the sleep to the remote server:

ssh server 'sleep 300 && grep "^ep=" ~/training.log | tail -15'

This avoids the local sleep restriction but doesn't help for purely local waiting scenarios.

Code Example

sleep 300 && ssh gpu-server 'tail -50 ~/training.log'

---

{
  "bash": {
    "allowSleepAsFirstCommand": true,
    "maxSleepSeconds": 600
  }
}

---

{
  "command": "sleep 300 && ssh server 'tail training.log'",
  "allowSleep": true
}

---

ssh server 'sleep 300 && grep "^ep=" ~/training.log | tail -15'
RAW_BUFFERClick to expand / collapse

Problem

The Bash tool currently blocks any sleep N command (where N ≥ 2) when it appears as the first command in a shell invocation. This forces users and Claude to use workarounds like run_in_background: true or remote-side sleep (ssh server 'sleep 300 && ...').

Why This Matters

In automated workflows (e.g., long-running ML training loops), Claude needs to periodically check on remote processes by waiting a fixed interval and then querying status:

sleep 300 && ssh gpu-server 'tail -50 ~/training.log'

Because sleep is blocked as the first command, you must either:

  1. Use run_in_background: true — but this returns immediately, and if the conversation has a stop hook that fires on each response, it creates a cascading problem: each hook trigger spawns another background task, resulting in dozens of orphaned background sleep processes.
  2. Prepend a dummy command like echo "wait" && sleep 300 && ... — this works but is fragile and unintuitive.
  3. Move sleep to the remote side (ssh server 'sleep 300 && ...') — this works but isn't always applicable (e.g., local file watching, waiting for a local build).

The Stop Hook Cascade Problem

When using automated loops with stop hooks:

  1. Claude runs sleep 300blocked, must use run_in_background
  2. Background task starts, Claude responds immediately
  3. Stop hook fires on response → triggers another iteration
  4. New iteration starts another sleep 300 background task
  5. Repeat → dozens of background sleep processes accumulate

This makes long-running monitoring workflows (ML training, CI/CD pipelines, deployment monitoring) extremely difficult to manage.

Proposed Solution

Add a configurable option to allow sleep as a first command in the Bash tool:

Option A: Setting in settings.json

{
  "bash": {
    "allowSleepAsFirstCommand": true,
    "maxSleepSeconds": 600
  }
}

Option B: Per-invocation flag

Similar to dangerouslyDisableSandbox, add a parameter like:

{
  "command": "sleep 300 && ssh server 'tail training.log'",
  "allowSleep": true
}

Option C: Increase the threshold

The current threshold of 2 seconds is very conservative. Raising it to 30-60 seconds would cover most polling use cases without significant risk.

Environment

  • Claude Code CLI (macOS)
  • Workflow: Automated ML training loop with stop hooks for continuous iteration
  • The workaround of remote-side sleep (ssh server 'sleep N && ...') works but isn't a general solution

Workaround

For SSH-based monitoring, move the sleep to the remote server:

ssh server 'sleep 300 && grep "^ep=" ~/training.log | tail -15'

This avoids the local sleep restriction but doesn't help for purely local waiting scenarios.

extent analysis

TL;DR

  • Consider adding a configurable option to allow sleep as the first command in the Bash tool to mitigate the blocking issue.

Guidance

  • Evaluate the proposed solution options (A, B, C) to determine the best approach for your specific use case.
  • Assess the trade-offs between using run_in_background: true, prepending a dummy command, or moving sleep to the remote side for your automated workflows.
  • Test the workaround of moving sleep to the remote server for SSH-based monitoring to see if it meets your needs.

Example

  • For SSH-based monitoring, use the remote-side sleep workaround: ssh server 'sleep 300 && grep "^ep=" ~/training.log | tail -15'

Notes

  • The current threshold of 2 seconds for blocking sleep commands may be too conservative, and increasing it could be a viable alternative.
  • The stop hook cascade problem can be mitigated by carefully managing background tasks and responses.

Recommendation

  • Apply a workaround, such as moving sleep to the remote server or prepending a dummy command, until a configurable option to allow sleep as the first command is implemented, as this will provide a more robust and intuitive solution for automated workflows.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING