# --bg Flag

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

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** claude --bg, --background, claude --exec

## Think of it like

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

## 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

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.

## Example code

```bash
claude --bg "investigate the flaky test"
```

Start a task and get the prompt back.

## Why it matters

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

## Common mistake

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

## Three principles

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

## Related terms

- [Background Session](https://learn.benibix.com/term/ai/background-session)
- [claude attach Command](https://learn.benibix.com/term/ai/claude-attach-command)
- [claude logs Command](https://learn.benibix.com/term/ai/claude-logs-command)
- [Non-Interactive Mode](https://learn.benibix.com/term/ai/non-interactive-mode)

## Taught in

- [Background Session Commands](https://learn.benibix.com/learn/ai-claude-code-commands/background-session-commands): Claude Code Commands, 7/17

![Where each launch flag sends the session: the background, the app, your machines, your editor.](https://learn.benibix.com/diagrams/flag-launch.svg)

---

Source: https://learn.benibix.com/term/ai/bg-flag
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
