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
--bgor its long form--backgroundto 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