defib my agent: Keep Long Agent Runs Alive When the Session Limit Isn't
I'll save the babysitting for when I have kids...

I spend a lot of my day with coding agents. Copilot and Claude Code are my daily drivers for work and side projects. Building things like this. When you lean on coding agents, you realize how realize how quick you hit session limits. The five hour wall.
The wall
You hand an agent a real task, like working through a backlog of milestones. These are long runs; the good ones stretch across an hour or two of genuine work, and the agent is holding a rich mental model of your codebase the whole time.
Then, two hours in:
- You hit your session limit. The five-hour window lapses, or the daily cap lands, and the agent just... stops. Mid-thought.
- A rate limit trips. "Overloaded." Back off and try again,except "try again" means you, by hand, at your keyboard.
- Credits run dry on a metered plan, right in the middle of the run.
- The terminal dies. SSH drops, laptop lid closes, the machine reboots for an update you didn't schedule.
Every one of these has the same cost: the agent's context evaporates and you're the one who has to reconstruct it. Reloading the entire context is expensive, no clarity on when the todo.md or memory.md were last updated and have to work your way backwards when it comes to the current commit. Starting a new session could cause double the work and have agent flailing around for a while, looking through the open edits trying to reverse engineer what the last session was in the middle of. Alternatively, you re-paste the task, re-explain what it had already figured out, and hope you remembered where it was. The session limit is the sharpest version of this. It's not an error you can fix,it's a clock. And the only tool you have is to sit there with a timer and wait for it to reset, then manually kickstart everything from a cold start.
That's not fun.
defib
defib, as in defibrillator,is a local CLI supervisor. You give it an agent task; it runs the agent, watches for the wall, and when the agent goes down it waits out the limit and resumes the same task using the agent's own native session/resume mechanism. Not a fresh prompt,the same provider session, with its context intact.
defib start --provider claude -p "Refactor the auth module and add tests."
Close your laptop. Lose your terminal. Hit your daily cap. The task picks up where it left off.
The design point that makes this work: the defib command you type is a thin client. A background daemon actually owns and supervises your tasks, which is why they outlive your terminal. On reboot, a small per-user service brings the daemon back and it resumes whatever was in flight.
What it actually handles
- Session limits, rate limits, quota/credit exhaustion, transient provider errors, terminal crashes, machine reboots. The whole family of things that kill long runs.
- Native resume. It continues the same provider session so the agent keeps its context,no re-priming, no lost thread.
- Smart waiting. When the provider tells it when the limit resets, it waits exactly that long. When it doesn't, it backs off with jitter and can probe for credit availability, so it wakes up the moment it's allowed to.
- New or existing sessions. Start fresh, or point
defibat a session you already have going.
Provider-agnostic on purpose
I use more than one agent, so defib was built to. Claude Code is first-class,native resume by session id, structured output, the works. GitHub Copilot CLI runs behind the same abstraction, with quota and rate-limit detection validated against real captured output. There's also a built-in fake provider so the whole thing can be tested deterministically without ever spending a real credit.
The bet underneath is simple: the agent shouldn't have to change, and you shouldn't have to babysit it. The failure modes of these tools are predictable enough to automate around. So automate around them.
Agents building agent tooling
defib is itself a product of coding agents. I "built" it with a neutered Fable 5 for the design (I don't get the hype), and an Opus/Sonnet combo for the implementation. Capturing the error modes was surprisingly difficult given the scarcity of docs!
Where this really pays off: agents on a VPS
Spinning up a VPS just to run your coding agents has become the trendy move, and for good reason, you get a clean, disposable environment the agent can't wreck, it runs whether or not your laptop is awake, and you're not tying up your own machine for hours.
@levelsio put it well after almost a year of coding this way:
I think I've been coding almost solely on my VPS with Claude Code for almost a year now… no need to keep laptop open ever, no battery drain, you can switch to your phone or any other device whenever you want to continue, and it just keeps going all night while you sleep. It just feels like living in the future.
His point about shipping is the one that stuck with me: because the agent is already on the server, a hacky idea can go live in seconds instead of being stuck on your local webserver.
This is really cool though: OpenRouterLabs/spawn launches any agent on any cloud with one command,spawn claude hetzner provisions the box, installs Claude Code, and you're off, across a matrix of ~10 agents and 8 providers (Hetzner, Lightsail, DigitalOcean, GCP, …).
Combine spawn with defib and you get a genuine productivity hack. spawn gives you a remote box that's already decoupled from your terminal; defib runs on it as the supervisor that keeps the long task alive through session limits, rate limits, and credit resets. Provision once, hand the agent a real piece of work, and let it grind through the walls unattended,the VPS keeps the process warm, defib keeps the task warm. You close your laptop entirely and the run just... continues, on someone else's hardware, resuming itself every time a limit lifts. That's the setup I keep coming back to.
Have a go
It's a single Go binary, no runtime, no server, local Unix-socket IPC only. Install, point it at a task, and stop losing two hours of an agent's context to a clock you can't argue with.
defib start --provider claude -p "…your long task…"
defib attach <task> # watch live; Ctrl-C detaches without stopping it
defib list # everything you're supervising
defib install-service --start # survive reboots

GitHub - ya222/defib-my-agent: Revive your agent when session limits refresh
Revive your agent when session limits refresh. Contribute to ya222/defib-my-agent development by creating an account on GitHub.
Reach out, let me know what you think.