Up to 59% offLaunch prices on every plan while spots last.See pricing
KANBANMCP
Sign inStart free

Claude Code Long-Running Tasks: A Setup Guide

10 min read

Key takeaways

  • A long-running Claude Code task needs a harness of plain files: GOAL.md as the system of record, an append-only NOTES.md, and explicit stop conditions in CLAUDE.md.
  • A cron job every 15 minutes that checks the checkpoint timestamp and calls claude --continue turns a dead run into a five-minute gap instead of a lost evening.
  • Write state to disk on a cadence, not on demand, because compaction summarizes older turns and summaries are lossy.
  • A CHECKPOINT.md with Done, In progress, Next, and Gotchas headings lets any agent in any session resume without repeating work.
  • Split a task into claimable cards when you see unverified changes, context bleed, or frequent compaction.

Claude Code can run multi-hour tasks reliably if you give it a harness: a CLAUDE.md with explicit operating rules, scheduled check-ins, a checkpoint file it rewrites as it works, and a compaction-resume procedure so context limits and crashes don't wipe the run. This guide gives you each piece as copy-paste configs, then wires the finished run into a shared board so the next agent picks up exactly where this one stopped.

What counts as a long-running task in Claude Code?

A normal prompt is anything Claude Code finishes inside one session: a refactor, a bugfix, a test suite. A long-running task is a job that will outlive the context window or your attention span — a migration touching 200 files, a multi-stage build pipeline, an agent run you start before bed. Once a job needs checkpoints, scheduled wake-ups, or a handoff note for the next session, it needs harness infrastructure, not a better prompt. Anthropic's engineering guidance on writing effective harnesses for long-running agents frames it the same way: the harness, not the model, decides whether a multi-hour job survives. The rest of this guide builds that harness, and KanbanMCP holds the card so the next agent picks up where this one stopped.

How do you structure a harness so Claude Code can run for hours?

A harness is four files and one loop: a goal file stating what "done" means, a working notes file the agent appends to, a verification command it runs after each step, and stop conditions that end the run cleanly instead of letting it drift. Everything else is decoration you really don't need.

The CLAUDE.md harness block (copy-paste)

Drop this into the project's CLAUDE.md:

## Harness
- Goal: read GOAL.md. Do not restate it, work it.
- After each completed step, append one line to NOTES.md:
  what you did, what you changed, what's unverified.
- Run `npm test` (or VERIFY.sh) after every step. If it fails,
  fix or record the failure in NOTES.md before continuing.
- Stop conditions: tests red twice on the same step, GOAL.md
  acceptance criteria met, or 90 minutes elapsed. On stop,
  write NEXT.md: current state, next concrete step.

The stop conditions matter more than the goal. Without them, an agent either wanders or burns tokens repeating logic that used to work.

Why the system of record and working memory must be separate files

Chat sessions stay disposable, so the harness has to assume every session ends badly: compaction, a crash, you killing it mid-edit. That's why GOAL.md, NOTES.md, and NEXT.md are plain files in the repo, not messages in a chat thread. The goal file is the system of record: it changes rarely and defines done. The notes file is working memory: cheap, append-only, and honest about what's unverified.

