long-running-tasks
Skill1 starsChanged 5 months agoMITView on GitHub
Decision tree for handling long-running operations in Claude Code — when to use background subagents, Monitor tool, explicit timeouts, or refactor the task. Auto-fires when a task duration estimate exceeds typical bounds.
In this repository42 other files it gives its agents.
- codex/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- new-hookSkill
- new-ruleSkill
- new-skillSkill
- publishSkill
- agent-config-adapterSkill
- agent-update-watcherSkill
- autopilotSkill
- autoresearch-toolfinderSkill
- claude-desktop-sessionsSkill
- code-verifierSkill
- doc-writingSkill
- end-of-turn-markerSkill
- figma-authoring-constraintsSkill
- figma-design-fetchSkill
- autopilotSkill
- autoresearch-toolfinderSkill
- code-verifierSkill
- linux-freeze-triageSkill
- preview-templateSkill
- privacy-redactSkill
- research-criticSkill
- agent-harness-generalSkill
- system-cleanupSkill
- verify-templateSkill
- verify-visualSkill
- init-codex-configSkill
- long-running-tasksSkill
- memory-flywheelSkill
- preview-templateSkill
- privacy-redactSkill
- prompt-librarySkill
- research-criticSkill
- system-cleanupSkill
- task-orchestratorSkill
- feature-audit-templateSkill
- workflow-fix-templateSkill
- task-relationship-analysisSkill
- tui-installerSkill
- verify-templateSkill
- verify-visualSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 75
If a task realistically takes > 1 hour:
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
/long-running-tasks
Choose the right mechanism when a task will take more than a few minutes.
Decision tree
Task duration estimate?
├─ < 30 seconds → run synchronous (default)
├─ 30s – 2 min → run synchronous, watch for timeout
├─ 2 – 10 min → Bash with `run_in_background: true`, then Monitor for completion
├─ 10 min – 1h → background subagent (`Task` with `run_in_background: true`); main agent continues with other work
└─ > 1 hour → consider refactoring; or use a CronCreate for scheduled recurrence; consider whether the model session itself will reach context limits before completionTool reference
Bash with run_in_background: true
For shell commands > 2 min:
Bash(command="<long-running-cmd>", run_in_background=True, timeout=600000)Returns control immediately. Use Monitor (or BashOutput) to check status.
Monitor tool
Watches a background process for events. Costs no tokens while waiting (event-driven, not polled):
Monitor(...)Wakes the agent only when an event of interest occurs. Use for "wait for build to finish" / "watch a log file for an error pattern".
Background subagent (Task with run_in_background: true)
For tasks needing reasoning + tool use, not just shell:
Task(
description="<one-line>",
subagent_type="general-purpose",
prompt="<self-contained prompt — the agent has no context from this conversation>",
run_in_background=True,
)Subagent runs independently. You receive a notification on completion. Async subagents can continue running even after the main agent finishes its turn (very recent feature; verify availability per CC version).
Explicit timeout in subagent prompts
For any subagent that might hang (e.g., one that runs tests), add to the prompt:
If this hasn't completed in 10 minutes, interrupt and report the current status.
Without an explicit timeout instruction, a hung process leaves the agent waiting indefinitely (GitHub issue #4744 in anthropics/claude-code).
Anti-patterns
- ❌ Looping
sleep 60; check_status; sleep 60; ...— burns context cache. UseMonitorinstead. - ❌ Foreground bash with
timeout: 600000(10 min) — blocks the entire session. Use background. - ❌ Sequential 4 × 5min tasks — try to parallelize via 4 background subagents.
- ❌ Polling a long-running task with
BashOutputevery 30s —Monitordoes the same thing without burning tokens.
When the task is fundamentally too long
If a task realistically takes > 1 hour:
- Split it — break into checkpointable sub-tasks that can survive a session restart
- Use a cron — schedule via
CronCreatefor periodic execution - Document the manual step — tell the user "this needs to run for X hours; here's the command, run it yourself and let me know when done"
Companion
Pair with output-brevity rule (no polling-loop output) and tool-proactivity rule (announce before firing a long-running task so the user can interrupt).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

