Blog · Codex

Codex long-running tasks: how to run Codex overnight or in the background

Codex can work on one task for hours, and it can keep going while you sleep, if four things are taken care of: a goal it can check itself, a computer that stays awake (or a task in the cloud), approvals that don't wait for you, and enough room in your plan. This guide covers the ways to run long Codex tasks, from Goal mode to cloud tasks and codex exec resume, what each can't do, and how to give Codex a standing night shift.

Ways to keep Codex running

Some keep one chat going, so Codex keeps its context; others start fresh each time.

OptionComputer can sleepSame chatWhere it stopsBest for
Goal mode (/goal)No, for local workYesWhen the goal is met, or it needs a decisionOne task with a clear finish line
Codex Cloud taskYesYesWhen the task is done; you review and open a pull requestHanding off a task before bed
Scheduled task in a chatNo, for local files: computer on, app runningYesRuns on its schedule: minutes, daily or weeklyChecking in on the same work at intervals
codex exec from cronNoYes, with codex exec resumeYour cron rhythm; you wire it up yourselfScripts and CI
Crewmark heartbeatNoYesWorking hours you set, even past midnightA standing job taken from a board, issue by issue

How to run Codex overnight

  1. Give it a goal it can check

    In the desktop app, the CLI or the IDE extension, /goal starts Goal mode: the goal text is both the first prompt and the finish line. If you aren't sure what done looks like, /plan asks you questions and turns the outcome into a goal with measurable criteria. Include a check, like a test suite passing.

    # Interactive: plan the outcome, then hand Codex a goal it checks itself
    /plan
    /goal all tests in test/auth pass and the lint step is clean
    
    # Headless, from a script or cron: let it edit files in the workspace
    codex exec --sandbox workspace-write "Work through TODO.md in order"
    
    # Next morning, or on the next cron run: continue the same session
    codex exec resume --last "Continue with the next unchecked item in TODO.md"
  2. Keep the computer awake, or send it to the cloud

    For local work on a Mac, turn on “Prevent sleep while running” in the desktop app. A Codex Cloud task runs in its own workspace and keeps working while your computer is asleep; start one by choosing Work in > Cloud and an environment.

  3. Set approvals so it doesn't stop at 2am

    A goal keeps the same sandbox and approval policy, and pauses when it needs a decision. Let it edit the workspace with --sandbox workspace-write, or use “Approve for me” so a reviewer handles routine requests. --full-auto is no longer supported, and danger-full-access belongs only in an isolated runner or container.

  4. Plan for usage limits

    Codex shares your ChatGPT plan's allowance: a rolling 5-hour window plus weekly limits, and cloud tasks draw from the same pool. ChatGPT Pro currently has no 5-hour limit; weekly limits may apply. Credits or an API key let local work keep going. See Claude Code vs Codex for the numbers.

  5. Check in from your phone

    In the ChatGPT app you can follow a task, approve commands and review diffs, for cloud tasks and for a Mac or Windows PC you've connected under Settings > Connections. The connected computer has to stay awake and online. See Codex remote control.

Source: OpenAI's Codex docs on long-running work

What stops a long Codex task

  • A decision only you can make. Goal mode pauses instead of widening its own access, so check approvals before you leave.
  • Sleep or a lost connection on local work. OpenAI suggests pausing the goal before you expect to lose connectivity and resuming it later.
  • The usage limit, until the window resets or you add credits.
  • Two chats editing the same files. Give parallel chats their own git worktrees.
  • Running out of work. Once the goal is met it stops, which is what you want; for a list of tasks, keep them in a file it works through.
With Crewmark

Give Codex a night shift

A long task ends; a job doesn't. Crewmark turns a Codex conversation into an AI employee with working hours and a heartbeat, so it keeps taking the next issue from a board without you queuing it.

  1. Set the working hours

    Working hours can run past midnight, so a night shift such as 22:00 to 07:00 works, weekdays only or every day. Outside its hours the employee sleeps and doesn't touch your plan.

  2. Pick the heartbeat

    Every 15, 30, 60, 120 or 240 minutes during its shift, the crewmark CLI queues a message into the same Codex conversation with codex queue --resume and starts it, so the employee picks up its next issue. Your computer has to stay on.

  3. Read the board in the morning

    Each issue has its comments and activity log, and anything that needs you arrives as a message the employee waits on. See how to make Codex proactive and what an AI employee is.

FAQ

Can Codex run overnight?

Yes. Give it a goal with /goal, keep the Mac awake with “Prevent sleep while running” (or use a Codex Cloud task, which keeps working while your computer sleeps), set approvals so it doesn't wait on you, and review the result in the morning.

How do I run Codex in the background?

Run codex exec without the interactive interface, from a script, cron or CI, and continue the same session later with codex exec resume --last. Or start a Codex Cloud task from the web or desktop app and close the window.

What is Goal mode in Codex?

Goal mode, started with /goal, keeps Codex working toward a goal you write; the goal text is both the first prompt and the completion criteria. You can pause, resume, edit or clear it from the progress row in the desktop app.

Does Codex keep working when my computer is asleep?

Cloud tasks do. Local work needs the computer awake, which the desktop app's “Prevent sleep while running” setting handles on a Mac; a connected computer you control from your phone also has to stay awake and online.

Will a long Codex run hit my usage limit?

It can. Codex uses your ChatGPT plan's 5-hour window and weekly limits, and cloud tasks draw from the same allowance. Spread work across windows with a schedule or a heartbeat rather than one long burst.

Is it safe to run Codex unattended?

Keep --sandbox workspace-write or “Approve for me” on your own machine, use danger-full-access only in an isolated runner or container, and work in a repository where changes go through review.

Checked against OpenAI's Codex docs (long-running work, Codex Cloud, non-interactive mode, mobile, scheduled tasks) on November 8, 2026.

Give Codex a night shift.

Crewmark turns Claude Code and Codex sessions into AI employees with roles, goals, working hours and a heartbeat.