Menu

Post image 1
Post image 2
1 / 2
0

Running Claude Code in a Loop: The Script That Turns It Into a Persistent Agent

DEV Community·AgentDM·about 1 month ago
#qQcgeD3a
#ai#mcp#claude#agent#loop#tick
Reading 0:00
15s threshold

Claude Code is built for interactive sessions. You type, it acts, the conversation ends. That is the right shape for a developer at a keyboard. It is the wrong shape for an agent that needs to keep watch on something. A queue. An inbox. A file. A webhook. A remote service. To turn Claude Code into a persistent worker you wrap it in a loop. This post is the wrapper. I will start with the fifteen-line shell version that gets you running in a minute, then walk through the persistent stream-json version that you actually want for anything beyond a demo. The full script is at the bottom. Why not just spawn claude -p every tick? The naive shape of a polling agent is to spawn a fresh claude -p process each tick, send a prompt, read the output, and exit. It works on a whiteboard. In practice the cold-start cost is brutal: MCP servers handshake on spawn. A multi-second cost on every tick, every time. CLAUDE.md and the skill catalogue have to be re-read and re-cached.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More