ProjectsCoding agentsReliability

CodeMedic

Self-healing coding agents for unattended LLM pipelines

When a scheduled job breaks and nobody is watching, CodeMedic reads the failure from its logs, sends a headless coding agent into the project to find the cause and fix it, and keeps the fix only if the project's own tests still pass.

publish.log5 min · $0.74

#102 medium publish error: Medium did not keep the whole story: {"status": "incomplete", …}

  1. Tests beforeThe project's suite passes, so a regression would be the session's.
  2. CauseThe blog's editor rewrote "Qwen3.5-4B" with an en dash, and the title check only folded curly quotes.
  3. Fixnorm() now folds en and em dashes in both browser scripts; a new test fails on the old code.
  4. Tests after67 passed, so CodeMedic pushed the commit.
  5. Carried onRe-ran the stuck publish step: the post went live.
  6. Told the authorOne Slack message: cause, fix, and git revert 9edcc2b to undo.

Agents that run on a schedule fail in ways their authors can't watch for: a site changes its markup, an API changes its shape, a network drop leaves work half done. Usually the fix is small, and the cost is the hours before anyone notices. CodeMedic is an on-call engineer for those agents. It watches their logs, turns new failures into incidents, and starts a headless Claude Code session inside the failing project with the incident, the project's state and a strict set of rules.

The session decides whether the failure is transient, a bug, or something only the author can fix. For a bug, it fixes the root cause, adds a test, commits, and re-runs the step that was stuck. CodeMedic then checks the work itself: it re-runs the tests, reverts the session's commits if they broke anything, and otherwise pushes them and sends the author one message with a one-line undo.

32

healing sessions in 15 days on four unattended agents: a publishing pipeline, an open-source PR agent, an awesome-list maintainer and a daily digest.

8 to 23 November 2026
5 fixes

committed and kept. CodeMedic re-ran the tests after each one, and none had to be reverted.

Each fix's tests run by CodeMedic
24

sessions found a transient cause, mostly network outages, and changed no code.

Outcome "transient"
$0.46

median cost per session, with a median run of 71 seconds. Every session has an $8 budget and a 45-minute limit.

Claude Opus, high effort

How CodeMedic works

CodeMedic runs every ten minutes and does at most one session per run. Everything it needs from a project is in a few lines of configuration: its repository, its logs, its test command, its lock file, the files a session must never touch, and a note on what the project does.

  1. Step 01

    Watch

    Read only what each log gained since the last look. Failure lines and Python tracebacks become incidents, keyed by a signature with ids, numbers, URLs and paths removed, so one bug on many items is one incident. Errors that usually clear up on their own wait until they repeat.

  2. Step 02

    Heal

    Take the project's tick lock so its own runs wait, run its tests, and start claude -p in the project with a guard hook and a budget. The session classifies the failure, fixes the root cause with the smallest change, adds a test, commits explicit paths and re-runs the stuck step.

  3. Step 03

    Verify

    Re-run the tests. If the session's commits broke tests that passed before, revert them; otherwise push. Send one Slack message with the cause, the fix and the git revert line, and keep the prompt, transcript and report in the run directory.

Guard rails

A session runs with nobody watching, so its limits are enforced in code, not only asked for. A Claude Code PreToolUse hook checks every tool call before it runs and denies the ones below, whatever the session was told by the logs, a web page or its own reasoning.

Table 1.What the guard blocks in a healing session, and why. The instructions add the rules that code can't check: public actions only by re-running the project's own step after checking it did not already go out, and never changing caps, schedules or who gets contacted.
BlockedWhy
git push, reset, checkout, stash, rebase, add -A, --amendCodeMedic pushes only after its own test run, and the author's uncommitted work stays untouched.
Edits outside the project, to protected files, or to files with uncommitted changesConfiguration, content and work in progress are the author's; the session describes the change they need instead.
.env, Claude logins, SSH and cloud credentials, the keychainSecrets are never read, let alone changed.
gh, non-GET HTTP requests, MCP toolsNothing public happens outside the project's own commands.
Installing packages, sudo, launchctl, system settingsA fix that needs a new dependency or a system change goes to the author.
Deleting files outside the run directory, deleting database rowsData, logs and past runs are evidence; scratch files live in the run directory.

Limits bound the cost of a bad day: two sessions per error per day, after which the error is muted for a day and the author is alerted, three sessions per project and four in all. A session that loses its connection, or hits the usage limit, is deferred and tried again rather than counted as a failure.

Two weeks in use

From 8 to 23 November 2026, CodeMedic watched four of the author's unattended agents. The five fixes were the kind of change the outside world forces on a scraper or a publisher: a reply form that moved behind a collapsed thread, a comment lookup that dropped underscores and asterisks from text like IQ2_XXS, an editor that changed a hyphen to a dash, and a GitHub call whose timeout crashed a run during a network drop.

  • 5 fixed: a code change, tested and kept
  • 1 got stuck work through without a code change
  • 24 transient: no code changed
  • 1 needed the author: the fix was in a file they were editing
  • 1 gave up: the API went offline mid-session
Figure 1.Outcomes of the 32 sessions. Not counted: 44 launches deferred before any work, 42 because the machine was offline and 2 at the usage limit. The one session that gave up predates the rule that defers offline sessions instead.

Limits

The tests are the gate. CodeMedic keeps a fix when the project's tests pass, so a project with weak tests gets a weak check. Sessions are told to add a test with every fix, which strengthens the gate over time but does not replace review: every fix arrives with its undo line for that reason.

The guard is defense in depth, not a sandbox. It matches commands and paths with rules, and a determined process could get around them. Run CodeMedic only on projects you own, under an account with no more access than those projects need.

One machine, one author. These numbers come from one author's four projects over two weeks, not from a benchmark. CodeMedic is built for a person's unattended automations, with a launchd job on macOS and cron elsewhere, not to replace a team's on-call rotation.

Citation

Please cite this work as

@misc{pakdamansavoji2026codemedic,
  title        = {CodeMedic: Self-Healing Coding Agents for Unattended LLM Pipelines},
  author       = {Pakdamansavoji, Sajjad},
  year         = {2026},
  howpublished = {\url{https://github.com/forall-labs/CodeMedic}}
}

Running it

Clone the GitHub repository, copy config.example.toml to config.toml and describe your projects, then try python3 -m codemedic tick --dry-run. It needs Python 3.11+, git and the Claude Code CLI. The test suite runs heal end to end against a fake agent and a local git remote.

Built on

Claude Code in headless mode, with its hooks doing the guarding.