Skip to content

CareerTechnology · Case study

KIT Before and After: Refactoring a Whole Development System

A case study of a system built to work with AI agents: accumulated problems, diagnosis, the new workflow, and measured results.

· 12 min read

KIT is a development environment where most code is written by Claude Code agents running in parallel: 19 repositories, a VPS CI lane, production on Cloudflare and two servers, run by one person. This piece presents the system and workflow after a whole-system refactor, in four steps: problems, diagnosis, solution, results.

Figure 1 · Before and after, six numbers
24.1 s
2.9 s
format check on every verify
5.1 s
0.23 s
typecheck of the largest package (TS7 incremental)
4.0 GB
2.1 GB
peak RAM of one test run
0/5
5/5
listening processes the watchdog detects
22
0
configuration drift warnings (kit-doctor)
393 MB
28 MB
dependencies installed on the data-collector server
Source: KIT refactor records, 8 to 9 Nov 2026.
Figure 2 · The system: one person, many agents, four control layers
Owner
sets goals; keeps privacy, cost and product decisions
Orchestrator agent
audits hypotheses, splits non-overlapping lanes, picks model tiers
Implement
change + commit locally
Review
another agent, refutes
Ship
push · deploy · read back
Hard fences
deny rules · dangerous-command hook
Repo checks
verify ladder · test counts
Process runners
Job Object · watchdog
Drift detection
kit-doctor
19 repos · VPS CI · Cloudflare + 2 servers
every production change has a rollback id
Post-refactor architecture. The dark box is the only way a change reaches production.

I. The problem: operational debt compounds

Each problem on its own is small, and many sound "basic". The cause is not a lack of knowledge but that tool defaults are designed for one person running one session. With many agents generating code in parallel, the same defaults multiply by sessions, workers and commits.

Figure 3 · Why "basic" problems appear: defaults built for one person
1 PERSON, 1 SESSIONMANY AGENTS, MANY SESSIONSTest workers= cores: uses the machine× sessions: out of RAMBackground processesa person stops themthe agent ends, the process staysCommand wrappers+0.5 s, nobody notices× dozens of calls × every verifyCaches, incrementala few runs a dayhundreds of runs a dayGenerated config filesa person knows it is noiseagents read it as someone's unfinished work
Developer-tool defaults are designed for one developer running one session. With many agents generating code in parallel, the same defaults become debt.
Figure 4 · Eight problems before the refactor, and why they grow
1Orphan processesdev servers alive for hours; one process tree ran 317 min at 100% CPU↗ every new session leaves more
2Tests fighting for RAMone worker per core by default; one test run took 4 GB↗ multiplies with concurrent sessions
3Command wrapperspnpm re-executing an older version: 0.53 s per call; npx 1.1 s vs 0.1 s↗ adds up per command in every verify
4No caches, no incrementalformat, lint, typecheck rerun in full; 48 of 57 tsconfigs not incremental↗ grows with code size
5Test evidence expiringthe fingerprint hashed tests and docs too; the largest package re-ran on 46% of commits↗ grows with daily commits
6CI lane waste70% of the VPS job CPU; still judged superseded commits; a false red alert every day↗ false alarms dull real ones
7Harness driftclaude broken inside tool shells; 11 repos always showing phantom "modified" files; stale config keys↗ every agent session misreads the state
8Disk and cachesa 2.5 GB orphaned package store; 4.9 GB of dead builds; 2.4 GB of temp cache↗ only grows, never shrinks
Source: read-only pre-refactor survey (14 areas), checked against source and measurements.
Figure 5 · Why operational debt compounds
uncapped workerscapped
1 session testing at once4.0 → 2.1 GB
2 sessions testing at once8.0 → 4.2 GB
3 sessions testing at once12.0 → 6.3 GB
track = the machine's full 31.4 GiB of RAM
Illustrative arithmetic from real measurements: one test run takes 4.0 GB uncapped, 2.1 GB capped; the machine has 31.4 GiB. Excludes browsers, dev servers and Claude sessions (300 to 600 MB each).

II. Diagnosis: audit before fixing

Five AI-written performance reports already existed, full of proposals and a very confident voice. The first step was to change nothing: check every claim against the current source. Only 7 of 21 claims held. Every number used for a conclusion afterwards had to be measured on an idle machine, repeated, with identical passing test counts on both sides.

Figure 6 · 21 claims from the earlier reports, checked against current code
7Held, or worse than reported
5Partly true
3Wrong or inflated (e.g. "TS7 37x faster" from a run that bailed out)
3Stale or already fixed
2A choice, not a fact
1Unverifiable
Source: the diagnosis step's conflict register. The input reports were AI-written.

III. Workflow: every step has an evidence gate

The biggest change is in how work with agents is done. No agent declares its own "done": the author cannot ship, the reviewer is a different agent that sees only the diff and evidence, and only the ship step touches production, with a live readback and a rollback id. The idle-machine rule proved its worth too: the same change measured on a busy machine was off in both directions.

