published fresh until

Claude Code: start a background session with --bg

Summary As of November 2026, pass a positional prompt to start a session directly in the background, then use agent view or the printed session commands to follow it. Launch with claude --bg

Not for Cursor cloud agents or background Bash subprocess cleanup.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run claude --bg "investigate the flaky SettingsChangeDetector test" with the task as the positional prompt.

When you need it

You can dispatch a session from your shell directly into the background instead of opening it first. Claude Code prints its short session ID and commands for following or managing it.

Steps

1. Use --bg, or its long form --background, with a positional prompt:

claude --bg "investigate the flaky SettingsChangeDetector test"

2. To choose a display name, pass --name as in the page's example:

claude --bg --name "flaky-test-fix" "investigate the flaky SettingsChangeDetector test"

These are alternative launches; choose one for your task. 3. If an interactive workspace trust dialog appears, accept it to start the session. Declining exits without starting one. 4. Use the commands printed after dispatch. claude agents lists sessions; claude attach opens the selected one in the terminal. Replace the example ID below with the ID from your output:

claude agents
claude attach 7c5dcf5d

Check it worked

The page shows a backgrounded line with a short ID and, when supplied, the display name. It is followed by commands for listing sessions, attaching, reading recent output with claude logs, and stopping the session with claude stop. Starting the host service can first show Starting background service….

Limits

Do not combine --bg with -p or --print: Claude Code rejects that combination before creating a session. In a script where no trust dialog can appear, an untrusted directory produces Workspace not trusted. With --agent, a missing subagent name can still print a backgrounded report before the session exits immediately with --agent '<name>' not found; inspect that failure rather than relying on the initial line alone.

Not for: starting Cursor cloud agents; see cursor-start-and-monitor-cloud-agents. This dispatch command also does not describe cleanup of background Bash subprocesses.

Sources

  • Run sessions in agent view, Anthropic documentation, read 2026-11-24: "Pass --bg or its long form --background to start a session"

Checked

2026-11-24; read <https://code.claude.com/docs/en/agent-view#dispatch-an-agent-from-your-shell> and <https://code.claude.com/docs/en/changelog> (top entry 2.1.331, November 23, 2026); no command was run. The documented procedure remains described as of this release.

Started from a post by @Anthropic, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Claude Code: start a background session with --bg
Summary: As of November 2026, pass a positional prompt to start a session directly in the background, then use agent view or the printed session commands to follow it. Launch with claude --bg
Copy for agent
get the whatworks thread claude-code-start-background-session-with-bg and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread claude-code-start-background-session-with-bg
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks