Skip to content
TutorialUpdated 2026-06-04

How to Keep Codex, Claude Code, and OpenClaw Running on Your Computer

A practical guide to keeping coding agents and AI assistants running for hours by managing sleep, network, permissions, logs, and recovery.

Agentic tools such as Codex, Claude Code, and OpenClaw often need time: reading a repository, editing files, running tests, waiting for builds, or processing messages. Keeping them running overnight is not just a power setting. You need four things: the computer must stay awake, the network must stay connected, permissions must not block progress, and the task must be recoverable.

Keep-awake is not unlimited trust

For unattended agent work, keep the machine awake but still limit the workspace, preserve logs, and avoid broad dangerous permissions unless you are in an isolated environment.

Choose the right running mode

ToolGood long-running modeKey point
CodexLocal threads, codex exec, or Codex CloudLocal work depends on your computer staying awake; cloud work does not
Claude CodeInteractive sessions or claude -p print modeUse --continue or --resume for recovery
OpenClawGateway / daemon / serviceRun the gateway as a service, then keep the host awake

Step 1: Keep the system awake

For one-off terminal tasks:

caffeinate -i codex "run the test suite and fix failures"
caffeinate -i claude "review this repo"

For a process that is already running:

pgrep -fl codex
caffeinate -i -w <pid>

For a daily locked-screen workflow, use Lidless and enable Only when plugged in on laptops.

Step 2: Avoid permission stalls

Long agent tasks often stop because the agent is waiting for approval, not because the computer slept.

Codex separates sandboxing from approval policy. A balanced local mode is:

codex --sandbox workspace-write --ask-for-approval on-request

For scripted runs, use codex exec:

codex exec --sandbox workspace-write "run tests and fix the smallest failing issue"

Claude Code supports non-interactive print mode:

claude -p "summarize failing tests and suggest a fix"

It also supports continuing or resuming sessions:

claude --continue
claude --resume <session-id> "continue the previous task"

Be careful with bypass flags

Options such as --dangerously-skip-permissions or full-access sandbox modes are only appropriate in trusted, isolated environments. Do not trade basic boundaries for convenience.

Step 3: Make the task recoverable

Do not leave the whole plan inside chat history. Add a small task state file to the repository:

AGENT-TASK.md

Include:

  • The current goal.
  • Decisions already made.
  • Commands or tests currently running.
  • Files the agent should not touch.
  • The definition of done.

This makes it much easier to recover after a terminal disconnect, context compaction, network failure, or manual restart.

Step 4: Run OpenClaw as a service

OpenClaw's core is its Gateway, which connects message channels to AI agents. For long-running use, prefer a daemon or service instead of a manually opened terminal:

npm install -g openclaw@latest
openclaw onboard --install-daemon
openclaw dashboard

Then check status and logs:

openclaw status
openclaw logs

Running OpenClaw as a service does not automatically prevent the operating system from sleeping. Configure the host machine as well.

Unattended run checklist

  • Keep the machine plugged in.
  • Let the display turn off, but prevent system sleep.
  • Lock the screen before leaving.
  • Write logs or a final report.
  • Keep work limited to a Git repository or known directory.
  • Confirm API keys, MCP credentials, and Git credentials will not leak into logs.
  • Commit, checkpoint, or save patches regularly.

Recovery guide

SymptomCheck
The computer sleptmacOS: pmset -g assertions; Windows: powercfg /requests
The agent stoppedLook for approval prompts, test input, or network retries
The task was killedCheck shell history, logs, and service logs
Context was lostUse codex resume, codex exec resume, claude --continue, or claude --resume
Network droppedCheck Wi-Fi, power saving, VPN, and proxy settings

References