Figure 7 · The workflow: every step has an evidence gate
01Auditevery report is a hypothesis, checked against codeclaim register
02Split lanesno overlap, one workspace per lanefiles per lane
03Implementcommit locally; no push, deploy or production writestests pass + counts
04Reviewa different agent, sees only diff + evidence0 blockers
05Shippush, deploy, read the live system backhealth + rollback
06Criticmaps the full scope, finds skipped worknext wave
14 reviews produced 48 findings (0 blocker, 1 major, 47 minor), all resolved before shipping. The single major finding was something no test caught.
Figure 8 · The same change, measured busy and idle
busy machineidle machine
Warm typecheck, Worker repo1.7× → 6.8×
Vitest 4 workers, game1.1× → 1.0×
pnpm without re-exec2.4× → 6.6×
TypeScript 7 vs tsc 67.2× → 7.8×
Speed-up factor. During the "busy" runs about 13 agent lanes shared the machine. Busy numbers can be wrong in both directions, so only idle numbers are used for conclusions.

IV. Fixes, layer by layer

Each layer was fixed at its root cause and has one headline number to verify it.

Toolchain. TypeScript 7 is about 22 times faster but stays a fast path: tsc 6 remains the official gate because TS7 produced a different file set in 2 of 47 typecheck runs, and some tools still need the TS6 API. A new tool replaces an old gate only when its results are identical, not when it is faster.

Figure 9 · Fixes by layer, one headline number each
ToolchainTS7 fast path, incremental, caches, pnpm 12, worker caps5.06 → 0.23 s
Processesrewritten watchdog, Job Object runners0/5 → 5/5
Evidence + CIinput-accurate fingerprint, skip superseded commits−24% reruns
Harnessconfig fixes, write-if-changed, kit-doctor22 → 0 warnings
Workflowaudit → implement → review → ship48 findings
Productionmemoised immutable data, fewer queries, minimal collector117 → 43 ms
Source: KIT refactor records, 8 to 9 Nov 2026.
Figure 10 · Typecheck of the largest package (1,099 files)
tsc 6, cold (before)5.06 s · 1.0×
tsc 6, warm incremental1.24 s · 4.1×
TypeScript 7 (tsgo), cold0.65 s · 7.8×
TypeScript 7, warm incremental0.23 s · 22.0×
Median of 5 on an idle machine. All four give the same result: 1,099 files, 0 errors; on a deliberate-error fixture TS6 and TS7 report the same 6 errors at the same lines and columns. TS7 shows a real check time of 0.549 s (not a bail-out).
Figure 11 · Time of the commands run every day
Format check (Prettier)24 → 2.9 s · 8.2×
content-based --cache
Lint (ESLint)10 → 0.86 s · 12.1×
--cache
Typecheck, Worker repo22 → 3.3 s · 6.8×
incremental + 188 files no longer checked twice
Python engine tests229 → 87 s · 2.6×
pytest-xdist -n 3
QA suite88 → 42 s · 2.1×
4-way parallel
Calling pnpm in a repo0.53 → 0.08 s · 6.6×
pin pnpm 12, no more re-exec
Median of 3 to 7 runs, background CPU under 25%, identical passing test counts on both sides. Light bar before, dark bar after.
Figure 12 · Peak RAM of the process tree (MB)
node --test, Worker repo4046 → 2072 · −49%
concurrency 6; 28% slower, a deliberate trade
Typecheck, Worker repo1608 → 767 · −52%
6.8× faster
Vitest, TypeScript game1295 → 829 · −36%
4 workers; same time
Prettier493 → 195 · −60%
8.2× faster
Game dev server (7 → 3 processes)278 → 103 · −63%
plain node instead of a pnpm → tsx chain
Working set summed over the tree, sampled every 250 ms; for comparison, not an absolute value.

Processes, CI and harness. The watchdog kills only when the owning session is dead and re-checks identity right before a kill. The CI lane re-runs only what actually changed and skips superseded commits. The Claude Code harness was fixed, slimmed down, and gained kit-doctor to catch configuration drift.

