Skip to content

ClaudeAgentOptions.backgroundTasks: false turns off background tasks - #25

Open
jpowersdev wants to merge 1 commit into
mainfrom
t3/claude-background-tasks
Open

jpowersdev wants to merge 1 commit into
mainfrom
t3/claude-background-tasks

Conversation

@jpowersdev

@jpowersdev jpowersdev commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

ClaudeAgentOptions.backgroundTasks: false sets CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1 on the session.

Why: when each turn is a whole job, an agent that puts a wait (CI checks, a long build) in the background ends its turn without waiting, and nothing wakes it later. Setting the variable by hand works, but this puts the switch where anyone using the Claude provider can find it.

What the variable does: checked against the bundled CLI. Bash loses its run_in_background parameter, so the model is never offered it, and subagents can't be backgrounded. A call that still passes the parameter is refused with an input validation error.

  • The option wins over env from the layer or the run.
  • HostSpec carries it, so detached sessions get it too.
  • The default is unchanged, so this ships as a patch.

Tests

  • Unit (buildOptions): false sets the variable even when RunOptions.env removes it; true leaves it unset.
  • e2e (test/background-tasks-e2e.test.ts), real claude against the mock Messages API: with the default, a Bash call with run_in_background: true runs in the background. With false, the same call is refused, both locally and detached.
  • Each test fails when its part of the fix is removed. pnpm typecheck and pnpm test pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant