# How to run Claude Code overnight

> Run Claude Code overnight: keep the computer awake, keep the session alive when the terminal closes, and plan for limits and permission prompts.

Source: https://shuriken.sh/guides/run-claude-code-overnight

Run Claude Code overnight: keep the computer awake, keep the session alive when the terminal closes, and plan for limits and permission prompts.

By Shuriken Updated 27 October 2026 5 min read

**Contents**

To run Claude Code overnight, you need three things: a computer that stays awake, a session that survives closing the terminal or app, and a plan for the moment you hit a usage limit or a permission prompt at 2 am. Get those right and you wake up to finished work instead of a question.

We learned each of these the annoying way. Here's the list, in the order things tend to break.

## 1. Keep the computer awake #

If the computer sleeps, the agent stops. On a desktop that's a power setting. On a MacBook, the lid is the problem: closing it sleeps the Mac even with caffeinate running.

The options, from free to one switch, are in [Keep Claude Code running with the MacBook lid closed](https://shuriken.sh/guides/keep-claude-code-running-lid-closed). Short version: caffeinate -i -s while the lid is open and plugged in; sudo pmset -a disablesleep 1 for lid-closed (and 0 in the morning, or your Mac never sleeps again); or Shuriken's Cocaine mode, one switch per computer. And a computer signed in to Shuriken starts on Keep awake: Always, so with the lid open it doesn't idle to sleep in the first place.

Plug it in. A whole night of agents and test runs on battery is optimistic.

## 2. Keep the session alive #

Claude Code lives as long as the process that runs it. Anthropic's Remote Control docs say it plainly: "If you close the terminal, quit the Desktop app or VS Code that runs the session on your machine, or otherwise stop the claude process, the session goes offline" ([Claude Code docs](https://code.claude.com/docs/en/remote-control)).

So the session needs a home that outlives your window.

### The free way: tmux #

Start a tmux session, run Claude Code inside it, and detach. tmux and "any programs running inside it" keep "running in the background" ([tmux wiki](https://github.com/tmux/tmux/wiki/Getting-Started)).

bash
tmux new -s night
claude # give it the task, then press Ctrl-b d to detach
tmux attach -t night # in the morning

This is also what Anthropic recommends on a remote machine: start claude "inside tmux or screen to keep the session running after you disconnect from SSH".

### The app way: a background service #

Shuriken runs your agents in a background service, not in the window. Close the app and Claude Code, Codex and the rest keep working; the service starts with your computer and restarts by itself if it stops. You turn it on under Settings › Devices. More on the [background service page](https://shuriken.sh/features/background-service).

Even without it, closing Shuriken's last window never stops running work.

## 3. Plan for permission prompts #

This is the one that catches everyone. Claude Code "still asks for permissions as usual, so the task can stop on a prompt while you're away" ([Claude Code docs](https://code.claude.com/docs/en/interactive-mode)). You come back to eight hours of nothing and one question: "Can I run npm install?"

Your options, from Anthropic's [permission modes](https://code.claude.com/docs/en/permission-modes):

- Pre-approve what the task needs. Run the task for a few minutes while you watch, and answer "Yes, and don't ask again" for the commands it will repeat: the test runner, the linter, the build.
- acceptEdits lets it edit files and run common filesystem commands without asking.
- auto runs "everything, with background safety checks", and Anthropic lists it for "long tasks, reducing prompt fatigue".
- bypassPermissions runs everything, and Anthropic's advice is to "only use this mode in isolated environments like containers, VMs, or dev containers without internet access". Not on your laptop with your SSH keys on it.

Whatever you pick, give it a branch or a worktree of its own, so a bad night is one git branch -D away from never having happened.

## 4. Plan for usage limits #

A long night can run through a 5-hour window, or two. What happens then depends on how you set it up.

Claude Code can wait for you. On recent versions, in an interactive session signed in with a subscription, Claude Code can "wait in the open session and continue the interrupted task shortly after the reset" ([Claude Code docs](https://code.claude.com/docs/en/errors)). It's on by default, and you'll see Continuing automatically at 3:45pm ([Claude Code docs](https://code.claude.com/docs/en/interactive-mode)). Keep the session open for this to work. If it hits the limit again, it re-arms at most twice in a row, then stops.

Know which limit you'll hit. The 5-hour window comes back in hours. The weekly limit can take days, and a fresh window won't help. [Claude's 5-hour limit](https://shuriken.sh/guides/claude-5-hour-limit-explained) and [Claude's weekly limit](https://shuriken.sh/guides/claude-weekly-limit-explained) explain both.

Queue the work, don't babysit it. In Shuriken you type the next tasks into the queue before bed. Each message waits its turn and goes when the agent is free. You can reorder, edit or remove rows, and set one to repeat.

Move to another account you own. If you pay for more than one plan, Shuriken moves your chats to the account with the most room when one reaches your switch point, 99% by default. A Claude Code chat moves on its next request, subagents included, and a Switched to … card tells you in the morning. Session limits start idle accounts' 5-hour windows early with one tiny background request each, so their limits come back sooner too. See [source switching](https://shuriken.sh/features/source-switching).

Use only accounts you own and are entitled to use. Providers' terms may not allow sharing a subscription sign-in.

API keys as a last resort, if you want them. The setting is off by default. Turn on Switch to API keys and Shuriken hands chats to your API keys only once every subscription is out, with a spend cap per fallback run ($25 unless you change it, counted across all your keys for that provider), so a busy night can't become a surprise bill.

Shuriken's Cocaine mode keeps the computers you pick awake while your agents run.

[Download](https://shuriken.sh/download)

## 5. The morning #

What you want at 8 am is a summary, not an archaeology dig.

- Notifications. Shuriken sends a notification on your computer when a chat needs you or finishes.
- The Activity digest. Come back and you get a short "While you were away" of what happened and which chats need you. The [Activity panel](https://shuriken.sh/features/activity) shows subagents, workflows and background commands, with what's still running.
- Changes, then Finish. Read the diff in the chat's branch. When you're happy, Finish runs your checks, then rebases and squash-merges, or opens a pull request with auto-merge.

## Every night? #

If "overnight" is every night, start it from a scheduler instead of by hand: cron or CI with Claude Code's [headless mode](https://shuriken.sh/guides/claude-code-headless-mode).

If you'd rather not leave a laptop on at all, run the agents on a computer that's always on ([running Claude Code on an always-on machine](https://shuriken.sh/guides/claude-code-on-an-always-on-machine)).

## The checklist #

Before you go to bed:

- Power: plugged in, and sleep handled (lid-closed or not).
- Session: running in tmux or a background service, not a terminal you'll close.
- Branch: the agent works on its own branch or worktree.
- Permissions: the commands it needs are pre-approved, or you picked a mode that asks less. No bypass outside a sandbox.
- Limits: you know which account it's on and how much is left this week. Auto-continue is on, or a second account you own is ready.
- Queue: the next tasks are lined up, so a finished task isn't an idle night.
- Morning: notifications on, so you know what needs you first.

That's seven checks for one night. Shuriken was built so most of them stop being checks: Cocaine mode, the background service, the queue and switching are each one setting. [Download Shuriken](https://shuriken.sh/download) and go to bed.

Try the free tool: [Claude limit reset tracker](https://shuriken.sh/tools/limit-resets/claude)

Share

[X](https://x.com/intent/post?url=https%3A%2F%2Fshuriken.sh%2Fguides%2Frun-claude-code-overnight&text=How%20to%20run%20Claude%20Code%20overnight)[LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fshuriken.sh%2Fguides%2Frun-claude-code-overnight)[Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fshuriken.sh%2Fguides%2Frun-claude-code-overnight&t=How%20to%20run%20Claude%20Code%20overnight)[Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fshuriken.sh%2Fguides%2Frun-claude-code-overnight&title=How%20to%20run%20Claude%20Code%20overnight)[E-mail](mailto:?subject=How%20to%20run%20Claude%20Code%20overnight&body=https%3A%2F%2Fshuriken.sh%2Fguides%2Frun-claude-code-overnight)

## Sources

- [Claude Code docs: Interactive mode (wait for a usage limit to reset)](https://code.claude.com/docs/en/interactive-mode) (accessed 22 October 2026)
- [Claude Code docs: Permission modes](https://code.claude.com/docs/en/permission-modes) (accessed 22 October 2026)
- [Claude Code docs: Remote Control (limitations)](https://code.claude.com/docs/en/remote-control) (accessed 22 October 2026)
- [Claude Code docs: Error reference (usage limits)](https://code.claude.com/docs/en/errors) (accessed 22 October 2026)
- [tmux wiki: Getting Started](https://github.com/tmux/tmux/wiki/Getting-Started) (accessed 22 October 2026)

## Frequently asked questions

**Does Claude Code keep running after I close the terminal?**

No. Claude Code runs as a process of that terminal, so closing it stops the session. Run it inside tmux or screen, or use an app whose agents run in a background service, like Shuriken's.

**What happens to permission prompts overnight?**

They wait. Claude Code keeps asking for permissions as usual, so a task can sit on a prompt until morning. Pre-approve the commands the task needs, or use a mode such as acceptEdits or auto that asks less often.

**Is it safe to leave Claude Code running unattended?**

It can be, if you limit what it may do. Work on a branch or worktree, pre-approve only what the task needs, keep secrets out of reach, and never use bypassPermissions outside an isolated container or VM.

**What if I hit the usage limit at 2 am?**

Recent Claude Code versions can wait for the reset and continue the task by themselves, if the session is still open. Shuriken can also move the chat to another account you own when one runs out.

Cocaine mode

Close the lid. Your agents keep working.

Pick which of your computers stay awake while agents work. On a Mac that holds with the lid closed, and on Windows and Linux where the laptop allows it.

[Download](https://shuriken.sh/download)

[Other platforms](https://shuriken.sh/download#main)

## Keep reading

- [Keep awake only while agents work: Update 27 Oct 2026 3 min read Keep your computer awake while an agent, the queue or a workflow runs, then let it sleep. Shuriken's two settings: While working and Always.](https://shuriken.sh/blog/keep-awake-while-working)
- [Yes, it's called Cocaine mode: Story 27 Oct 2026 3 min read Cocaine mode keeps your Mac awake with the lid closed, so your coding agents keep working. Why it has that name, how it works, and the honest warnings.](https://shuriken.sh/blog/cocaine-mode-yes-really)
- [Shuriken on Windows 10 and 11: Update 27 Oct 2026 3 min read Run Claude Code, Codex and 65 more coding agents in parallel on Windows 10 and 11. Installer or .zip, x64, with signed updates.](https://shuriken.sh/blog/shuriken-on-windows)
- [Keep-awake apps for coding agents compared: Comparison 27 Oct 2026 7 min read Keep-awake apps for coding agents: caffeinate and KeepingYouAwake can't hold a closed MacBook lid; pmset, Amphetamine and Cocaine mode can.](https://shuriken.sh/compare/amphetamine-alternatives-for-coding-agents)

## Free tools

- [Claude limit reset tracker](https://shuriken.sh/tools/limit-resets/claude)
- [Codex limit reset tracker](https://shuriken.sh/tools/limit-resets/codex)
