Backgrounding tasks and sessions in Claude Code
Learn how Claude Code background tasks and sessions keep commands running and enable terminal reattachment.
Lesson Content
Some commands just take a while to run, such as running a full test suite or executing a long-running command. If one of these commands executes within Claude Code, you could just be sitting around waiting for it to finish, rather than continuing your work.
Send a long-running task to the background
Luckily, Claude Code lets you push any running command into the background, so you can keep working while it executes. While the command is running, tap Ctrl + B, and this will detach the command from the conversation. This will free up your prompt box, but keep the command running.
When a command moves to the background, its output will get written to disk within a specific file. It will also assign the task an ID, so it can be referenced later. This allows Claude Code to retrieve this background task later, and also read the results of its execution.
After sending a job to the background, you can carry out any other work you wish. But if you want to check its status, you can just ask it:
Check on that background taskClaude Code will then read through the output and tell you what's going on. If anything failed, such as tests, it knows about them and can also work on fixing them.
Send a session to the background
Not only can you send a single command to the background, but you can also send the entire conversation to a background thread.
You can type /background, or /bg, to send a conversation to the background. Claude will then exit, and provide you with commands to reattach the session later.
Reattach session to terminal
We can then reattach the terminal to the session by executing:
claude attach [CONVERSATION_ID]
Join the discussion!
Comments
Want to comment on this lesson?
Log in to leave comments.