← All posts

Guide

How to run Claude Code in the background (and still catch when it needs you)

How to run Claude Code in the background (and still catch when it needs you)

Yes — Claude Code can run in the background. The /background command (alias /bg) detaches a whole session to keep working as a background agent, long commands can run in the background inside a session, and headless mode (claude -p) runs with no terminal at all. What none of them do on their own is tell you the moment the agent needs a decision — and that gap is why background agents quietly stall.

The scenario is always the same: you hand Claude Code a task — refactor a module, chase down a flaky test, wire up an endpoint — and then you want to go do something else. Read a PR, answer Slack, ship a different feature. The phrase people reach for is "run Claude Code in the background," but it hides two very different things: keeping the process alive and keeping yourself in the loop are separate problems. This guide covers both, and the workflow that closes the gap.

Two meanings of "background"

There's truly detached, and there's running but still watchable. They are not the same problem.

Here's the thing most people miss: a coding agent is not a batch job. It pauses. Claude Code stops for permission before a risky command, asks what you meant when your instructions were ambiguous, and waits at the end for the next move. Those pauses are the whole interaction. So when developers say they want to run Claude Code in the background, they almost always want the second meaning — out of the way, but not out of reach. Treat an interactive agent like a headless one and it sits idle on a prompt you never saw.

The native-ish options, and where they leak

The instinct is to reach for the classic Unix toolbox. Each one keeps the process alive; none of them keep you in the loop.

Is there a /background command in Claude Code?

Yes — and it's worth clearing up, because a lot of people search for the literal slash form, claude /background, and aren't sure it exists. It does. /background (alias /bg) detaches the current session so it keeps running as a background agent and hands your terminal back; claude --bg starts a session detached from the outset. While it runs, /tasks lists what's working in the background of the session, and you re-attach later to see where it got. So when someone asks "can Claude Code run in the background?" or "how do I run Claude Code background tasks?", the short answer is: through /background / --bg for a whole detached session, the in-session background tooling for individual long commands, and headless mode (claude -p "…") for a fully scripted, non-interactive run.

Here's the catch, and it's the same one as every option above: detaching the session frees your terminal, but nothing in /background taps you on the shoulder when the agent hits a decision. You still have to remember to check the agent view. "Can Claude work in the background?" — yes; "will it come find me when it's stuck?" — that's the piece you have to add.

The common failure is identical across all of them: the agent keeps running, but the signal — it needs a decision, it finished — never finds you. You traded babysitting for blindness. That trade is the subject of stop babysitting your AI coding agent.

The workflow that actually works

If what you want is "running but still notified," three pieces have to be true at once:

That last piece is the one tmux and nohup structurally can't give you, and it's where Claude Code's design helps. Claude Code exposes lifecycle hooks — roughly Notification (it wants attention), Stop (it finished), and PreToolUse (about to run a tool, can pause for allow/deny). Those are the exact moments worth a sound or a flash; Claude Code hooks, explained walks through how each one fires. Wire them to a notifier and "background" stops meaning "blind." The same plumbing is what lets you push past one task at a time and run multiple AI agents at once without losing track of which one is waiting on you.

Frequently asked questions

Can Claude Code run in the background?

Yes. Claude Code can detach a whole session with the /background command (alias /bg) or the --bg flag so it keeps working as a background agent while your terminal is free, run individual long commands in the background inside a session, or run fully non-interactively in headless mode with claude -p "your task". The gap none of these close on their own is notifying you the moment the agent needs a decision.

Is there a /background command in Claude Code?

Yes. /background (alias /bg) is a real Claude Code slash command: it detaches the current session to keep running as a background agent and hands your terminal back. claude --bg starts a session detached from the outset, and /tasks lists what is running in the background of the current session.

How do I run Claude Code background tasks or background agents?

Use /background or claude --bg to turn a session into a detached background agent, check on it from the agent view and re-attach when you want, and use /tasks to see in-session background work. For a fully scripted run with no prompts, use headless mode (claude -p). To be pinged on approvals and completion across the whole run, wire Claude Code hooks to a notifier — that is the part the background commands do not do for you.

Why does running Claude Code in the background still leave it stalled?

Detaching with /background, tmux, or nohup keeps the process alive but does not reach you when the agent pauses for a permission prompt or a clarifying question. The session sits waiting on an answer you never saw. The fix is an explicit notification on those events — and, when the ping lands while you're away, a way to answer your agent from your phone — not just keeping the process running.

Where Backgrind fits

This is the shape Backgrind is built around. A background daemon keeps your agents alive across UI restarts and crashes, and notifications fire even while the window is hidden — a chime plus an accent ring on the tab that needs you, driven by those same Claude Code hooks. You run your real claude CLI (your login, your history), put it out of the way, and answer only when it actually pings — and when the ping catches you away from the keyboard, you can drive your agent from your phone instead of running back to the desk. If you want the deeper mechanics of pinning it over your other windows, see an always-on-top terminal over any app, or try the live demo to feel the notification loop.