How to raise only the background command time limit in unattended Claude Code runs
In sessions nobody is watching, such as -p runs, Agent SDK apps, CI jobs and cloud sessions, Claude Code puts a time limit on background Bash and PowerShell commands. A command Claude starts in the background gets 30 minutes (or the timeout it passes, up to 2 hours), and a foreground command moved to the background at its timeout gets 30 minutes from the move. In a -p run whose prompt you pass as text, both are 10 minutes. Local sessions you work in from the terminal, the desktop app or VS Code have no such limit.
- Claude Code 2.1.336 (December 3) added
BASH_DEFAULT_BACKGROUND_TIMEOUT_MS. It lengthens the default time limit of background commands in Agent SDK and cloud sessions and leaves foreground timeouts alone. This sets one hour.
export BASH_DEFAULT_BACKGROUND_TIMEOUT_MS=3600000
-
Before, you had to set
BASH_DEFAULT_TIMEOUT_MSabove 1800000 to replace the 30-minute default, which also raised the default foreground timeout (120000, two minutes). For a pipeline that runs long builds or tests in the background, the new variable is enough. -
A command that hits the limit stops with
Background command "<description>" was stopped after reaching its background time limit., and Claude can start it again with a longer timeout.
The new variable is only in the changelog so far, not the reference docs. The changelog names Agent SDK and cloud sessions only and doesn't say whether it applies to -p runs or can go past the 2-hour maximum. To go past 2 hours, set the documented BASH_MAX_TIMEOUT_MS above 7200000.
Sources
Get notified when a new tip lands
Tip alerts only go out in the app. Install it and turn notifications on.