Figure 13 · Process lifecycle
Detecting listening processes
BEFOREsystem API took 300 to 3,000 ms and missed 5 of 5AFTERreads the TCP table directly: about 1 ms, 5 of 5 found
The kill decision
BEFOREby age and CPU; could kill a live session's background test; orphaned dev servers with child processes were never cleanedAFTERonly once the owning session is dead; identity (PID + start time) re-checked right before the kill
Cancelling a verify
BEFOREparent dies, children live on; a runner could wait 2 hoursAFTERWindows Job Object + parent-chain watch: the whole tree dies in about 1.1 s
Tests for the watchdog itself
BEFOREnoneAFTER94 tests on synthetic process trees, including PID reuse
Source: KIT refactor records, 8 to 9 Nov 2026.
Figure 14 · Test evidence and the CI lane
Test-evidence fingerprint
BEFOREhashed whole directories incl. tests and docs: editing a README re-ran dependantsAFTERhashes real inputs only; over 50 commits the new selection is a subset of the old, about 24% fewer reruns
Superseded commits
BEFOREthe CI lane judged them in full; about 1 in 3 runs judged a stale commitAFTERstops before the heavy phase if main moved and judges the new tip; bounded hops and time
Backup alert
BEFOREa false red every day (a 2-hour threshold for data produced once a day)AFTER26-hour threshold; the stopped-collector alarm stays at 2 hours
Timestamps in evidence
BEFOREaccepted timestamps up to 1 hour in the futureAFTERone shared policy: more than 300 s ahead is invalid
Source: KIT refactor records, 8 to 9 Nov 2026.
Figure 15 · The Claude Code harness
claude inside tool shells
BEFOREbroken (exit 127): the shell snapshot dropped an internal functionAFTERworks in interactive and tool shells
Phantom "modified" files
BEFORE11 repos: the config generator rewrote files with different line endingsAFTER0: writes only on real change, keeps line endings
Instructions loaded per session
BEFORE3,247 bytes at the root, including tool-only sectionsAFTER1,953 bytes; tool-specific parts load only in their own folder
Drift detection
BEFOREmanual, report by reportAFTERread-only kit-doctor: 22 warnings to 0, runs in about 0.14 to 0.3 s
Agent permissions
BEFOREthe auto classifier blocked legitimate operations; some configured paths were malformedAFTERruns unblocked; hard fences (secrets, force-push, reset) kept
Source: KIT refactor records, 8 to 9 Nov 2026.

V. Safety with unblocked agents

The automatic safety classifier also blocked legitimate operations, so it was turned off. Safety moved to five layers of hard rules and process, each stopping one specific risk, instead of one general judgement layer.

Figure 16 · Auto classifier off, five safety layers on
Deny rulesstops: reading secrets, repos owned by someone else
Command-blocking hookstops: force-push, reset --hard, stash, clean, add -A
Stage rulestops: implementing agents pushing, deploying or writing production
Independent reviewstops: a wrong change reaching ship
Readback + rollbackstops: a defect staying in production
The automatic classifier also blocked legitimate operations (read-only checks, approved deploys). Safety moved to hard-rule and process layers, each stopping one specific risk.

VI. Results, cost, and what did not work

The gains reach beyond the dev machine: one SSR page uses 63% less CPU per render, one homepage reads 42% fewer rows, and the data-collector server installs only its 5 direct dependencies. Disk was reconciled per drive, so the real amount freed (about 13 GB) is lower than the summed total (about 15 GB).

The refactor took about 8 hours with no added infrastructure spend. Not everything went smoothly, and the misses are part of the workflow too: each got an independent check and left a new rule behind.

Figure 17 · Effect on production
CPU per SSR page render (ms)117 → 43 · −63%
D1 rows read per homepage view2,555 → 1,483 · −42%
Pages Function calls / 24 h11,882 → 9,460 · −20%
Collector server dependencies (MB)393 → 28 · −93%
Function calls compare the 24 hours before and after deploy, not normalised for traffic. Every production change has a rollback id and was read back after deploy.
Figure 18 · Disk: deleted, moved, regenerated (GB)
Truly deleted, system drive7.2
orphaned package store, temp cache, metadata, a stale worktree
Truly deleted, data drive5.8
4.9 GB of dead builds, merged worktree, a scratch data copy
Only moved to the archive3.7
same drive: frees nothing
Regenerated, root-caused0.9
temp deploy checkouts lived on the system drive: moved to the data drive
Reconciled per volume. Summing each step's "cleaned" items gives about 15 GB; the real figure is about 13 GB.
Figure 19 · What the refactor cost
~8 h
wall time on day 1, plus one morning of readbacks
77
planned agent runs: Sonnet 50, Opus 17, Fable 10
11.2 M
subagent tokens
4,622
tool calls
$0
added infrastructure spend
Source: workflow journals. Tokens as reported per subagent, excluding the orchestrating session. Infrastructure stayed on Free plans and existing servers.
Figure 20 · What did not work, and how it was handled
An agent ran --help on an unread script; it ignored the flag and called the production database
→ independent SELECT-only check: 0 rows changed
✓ read before running; scripts refuse unknown flags
Messaging a running agent spawned a copy; two copies edited one directory
→ copy stopped, no change lost
✓ never cut into an agent inside a workflow
The first server deploy ran the old version of its own deploy script
→ rolled back, rebuilt: 253 → 23 dependency folders
✓ run a just-changed deploy script twice
A CPU optimisation 7.6% faster locally
→ after 1 h in production: not separable from noise
✓ report it as such, keep watching
The auto classifier blocked read-only checks and approved deploys
→ agents did not work around it; they wrote the command down
✓ move safety to hard-rule layers
Source: KIT refactor records, 8 to 9 Nov 2026.

VII. Three principles

  • Measure operational debt under real load. Small problems multiply with sessions, workers and commits.
  • No "done" without evidence. Counts, measurement conditions, independent review, production readback, a way back.
  • A new tool replaces an old gate when results are identical. Faster is not enough.
An effective system for working with AI agents is not the one running the most agents, but the one where every "done" can be verified.

technologycareergrowth