[FEATURE] Let users default the Agent tool's run_in_background to true (and/or flip the default), so dispatching a subagent doesn't silently block the parent session

Status Fixed / completed
Maintainer reply ✓ Yes — bcherny
Activity 6 comments · opened Jun 27, 2026 · closed Aug 16, 2026
💡 Likely answer: A maintainer (bcherny, collaborator) responded on this thread — see the highlighted reply below.

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Priority: High - Significant impact on productivity
Feature Category: Configuration and settings

Problem Statement

When the model dispatches a subagent via the Agent tool, the run_in_background parameter defaults to false (foreground). A foreground Agent blocks the parent session synchronously: the parent — and the human watching it — is frozen until the subagent returns. For long or independent subagent work, that stall is pure waste, and it's especially painful when several sessions are open at once and each one blocks on its own foreground dispatch.

The safe choice (run_in_background: true) frees the parent immediately, but it has to be passed explicitly on every single Agent call. So avoiding the stall depends entirely on the model remembering to set the flag — and the more dangerous behavior (a silent, blocking parent) is the omitted-value default, i.e. the easiest thing to forget. The failure mode of the current default (parent silently stalls, sometimes for a long time) is worse than the failure mode of background (results simply arrive asynchronously).

Critically, there is currently no way for a user to change this default:

  • There is no settings.json key or environment variable for it. (disableAgentView turns the whole feature off; agent picks a default named subagent; --bg / /background govern the main session, not the Agent tool's parameter.)
  • Hook-based workarounds aren't reliable: a PreToolUse hook that injects the flag via updatedInput is not honored by the Claude Code desktop app, so on desktop there is no mechanical way to set this default at all — avoiding the stall is left entirely to the model's memory.

Net effect: the risky option is both the default and the hardest to enforce.

Proposed Solution

Give users a way to make background the default for Agent-tool dispatches. Either of the following would solve it (both acceptable; listed in order of preference):

(b) A settings.json key (opt-in, no behavior change for anyone who doesn't set it). For example:

{
  "agentDefaultRunInBackground": true
}

When set, an Agent call that omits run_in_background is treated as run_in_background: true. This must work on the desktop app too (the place where hook-based workarounds currently don't apply).

(a) Alternatively, flip the Agent tool's run_in_background default to true — at minimum for long-running / independent dispatches — on the grounds that a silent blocking stall is a worse default failure mode than asynchronous results.

Honest caveat: a blanket flip of (a) for every dispatch isn't strictly free — there are legitimate cases where you want to block and consume the subagent's result inline before continuing (e.g. a quick lookup whose answer you need now). That trade-off is exactly why the user-configurable setting (b) is the safer primary ask: it lets people who run lots of parallel/long dispatches opt into the non-blocking default without changing behavior for those who rely on foreground. A middle option would be to keep the tool default as-is but make the model's guidance bias toward background for clearly independent/long work.

Alternative Solutions

Workarounds tried, and why they fall short:

  • Passing run_in_background: true explicitly on every Agent call — works, but depends on the model remembering every time; the omitted default is the dangerous one.
  • A PreToolUse hook injecting the flag (updatedInput) — not honored by the desktop app, so it can't establish the default there.
  • disableAgentView / --bg / /background — none of these set the Agent tool's per-dispatch background default (see Problem Statement).

None of these give a durable, desktop-working way to make "don't block the parent" the default.

Use Case Example

  1. I have two or three Claude Code sessions open, each doing independent work.
  2. In one session the model decides to dispatch a subagent for a long, self-contained task (a broad search, a migration, a multi-file audit).
  3. Because run_in_background defaults to false, that session freezes until the subagent finishes — I can't steer it, and if I'm not watching, it just sits there. Meanwhile I'd happily have let it keep going and collected the subagent's result when it landed.
  4. With a setting (or a background-leaning default), the dispatch would return control immediately and notify me on completion, so none of the parallel sessions stalls on a dispatch I never needed to block on.

Additional Context

  • This is about the model-facing Agent tool's run_in_background parameter, which is distinct from the user-facing --bg flag / /background command (those send the main session to the background; they don't set the Agent tool's default).
  • I checked the settings reference: there is currently no key for this default.
  • The desktop-vs-CLI gap matters here: hook-based defaulting works (at best) only on the CLI, so a first-class setting is the only mechanism that would also work on the desktop app. (cf. #67197 on CLI/desktop agent-management inconsistency.)
  • Related but different: #68586 (Agent tool output_mode) touches the same tool surface but addresses how results enter context, not the background default.

View original on GitHub ↗

6 Comments

github-actions[bot] · 2 months ago

Found 1 possible duplicate issue:

  1. https://github.com/anthropics/claude-code/issues/22034

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

kcarriedo · 2 months ago

+1 on Option B (settings.json key). Flipping the global default is risky for existing workflows that depend on the blocking behavior, but a per-user opt-in is safe.

The PreToolUse hook gap you mention is a real problem -- it means the only current workarounds are (a) hoping the model remembers to pass the flag on every call, or (b) writing a custom MCP wrapper that intercepts Agent tool calls. Neither is maintainable at scale.

The silent-stall failure mode is worse than people realize. When a parent session is frozen waiting on a subagent, any background work scheduled on that session also stops. If you have 4 parallel sessions and 2 are blocked on foreground subagents, your effective concurrency just dropped by half with no warning.

One wrinkle: if you flip the default or add an opt-in, the completion notification path matters. Background agents today surface results through list_sessions polling -- is there a plan for a push-based result delivery so parents can react without polling loops?

odakin · 2 months ago

👎 on the duplicate suggestion. #22034 is about an agent-definition-level field (a background: true key in the YAML frontmatter of an individual agent file under ~/.claude/agents/, scoped to that agent's invocations). It does not change the default for ad-hoc Agent / spawn_task calls that don't reference a named agent definition.

#71768 is about the global default for the Agent tool's run_in_background parameter — i.e. a settings.json key that affects every dispatch, including the unnamed/ad-hoc ones that #22034 cannot touch. The two are complementary, not duplicates: #22034 (closed) addresses a different layer.

Keeping this open.

odakin · 2 months ago
is there a plan for a push-based result delivery so parents can react without polling loops?

I don't have insight into Anthropic's internal roadmap on this, but I'll share the operator-side mitigation I've been running in case it's useful while a native primitive is pending.

The pattern is: have the child write a completion marker file (token, status, result path, summary) at the moment it returns. A SessionStart hook then surfaces any unconsumed markers to the next session that opens in the same workspace. The parent doesn't poll list_sessions at all — it just receives an auto-surfaced "result is ready, here" reminder whenever it (or any sibling session) starts.

That's not equivalent to native push: the parent can't react within the same live turn unless it happens to poll, and "child completed" lands one session-boundary later. But it does eliminate the active polling loop, and it survives parent disconnect/restart — the marker waits on disk until consumed. It covers the "I dispatched 5 children, then closed the parent, then came back tomorrow" case that polling can't.

The caveat (relevant to your silent-stall failure mode point): when a foreground subagent is what's blocking, no marker pattern can help — the parent is frozen before it would have observed any marker. That's why the settings.json key (Option B) is the real upstream fix: avoiding the stall in the first place is strictly better than detecting it after the fact.

Strong +1 on the per-user opt-in framing.

github-actions[bot] · 14 days ago

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

bcherny collaborator · 14 days ago

Good news — this shipped. As of v2.1.198 subagents run in the background by default, so Claude keeps working while they run and gets notified when they finish; more recently the Agent tool no longer even offers a foreground option in interactive sessions. You can also pin a specific subagent to the background with background: true in its frontmatter. Changelog: https://github.com/anthropics/claude-code/blob/main/CHANGELOG.md and docs: https://code.claude.com/docs/en/sub-agents#run-subagents-in-foreground-or-background

Closing as shipped; please reopen if you still see blocking foreground dispatches on the latest version.

🤖 Generated with Claude Code