all guides

Background work, explained by monkey

(plus the cheat sheet)

comment: JUGGLE

Claude Code can keep working while you do something else, from one long test to a whole session running off-screen. Here's every key and command on one cheat sheet, and the real difference between /subtask, /fork and /bg.

You don't have to sit and watch Claude run a long test. Claude Code can move work into the background at four sizes: one shell command, a helper inside your chat, a full copy of your session, or your whole session moved off the screen. Each one has its own key or command, and they're easy to mix up, so here's what each one does.

Cheat sheet

cheat sheet
Ctrl+B                send a running command to the background
/tasks                see the background commands and helpers in this chat
/subtask <task>       a helper that knows the whole chat. Its answer comes back here
/fork [prompt]        a full copy of the session that goes off on its own
/bg  (or ←)           move this whole session to the background
claude agents         one screen with every background session
claude --bg "..."     start a new session straight in the background

Ctrl+B: one long command

While Claude is running a shell command, like a long test, press Ctrl+B. The command keeps running in the background and Claude carries on with you. The output goes to a file Claude reads later.

  • In tmux, press Ctrl+B twice, or use Ctrl+X Ctrl+B.
  • It works on agents running in the foreground too, and on commands you run yourself with !.
  • A command that hits its time limit moves to the background by itself instead of being stopped.
  • /tasks (or /bashes) lists everything in the background in this session. From there you can check on one, open it or stop it.

/subtask: a helper that knows the whole chat

cheat sheet
/subtask draft unit tests for the parser changes so far

This starts a helper in the background that already knows everything in your conversation, so you don't have to explain anything again. You keep working, and when it's done, its answer comes back into your chat as a message. It needs v2.1.212 or later.

It shows up in a panel under the prompt:

  • ↑ and ↓ move between helpers.
  • Enter opens one, so you can read what it's doing and message it.
  • x stops it.
  • Esc takes you back to the prompt.

The subagents Claude starts by itself run in the background by default too, up to 20 at once. Pressing Ctrl+X Ctrl+K twice stops all of them.

/fork: a copy that goes off on its own

/fork copies your whole conversation into a new background session, and you keep working where you are. The copy gets its own row in agent view and makes its own git worktree, a separate working copy of your repo, before it edits anything. Its result does not come back to your chat. You check on it in agent view.

/bg: move this whole session to the background

/background, or /bg for short, moves the session you're in to the background and frees up your terminal. Pressing ← on an empty prompt does the same thing and opens agent view. You can give it one last instruction on the way out:

cheat sheet
/bg run the test suite and fix any failures

Or start a session that goes straight to the background, from your terminal:

terminal
claude --bg "investigate the flaky checkout test"     # a new background session
claude --bg --name "flaky-test-fix" "..."              # with a name
claude --bg --exec 'pytest -x'                         # a plain shell job, no Claude

claude agents: see every one

Run claude agents for one screen with every background session, grouped into Ready for review, Needs input, Working and Completed. Each row has a one-line summary. A yellow icon means it needs you, and a #1234 label links to the pull request it opened, turning green when the checks pass.

cheat sheet
Space        peek at a session and reply
Enter or →   attach to it
←            detach (on an empty prompt)
Ctrl+X       stop it. Press again within 2 seconds to delete it
Ctrl+T       pin it, so it keeps running
Ctrl+R       rename it
?            every shortcut

Type a prompt at the bottom and press Enter to start a new session. Back in a normal session, the footer shows something like ← 2 agents when background sessions are waiting on you. While agent view is open, you get a terminal notification when a session needs you, finishes or fails.

From the shell:

terminal
claude logs <id>       # what it's been doing
claude attach <id>     # jump into it
claude stop <id>       # stop it
claude rm <id>         # remove it
claude agents --json   # the list, for scripts

Tips most people don't know

  • /subtask, /fork and /bg aren't the same thing. /subtask is a helper whose answer comes back to this chat. /fork is a separate copy that keeps going on its own. /bg moves this conversation itself to the background.
  • Background sessions tidy up their own git work. A session started from agent view or with claude --bg works in its own worktree. When it's done it commits, pushes its branch and can open a draft pull request, but it never pushes to main, never force-pushes and never merges. If your CLAUDE.md says you handle git yourself, it leaves git to you.
  • A session you moved with ← or /bg doesn't get its own worktree. It keeps editing the files where it already was.
  • Pin with Ctrl+T. A session that's finished, or waiting for your next message, has its process stopped after about an hour with nobody attached. It picks up where it left off when you attach. Pinning keeps it running.

Careful

  • Every session uses your limits. Ten agents running at once use your quota roughly ten times as fast as one.
  • Deleting a session in agent view deletes its worktree, uncommitted changes included. Commit first.
  • Background sessions run on your computer. They survive sleep and closing the terminal, but stop when the computer shuts down.

Gotchas

  • Background subagents get a smaller set of tools, and their permission prompts pop up in your main session.
  • In unattended runs (-p, or the cloud), background commands are stopped after 30 minutes by default, 10 in a plain -p run, and 2 hours at most. In your own terminal sessions there's no limit.
  • claude --bg can't be combined with -p.
  • With agent view turned off (disableAgentView), /subtask disappears and /fork goes back to being the in-chat helper.
  • On a Mac, background sessions need their own Files and Folders permission to read Desktop, Documents or Downloads.
Agent viewthe official docs: claude agents, claude --bg, /bg and what background sessions do with gitCommands/subtask, /fork, /background and /tasksSubagents, explained by monkeyhow helpers work, plus a code reviewer to paste

Monkey believe in you. Now go build.

follow @nocodemonkey

More guides