When a session dies, the next one reads three small files and recovers the context of the project in seconds, with no idea what the previous agent was "actually doing" beyond what it left behind. Keep each note to one line so the file stays readable after hundreds of steps; if it grows past a screen, the task is really two tasks. This separation is the same split a shared board makes: cards hold state, agents hold nothing. KanbanMCP formalizes it so any agent claims a card, does the work, and leaves a note for the next one (https://kanbanmcp.com/agents), but the file-based version above works today with zero setup.

How do scheduled tasks keep long jobs on track?

A multi-hour run fails quietly. The agent stalls waiting on a prompt, or the terminal session dies and nobody notices for an hour. A scheduler fixes that by checking on the run every few minutes instead of you babysitting it. Three options: cron on Linux/macOS, launchd if you want restart-on-crash behaviour on macOS, or Claude Code's own hooks and headless mode, documented at Anthropic's CLI reference including --continue and --resume flags you can call from a script.

A cron snippet that checks the checkpoint file

Run a cron job every 15 minutes that does one thing: read the checkpoint file your agent writes (see the checkpoint section below). If the file's timestamp is stale past a threshold, the script invokes claude --continue with a short prompt telling it to re-read the checkpoint and carry on. If the process is gone entirely, --resume the session id logged at startup. This turns a dead run into a five-minute gap instead of a lost evening.

What the scheduled prompt should actually say

Keep it to three lines: re-read the checkpoint file, verify the last completed step against the task list, then either continue the next step or write a note on the board explaining where it stopped and why. That note is what the next agent picks up. The same board pattern works across agents, which is what KanbanMCP's Claude integration is built around: one agent claims a card, leaves its state, the next one resumes from that note rather than from a chat transcript you'd have to reconstruct.

How do you handle context compaction mid-task?

Compaction summarizes older turns and drops the raw detail: file paths you mentioned once, exact commands that worked, the note you left three hours ago. What survives is the summary, and summaries are lossy. If the only copy of your working state lives in the conversation, compaction is where it thins out.

Write state to disk before the model needs it

Make the model flush its working memory to a notes file on a cadence, not on demand. Tell it: after every completed subtask, append to notes.md what changed, what commands ran, and what is next. The file is the system of record; the chat session stays disposable. If compaction fires or the run dies, the disk copy is intact. The pattern generalizes across agents too, which is the idea behind Muse Code: each agent claims a card, does the work, and leaves a note for the next one on the same board.

What to put in the resume prompt after compaction

After compaction, the model's summary is thin, so the resume prompt should point at durable state, not re-tell the story. Keep it short: the notes file path, the current card or task ID, the branch name, and the one thing in flight. Something like: "Read notes.md, card 14 is in progress on branch auth-rework, finish the token refresh tests." The model rebuilds its own context from disk instead of trusting a compressed summary. One honest gap: this only works if the model actually wrote the file before compaction hit, so the flush cadence matters more than the resume prompt.

What checkpoints let you resume a failed long-running session?

Write a checkpoint file on a schedule, not on a hunch. Every 20-30 minutes of work, the agent appends to CHECKPOINT.md in the repo root: current task ID, what's done, what's in flight, the exact next step, and any commands that were mid-run. Plain markdown, one file, no structure beyond headings. Any agent in any session can read it, which is the point — the file is the system of record, and the chat session stays disposable.

Checkpoint format that any agent can read

Keep it to four headings: Done, In progress, Next, Gotchas. The last one matters most — it's where the agent leaves notes like "don't rerun migrations, they're applied." That's the note-for-the-next-agent pattern: the card carries the state, the session carries nothing. If the run dies at hour three, the file holds everything a fresh session needs to continue without repeating logic that used to work.

Resuming with claude --resume vs a fresh session

claude --resume restores the prior conversation, which works if the session died cleanly and before auto-compact mangled the early context. After compaction, details get lossy — Anthropic's docs describe how auto-compact summarizes the conversation when context runs low, so a fresh session pointed at CHECKPOINT.md is often more reliable than a resumed one. The honest tradeoff: a fresh session loses the agent's in-flight reasoning, so the checkpoint file has to earn its keep. Write it as if the next reader is a stranger, because after compaction it is.

The same convention is what lets a different agent take over mid-task — the Qwen Code agent page shows how a claimed card plus a checkpoint note hands work across models, not just sessions.

How do you monitor and intervene without breaking the run?

Watching a multi-hour run means reading state from outside the session, not scrolling chat logs. Chat sessions stay disposable; the checkpoint file and the board are the system of record. If your checkpoint includes a one-line status and the current card, a glance tells you whether the agent is moving or stuck.

Reading the checkpoint instead of the chat

Tail the checkpoint file or check the card's status field every few minutes. Timestamps matter more than prose: a checkpoint written 40 minutes ago means the run is stalled, and you can inspect the last diff without touching the session. This is the same habit as checking a board instead of reading every session transcript across hundreds of cli and app chats and sessions.

Intervening by writing to the task, not the terminal

Typing into a running Claude Code session risks derailing it mid-plan. Instead, append a note to the card or checkpoint: the agent reads it at the next checkpoint and adjusts. On KanbanMCP that note lives on the board the agent already claims work from, so steering is one comment away. The honest limit: KanbanMCP only helps if your run actually checkpoints to the board, and it won't show you token burn or live diffs the way watching the terminal does. For those, you still glance at the session itself, you just don't talk to it.

When should you split a task instead of letting it run long?

Split signals: verification gaps and context bleed

Watch for three signals that a multi-hour job is really a chain of claimable cards. First, verification gaps: the agent finished code but never ran it, because the build and the fix need different contexts. Second, context bleed: it starts repeating logic that used to work or editing files unrelated to the task. Third, compaction frequency: if Claude Code is summarising itself every few checkpoints, per Anthropic's Claude Code documentation, the useful context is thinner than the session length suggests.

SignalSplit into
Unverified changesImplement card + verify card
Context bleedOne card per concern
Frequent compactionShorter cards, notes carry state

Handing off with a note the next agent can act on

When you split, each card gets a claimable status and a handoff note: what was done, what was tried, what failed, and the exact next command. The next agent claims the card, reads the note, and starts from the command, not from a chat transcript. Chat sessions stay disposable; the board is the system of record, and the note is the working memory that survives the handoff.

Which tools hold the state while Claude Code runs?

The system of record question has three honest answers. Task Warrior holds tasks well but lives in a CLI, so agent handoffs mean parsing text. backlog.md keeps the board in your repo, which agents read natively and you get a web UI. Linear and Trello hold state outside the repo, which works until an agent needs write access mid-run.

KanbanMCP is our answer: a board the agent claims cards from and leaves notes on, so the next session picks up the working memory without reading a chat log. You steer from the same board while it runs.

Where it falls short: it is not a document store. Specs and design notes still belong in your repo, and if you want them on cards you will end up pasting. It also assumes your agents can call MCP tools, so anything without that stays on Task Warrior. If you already run backlog.md and like it, keep it; the checkpoint file from the earlier sections drops into either setup the same way.

FAQ

Can Claude Code run unattended overnight, and what happens if it crashes?

Yes, if the harness is in place: stop conditions, a checkpoint file, and a scheduler that checks it every 15 minutes. If the process dies, the cron script notices the stale checkpoint timestamp and calls claude --continue or --resume. The run becomes a five-minute gap instead of a lost evening, because state lives in files, not the session.

Does claude --resume restore the full context of a long session?

No. It restores the prior conversation, which works if the session died cleanly before auto-compact fired. Once compaction has summarized older turns, the restored context is lossy: file paths, exact commands, and early notes thin out. A fresh session pointed at CHECKPOINT.md is often more reliable than a resumed one.

How much does it cost to run Claude Code on a multi-hour task?

Cost scales with tokens burned, and a multi-hour run burns plenty, especially if the agent repeats work or wanders without stop conditions. The harness keeps spend down: verification after each step catches failures early, stop conditions end the run cleanly, and checkpoints mean a crash costs one step, not a full restart.

Can I use the same checkpoint setup with Codex or Cursor instead of Claude Code?

Yes. The core pieces are agent-agnostic: a goal file, an append-only notes file, a checkpoint with Done, In progress, Next, and Gotchas headings, and a resume prompt pointing at disk rather than chat. Any agent that can read and write repo files can follow the same convention, and the handoff note pattern works across different models.