How to Cut Vibe Coding Technical Debt
172,588 lines deleted in 30 days (86,851 in the last 7 days alone), 58 net-negative commits out of 448 merged PRs on the Alook repository, zero removed features, and 18,661 unit and DOM tests green.
Most vibe-coded apps die under dead code the AI wrote "just in case," long before they run out of features.
AI made adding code close to free. Maintaining a large codebase with coding agents requires the opposite habit: treating every new feature as a reason to cut dead weight, merge duplicate paths, and lock engineering principles into automated checks.

Why vibe coding technical debt piles up in a large codebase
When an app is two weeks old, asking Claude Code or Codex to "add X" works because there is almost nothing to collide with. Six months later, the same prompt habit creates a specific kind of AI-generated code technical debt.
Coding agents optimize for the task in front of them. Tell an agent to build a settings panel or a new backend query, and it will write a fresh Tabs component, a bespoke radio group, or a brand-new database helper instead of searching 400 files to see what the product already uses. Each shortcut passes its own test, gets merged, and leaves a second copy of the same concept in the repo.
That bloat compounds in three places at once:
- Duplicate UI and query paths. Two components do the same job with slightly different padding, state handling, or edge-case behavior. Fixing a bug in one leaves the other broken.
- Ghost code left behind after pivots. When requirements shift mid-sprint, agents wire up the new route, Durable Object call, or telemetry hook while leaving the old path untouched so they will not break the current diff.
- Brittle tests that lock in bad structure. Agents love writing regex pseudo-unit tests that read source strings, or stacking slow redundant E2E specs. When you try to simplify the code later, those tests fail on refactors and quietly reward copy-paste additions instead.
Once a repo reaches that stage, asking "what else can AI add?" makes every future change slower. The useful question for mature repositories is simpler: what can we delete without losing product capability?
What deleting 172,588 lines actually looked like
Every major cleanup happened inside normal shipping weeks on alookai/alook, not during a feature freeze. The deletions landed across the exact categories where vibe-coded repos tend to swell.
| Cleanup area | Public PRs | Lines deleted | Net LOC | What got simplified |
|---|---|---|---|---|
| Brittle & redundant tests | #1430, #1431 | -21,959 | -21,684 | Removed source-string regex pseudo-tests and degraded E2E specs; covered behavior with fast DOM tests |
| Tangled scroll logic | #1434 | -9,631 | -6,827 | Replaced useScrollAnchor across 43 files with a 3-state useConversationScroll kernel |
| Overbuilt frontend telemetry | #1416 | -7,326 | -6,988 | Removed bloated frontend Faro tracing instrumentation across 228 files |
| Redundant abstraction layers | #1450 | -4,664 | -4,217 | Deleted the LineClamp wrapper, kept the main renderer, and fixed tail-scroll bugs |
| Legacy quota & protocol drift | #1528 | -3,201 | -2,227 | Stripped non-standard quota scraping paths across 67 files to align with clean standards |
| Pre-feature dead-code cleanup | #1567, #1572 | -569 | +285 / -234 | Cleared unused Page AI agents, comment routes, SiteHubObject RPCs, and 4 hot-path D1 reads before shipping public Page sharing (#1576) |
Two of those deletions explain the payoff better than any refactoring slogan.
First, removing an unnecessary layer often fixes the bug you were fighting. Before PR #1450, chat tail-scrolling kept misbehaving inside a LineClamp wrapper. Deleting 4,664 lines and keeping the primary message renderer fixed tail scrolling and left a path small enough to reason about in one screen. Similarly, PR #1434 collapsed layered useScrollAnchor workarounds into a single 3-state useConversationScroll kernel, cutting 6,827 net lines across 43 files.
Second, deleting dead code right before a major feature makes the new feature much smaller. Before shipping public sharing on Alook Pages (PR #1576), we merged PR #1567 and PR #1572 to remove abandoned Page AI agent hooks, unused comment routes, redundant SiteHubObject Durable Object RPCs, and four extra D1 reads on the hot path. Without that cleanup, public sharing would have inherited every one of those dead edges.
Frontend hand-rolling adds fewer lines than a telemetry rewrite, yet it fractures product consistency just as fast. In PR #1546, the Triggers UI had accumulated custom Tabs, RadioGroup, Textarea, and count badges. Moving 13 files back onto shared @/components/ui/* primitives meant every future polish change lands in one place.
The stability-phase AGENTS.md / CLAUDE.md rules for large codebases
Most AGENTS.md guides tell models to "write clean, modular code." Models ignore advice that vague because every new helper an agent invents looks clean on its own.
What actually changed agent behavior in our repo was putting explicit project-phase rules into AGENTS.md and CLAUDE.md. Here is the exact stability-phase block you can adapt for any mature codebase:
We are in a stability phase, not a greenfield sprint. This codebase is already large, so treat every new feature as a chance to clean up and consolidate old code.
1. Think in product consistency, not ad-hoc hand-rolled code
Before hand-rolling any UI/UX, treat this as an already-mature product and check whether the same interaction, component, naming, or pattern already exists elsewhere in the app. Reuse it, and keep the design system and component showcase in sync when shared primitives change.
2. Same rule on the backend: organize before adding
Instead of inventing a fresh query or brand-new abstraction for every feature, clean up and reuse the logic already in the repo.
3. Do not multiply entities without necessity
If consolidating an existing path solves the problem, do not add another layer. Writing more code is not skill. Solving the problem with less code is.Three small details make that prompt work in practice:
- Declare the phase upfront. If you do not tell an agent the repo is in a stability phase, it defaults to hackathon mode and scaffolds fresh files for every ticket.
- Name the concrete reuse targets. In Alook, shared UI primitives live under
@/components/ui/*and visual states stay synchronized on/brand-visual. Naming the real directory and showcase gives coding agents a place to check before writing JSX. - Invert the backend default. Reusing an existing query takes a few extra minutes of reading. Writing "organize and reuse before adding" directly into
CLAUDE.mdoverrides the model's instinct to spin up a parallel helper.
If your team runs both Claude Code and Codex, keep one canonical root AGENTS.md (and point CLAUDE.md to it with @AGENTS.md if you need tool-specific notes). We trimmed our own AGENTS.md to match alook -h directly in PR #1553 and unified human-UI and bot terminology in PR #1575 so docs, prompts, and UI stop drifting into separate dialects. For how rules load and survive compaction, see our empirical walkthroughs on Codex memory and AGENTS.md loading and Claude Code persistent memory.
Five Alook engineering principles that keep AI codebases lean
One big cleanup sprint does not last if day-to-day PRs keep reintroducing bloat. On alookai/alook, we turned that AGENTS.md discipline into five concrete guardrails spanning planning, data modeling, CI, security, and testing.
1. Plan first, and delete dead ground before building
Agents do not jump straight into editing a large codebase from a one-sentence request. Every non-trivial change starts with a local plan under plans/ spelling out visible behavior, new dependencies, touched files, and QA checks. Before adding to an older feature area, we clear dead routes and unused queries first (PR #1567, PR #1572) and cut off-track code cleanly instead of leaving hidden feature flags.
We also forbid explanatory comments in ordinary business logic unless the comment encodes a spec or invariant. Stale comments mislead coding agents faster than they mislead humans.
2. Keep a single source of truth, and model real-world ownership
Every business state gets one authoritative owner instead of shadow maps or speculative client caches. Data models follow real-world ownership rather than whichever temporary actor created the row.
In PR #1576, we migrated community_page ownership from bot_id to human owner_user_id (leaving bot_id nullable with ON DELETE SET NULL purely as a creator record). Bots get rotated or deleted; deleting a bot should never wipe a user's pages, and multiple bots under the same owner can now collaborate on one page cleanly. When a user disables public sharing, we clear the share token and call the edge invalidate endpoint immediately instead of waiting on cache TTLs.
On the frontend, PR #1540 split community sync logic by domain and stripped redundant Map clones on the read path so components read one clean source of state.
3. Turn verbal rules into CI ratchets, and design queries for real scale
Verbal agreements break the week two agents work in parallel. Any mistake that shows up twice gets encoded into scripts/ci/ as an automated check (alongside PR #1570, which compacted noisy GitHub Actions logs while preserving exact failure diagnostics).
Database queries follow the same zero-trust rule. Every query must scope by owner, workspace, channel, or an indexed time window before reading business rows, never fetch first and check permissions after. Passing locally on 10 rows proves nothing: in SQLite and Cloudflare D1, an index SEARCH on a low-cardinality boolean like isBot can still walk unrelated tenants, and a trailing LIMIT does not bound scan cost. Risky changes must verify that scanned work stays flat as unrelated rows grow.
On Cloudflare D1, we also enforce a zero DROP TABLE migration rule. Rebuilding a parent table via DROP TABLE can trigger ON DELETE CASCADE wipes on child tables even under PRAGMA defer_foreign_keys = ON. In PR #1576's 0130 migration, we used native column evolution (ADD, backfill, DROP INDEX, DROP, RENAME) and verified foreign_key_check on populated SQLite data. On hot paths, removing hidden serialization beats micro-tuning: setting max_batch_timeout = 0 on queues (PR #1571), parallelizing wake and inbox fan-out (PR #1573), and bounding hot-path concurrency while removing extra D1 reads (PR #1577).
4. Security boundaries beat convenient features
If a convenient feature violates account safety or cross-origin isolation, we cut it.
In PR #1528, we deleted 2,227 net lines across 67 files to strip non-standard third-party quota scraping and replace it with zero-network local turn-usage tracking. For AI-generated HTML/JS hosted inside Alook Pages (PR #1576), we moved execution onto dedicated domains (alook.page and {id}.alook.page) so untrusted page scripts are isolated at the browser same-origin boundary and can never touch alook.ai cookies.
Services themselves stay strictly stateless: durable state lives in the database or local disk, never in Worker memory.
5. Prove behavior at the lowest real boundary, and separate merged from live
Line count and mock coverage buy false comfort. A green mock test does not prove a D1 migration is safe on populated data, and a narrow desktop window does not prove an iOS WebView keyboard layout works.
We pick the lowest layer that actually exercises the risk: pure unit tests for logic, Vitest DOM tests for visible state and events, native Worker/D1 integration for storage contracts, and browser E2E strictly for real multi-process user journeys. We ban two agent habits outright in AGENTS.md: source-string regex pseudo-unit tests and "one bugfix = one new Playwright E2E spec." Cutting 21,959 lines of brittle tests first (PR #1430, PR #1431) gave us a fast 18,661-test safety net we actually trust before deleting 9,631 lines of scroll logic or 7,326 lines of telemetry.
For UI changes, we inspect real light and dark browser screenshots before merging. And we never treat merged to main as live in production: code merge, D1 migration, Worker deployment, and live verification remain explicit separate steps.
Why rules alone stop working once multiple agents share a repo
Putting subtraction rules in AGENTS.md works well when one developer guides one coding agent at a time. The failure mode changes once two or three agents edit the same large codebase in parallel.
Static instruction files only say how to code. They do not tell Agent B that Agent A already consolidated a shared query ten minutes ago, or that a human rejected a wrapper approach in yesterday's review. Without shared visibility into active work and prior decisions, two rule-following agents still invent two incompatible abstractions in the same afternoon. That is also why our AGENTS.md enforces basic multi-agent git hygiene: never git reset or git stash another agent's uncommitted work without asking.
We pair repo-level AGENTS.md rules and CI ratchets with shared Alook channels where humans and bots see the same active PRs, ownership marks, review screenshots, and rejected paths. We also wire GitHub PR webhooks to a dedicated Architect bot that sits across UI, backend, and PR channels, reviews every diff against those stability rules before merge, distills repeated catches into memory.md and experiences/, and resets heavy sessions cleanly with alook commit so a month of judgment stays sharp.
- Walk through the full GitHub webhook, cross-channel Architect review, and long-term memory setup: Auto-review and simplify vibe-coded PRs with a cross-channel Architect agent.
- Pair automated architecture review with end-to-end GitHub coding workflows: Turn GitHub issues into merged PRs with webhooks and AI agents, Ship Linear Ready tickets to merged PRs with AI agents, Turn Sentry production crashes into tested hotfix PRs, Auto-fix failed Vercel builds and deliver verified previews, and Run a fix on your Mac and test it on Windows from your phone.
- Go deeper on multi-agent engineering coordination: How to Prevent Coding Agents From Duplicating Work, What Happens When Multiple AI Agents Edit the Same Repository?, and How to Keep Context Across Multiple Coding Agent Sessions.
Copy-paste AGENTS.md template for your own repo
Start small. Paste this unified AGENTS.md template into your repo root (if you also use Claude Code, point CLAUDE.md to it with @AGENTS.md). It combines our stability-phase subtraction rules, five engineering guardrails, and multi-agent git hygiene. Then pick one item on your backlog and ask your coding agent one question before it writes any new file: what can we delete or merge first so this feature fits into what already exists?
AGENTS.md: Stability-Phase Engineering Rules
============================================
This repository is in a stability phase, not a greenfield sprint. Treat every new feature as a chance to simplify and consolidate existing code.
## 1. Delete and reuse before adding
- Frontend: inspect shared UI primitives (such as `@/components/ui/*`) and your visual spec page before writing JSX. Reuse and maintain shared components instead of hand-rolling one-off copies.
- Backend: organize and reuse existing queries and domain helpers before adding new routes or abstractions.
- Clear dead routes, obsolete fields, and redundant wrappers in the module you touch. Remove abandoned paths completely instead of hiding them behind flags.
- Skip explanatory prose comments in business code; keep only invariant or specification notes.
## 2. Plan first, keep a single source of truth
- Write a short plan before non-trivial changes: user-visible behavior, touched files, dependencies, and verification steps.
- Every piece of state has one authoritative owner. Do not maintain shadow maps or speculative client caches.
- Model data ownership after reality (tie assets to the human owner or workspace, not a disposable bot or session).
## 3. Bound queries at real scale, turn repeat bugs into CI ratchets
- Scope every database query by owner, workspace, channel, or an indexed time window before filtering permissions. Passing on 10 local rows does not prove bounded scans in production.
- Never rebuild foreign-key parent tables via `DROP TABLE` during migrations; use native column evolution and run `foreign_key_check` on populated data.
- Any mistake that happens twice becomes an automated `scripts/ci/` check.
## 4. Security boundaries beat convenient features
- Isolate untrusted external input (webhooks, user-generated HTML/JS) behind hard boundaries; never mix untrusted execution with primary session cookies or implicit write authority.
- Keep server handlers stateless: persist durable state to the database or disk, never process memory.
## 5. Prove behavior at the lowest real boundary, separate merge from deploy
- Match tests to real risk (unit tests for pure logic, DOM behavior tests for UI, native storage integration for DB contracts, E2E only for cross-process user journeys). Ban source-string regex pseudo-tests and one-bug-one-E2E sprawl.
- Verify UI changes with real light and dark browser screenshots before merge.
- Treat `merged to main`, `migration applied`, `deployed`, and `verified live` as separate explicit steps.
## 6. Multi-agent git and channel hygiene
- Never run `git reset`, `git stash`, or overwrite another agent's uncommitted changes without asking.
- Share active PRs, task claims, and rejected approaches in your shared channel, and update this file or CI checks whenever a recurring pattern surfaces.To keep those rules alive across multiple agents, channels, and session resets, read How to Build Agent Memory for Collaborative Teams. If you want to follow our engineering notes or share your own net-negative diffs, find us on X at @alook_ai or inspect the commits directly in github.com/alookai/alook.
Sources & Referenced PRs
All commit counts, test totals, and line-deletion figures come directly from alookai/alook origin/main as of November 30, 2026:
- 7-day window: 152 commits, 86,851 lines deleted.
- 30-day window: 448 commits, 172,588 lines deleted, 58 net-negative commits.
- Test baseline: 18,661 unit and DOM tests passing on November 30, 2026.
- Referenced public PRs: #1416, #1430, #1431, #1434, #1450, #1528, #1540, #1546, #1553, #1567, #1570, #1571, #1572, #1573, #1575, #1576, #1577.