[Feature] Let an SDK / -p host declare its session attended, so background commands aren't stopped at 30 minutes (as in VS Code since 2.1.288)
Summary
Since 2.1.288, the background command time limit applies only to unattended sessions (-p, Agent SDK, CI, cloud); terminal, desktop and VS Code sessions have none. An SDK host has no way to say that its session is attended, so a chat UI built on the Agent SDK / -p --input-format stream-json still stops every run_in_background command at 30 minutes (2 h at most), even with a person watching the chat.
Current behaviour (read from the 2.1.291 bundle)
- The limit applies when the session is non-interactive and is neither the desktop app nor
CLAUDE_CODE_ENTRYPOINT=claude-vscode. - The only other way out is the host object's
disableBackgroundDeadline(), which onlyclaude mcp servecalls. No setting, environment variable orinitializeoption reaches it. CLAUDE_CODE_SESSION_ATTENDEDexists (the CLI sets it for its child processes), but the deadline does not read it.- So a third-party editor integration (ours is a VS Code extension that hosts Claude Code chats in its own webview) can only:
- spoof the native panel's entrypoint, which also changes everything else that entrypoint means (telemetry, IDE integration checks); or
- raise
BASH_MAX_TIMEOUT_MSand fill in a longtimeouton every background call.
We ship the second for now. It also raises the foreground maximum, and it can't cover a foreground command the CLI moves to the background later (Ctrl+B or auto-background), since no new tool call happens for that move.
Request
A supported way for an SDK host to declare its session attended, so it gets the same background-command behaviour as the VS Code panel. Any of these would work for us:
- Honour
CLAUDE_CODE_SESSION_ATTENDED=1in the session's own environment for the deadline check. - An
initializecontrol-request option (for exampleattended: true) or an SDK option that callsdisableBackgroundDeadline(). - A setting such as
backgroundTaskTimeout: "none".
Related: #80372 (background tasks stopped in long sessions, before 2.1.288).
Environment: Claude Code 2.1.291, Windows 11 and Linux, claude -p --input-format stream-json --output-format stream-json, entrypoint sdk-cli.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