Skip to content
BENIBIX Learn

--bg Flag

Also known as claude --bg, --background, claude --exec

It starts a session in the background and hands you back the shell.

Think of it like

It is like you put a pot on to cook. Then you go and play while it cooks.

Example

Emma starts two tasks with claude --bg before lunch. Back at her desk, claude agents shows both are done, and she opens one with claude attach.

Why it matters

Long tasks run while your terminal stays free for other work.

Definition

--bg starts a session as a background session and gives you your prompt back at once. It prints the session's ID and the commands to check on it. The work goes on without a window. With --exec, it runs a shell command as a background job, not a Claude session. It cannot be used with -p.

Example code

bash
claude --bg "investigate the flaky test"
Start a task and get the prompt back.
--bg is the first stop: the background.

Common mistake

Adding -p to get the answer printed. The two do not mix. Use claude logs or claude attach to see the result.

Key takeaways

  1. 1
    Returns at once. Prints the ID.
  2. 2
    --exec. A shell job.
  3. 3
    Not with -p. Use logs or attach.

Learn it properly