🤖 AI Summary
Anthropic’s “external looping” pattern for Claude Code provides a lightweight orchestration layer to apply one task to N inputs while avoiding session bloat, lost progress, and high cost from long-lived AI contexts. Instead of running many edits inside a single Claude session, a shell loop (loop.sh) launches Claude fresh for each iteration, pulls a task from a persistent loop-state/tasks.json queue (pending/current/completed/failed), has Claude perform the edit, then writes the updated state. The loop creates markers (.done, .lock) and stores prompts and combined state under loop-state/ so you can audit, resume, or reset runs (reset.sh, demo.sh). A permissions.json file declares filesystem access (Edit/Write) so Claude can safely modify repo files.
Technically this pattern preserves a clean per-task context, lowers inference cost, and makes runs resumable and auditable. Key files: task.md (task instructions), permissions.json, loop.sh, loop-state/*.json and .prompt-combined.md. The included demo automates renaming .txt → .md across demo directories; typical use cases include bulk file migrations, per-module documentation generation, header/import updates, and directory-by-directory refactors. The design also exposes natural ways to scale—split work into separate task queues or state dirs for parallel runners—while the .lock prevents accidental concurrent runs against the same state.
Loading comments...
login to comment
loading comments...
no comments yet