Back to the cards

Ctrl+B — Background Running Commands

Press Ctrl+B while a bash command or agent is running to send it to the background. The task keeps executing while you regain control of the conversation immediately — Claude can answer new prompts as the work carries on.

This is perfect for long-running operations — builds, installs, test suites, dev servers — anything where you'd rather keep working than watch output scroll by.

How It Works

  1. Claude starts running a command (e.g., npm install, pytest, a build step) or a subagent
  2. You press Ctrl+B while it's executing
  3. Every running foreground task moves to the background and gets a task ID
  4. You can immediately type new prompts, ask questions, or run other commands
  5. The command's output streams to a file; Claude reads that file with its Read tool whenever it needs the results, and is notified when the task finishes

Ctrl+B only acts when there is a foreground task that can move to the background.

Checking on Background Tasks

  • /tasks (alias /bashes) — List running shells and subagents, open one for details, or stop it
  • Ask Claude — "How's that background task doing?" works; it can read the output so far
  • Stop all background subagents — Press Ctrl+X Ctrl+K twice within three seconds

Backgrounding Without the Key

You don't always need Ctrl+B:

  • Ask for it up front. "Start the dev server in the background, then check the homepage" — Claude launches it that way from the start.
  • Timeouts do it for you. When a foreground command hits its timeout before finishing, Claude Code moves it to the background instead of killing it (unless the command starts with sleep).
  • Background the whole session. /bg sends the entire conversation to a background session and frees your terminal; Ctrl+B is for individual tasks inside the session.
Ctrl+BAsk Claude/bg
WhenAfter a task starts runningBefore it startsAny time
MovesThe running command or agentThat one commandThe whole conversation

How Long Background Work Runs

In a session you're working in — a terminal, the desktop app, or VS Code — background commands have no time limit. They're stopped when you exit Claude Code (unless you background the session instead, in which case they keep running there). In sessions that run unattended, such as claude -p runs and cloud sessions, a background command gets 30 minutes by default and up to 2 hours if Claude asks for longer; Claude is told when one is stopped.

Try It Now

  1. Ask Claude to run a command that takes a few seconds, like:

    "Run sleep 8; echo 'Background task complete!'"

  2. While it's running, press Ctrl+B
  3. Notice you get control back right away
  4. Run /tasks to see it listed, then ask Claude what it printed

Gotchas

  • tmux users: Ctrl+B is tmux's prefix key, so press it twice — or use the Ctrl+X Ctrl+B chord, which does the same thing without the conflict
  • To disable backgrounding entirely, set CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1; commands then stop at their timeout
  • The binding is task:background in keybindings.json if you want a different key

Pro tip: Start dev servers and watchers in the background on purpose, then ask Claude to check their output after each change — "anything new in the server log?" turns a background task into a live feedback loop.

  • Queue messages — Press Enter to queue prompts while Claude is working
  • Background agents — Run agent work in the background from the start
  • /bg — Send the whole session to the background and reattach later
  • Monitor Tool — Let Claude watch a background process and react to its output
  • Agent tool — Claude spawns specialized subagents for parallel work
Rate this tip