Will it run?
Agents

Hermes agent rewrites itself: million Python lines cleaned in 19 hours by 1,393 sub-agents

By Nadia Ksiazek Clawpit staff
Hermes agent rewrites itself: million Python lines cleaned in 19 hours by 1,393 sub-agents

On September 2, Teknium asked the Hermes agent — the open-source coding agent the team develops — to deep-clean a repository that had accumulated more than a million lines of non-test Python. The file gateway/run.py alone weighed in at 34,847 lines. Nineteen hours and 1,393 sub-agents later (peaking at 218 running in parallel), the codebase had shrunk 34.4%. The PR merged on September 4 after a restart, a continuation session, and two rounds of community review. Token spend came to roughly $19,300 for the main run, about $25 thousand including continuations, not counting human review time.

The instruction, issued through the /goal command that gives the agent a persistent objective and resumes it when it stalls, was explicit and demanding: drastic line-count reduction, at least 30% overall; break up "god files"; consolidate helpers and methods for reuse; eliminate nested if-else chains; improve readability and interpretability; cut bloat without waiting for human sign-off. The goal was met in full. The code ended up smaller and clearer without breaking functionality.

The numbers explain why this had never been done before. The team estimated a manual effort on the same scope would cost $150 thousand to $1.8 million (roughly 550 thousand to 6.7 million shekels) for a small team over two months to two years — a range that reflects genuine uncertainty about refactoring complexity. Against that, the model cost was a sliver: under 2% of the low-end manual estimate. That gap is why the cleanup sat on the backlog for months while features and urgent bugs took priority; suddenly it became economically viable without pulling engineers off other work.

What made the run possible isn't just a large model but a skills system Hermes builds for itself during day-to-day work. When an engineer corrects a mistake or the agent discovers a reliable path, the lesson is saved as a readable markdown document with helper files and scripts — a skill that loads automatically on future tasks. The hermes-agent-dev skill, for instance, includes an instruction to run a failing test against origin/main HEAD in a clean environment to verify whether the failure predated the change. That same logic was reused during the refactor to compare each sub-agent's changes against a frozen baseline at every integration point.

Skills don't stay with a single developer. Teknium shares hermes-agent-dev with the rest of the engineering team, who install it in their own Hermes environments so every agent benefits from the cumulative experience. It's extreme "dogfooding" in action: Hermes develops Hermes, learns from the process, and exports the knowledge outward. The payoff isn't just a smaller codebase — it's infrastructure that makes every future refactoring task cheaper and faster.