Skip to main content
DevOps9 min read

Healthy Code Is AI Infrastructure: Cut Agent Drift, Token Waste, and Modernization Rework

Agentic AI can accelerate delivery, but the gains are fragile when code quality declines. Engineering leaders should treat refactoring, test coverage, modularity, and documentation as operational cost controls that make AI-assisted development cheaper, safer, and easier to modernize.

Agentic AI can make a team feel dramatically faster—until the codebase starts pushing back. If every prompt requires the agent to wade through tangled dependencies, unclear naming, missing tests, and stale documentation, the cost of “AI-assisted” delivery can rise quickly.

The lesson for engineering leaders is straightforward: healthy code is no longer just a craftsmanship goal. It is infrastructure for efficient AI-assisted software delivery.

Context: AI Velocity Depends on Codebase Quality

Healthy Code Is AI Infrastructure: Cut Agent Drift, Token Waste, and Modernization Rework
Healthy Code Is AI Infrastructure: Cut Agent Drift, Token Waste, and Modernization Rework

A recent InfoQ article, “Producing Healthy Code with Artificial Intelligence Costs Fewer Tokens,” highlights an important but often under-discussed point: agentic AI can speed up software delivery, but those gains can vanish within months as code quality degrades. The article frames healthier code as requiring fewer AI tokens to work with, because agents need less context, fewer retries, and less clarification to understand and safely modify the system.

That framing matters. Many organizations are evaluating AI coding agents primarily through the lens of developer productivity: pull requests created, tickets closed, code generated, or cycle time reduced. Those metrics are useful, but incomplete. If AI-generated changes increase complexity, weaken architectural boundaries, or expand test gaps, the team may simply be borrowing velocity from the future.

This is especially relevant for teams modernizing legacy systems. AI tools can help explain old code, generate migration scaffolding, update dependencies, and produce tests. But the effectiveness of those tools depends heavily on the quality of the code they are asked to operate on. A modular, well-tested service gives an agent a narrow and reliable problem space. A tightly coupled legacy application with inconsistent patterns forces the agent to infer intent from noise.

Why Unhealthy Code Wastes AI Tokens

Tokens are not just a billing unit. They are a proxy for how much context an AI system must consume and reason about before it can act.

When a codebase is healthy, an agent can work with compact, meaningful context: a clear module, a focused interface, a test file, and a small set of related dependencies. When a codebase is unhealthy, the agent may need to inspect large parts of the repository to answer basic questions such as:

  • Where is this behavior actually implemented?
  • Which code path is still in use?
  • What side effects might this change trigger?
  • Are there tests that define the expected behavior?
  • Is the documentation current or misleading?

Every ambiguity increases token usage. Every retry increases cost. Every failed patch consumes human review time. Over time, poor code quality turns AI assistance into an expensive guessing game.

This is where the InfoQ argument is especially useful for CTOs and platform leaders: healthier code requires fewer tokens because it carries less accidental complexity. A clean boundary, a useful test, or a concise design note can reduce the amount of context an agent needs to complete the task safely.

Agent Drift Is a Code Quality Problem, Too

Agent drift happens when an AI assistant moves away from the intended task, architecture, or operating constraints. Sometimes the drift is obvious: the agent edits unrelated files, introduces a new dependency, or rewrites a component unnecessarily. Other times it is subtle: it follows an outdated pattern, duplicates existing logic, or implements behavior in the wrong layer.

Teams often respond by improving prompts or adding more instructions. That helps, but it does not solve the underlying problem if the repository itself sends mixed signals.

A codebase with multiple competing patterns gives the agent multiple plausible answers. If half the services use one error-handling strategy and half use another, the agent may choose either. If business logic is duplicated in controllers, workers, and database triggers, the agent may patch the symptom rather than the system. If tests are sparse, the agent has little executable feedback to confirm whether its solution is correct.

In other words, agent drift is not only an AI behavior issue. It is often a maintainability issue exposed by AI.

AI Speed Can Hide Modernization Rework

AI coding agents are useful during modernization initiatives: framework upgrades, dependency updates, cloud migrations, API refactors, and test generation. But modernization is not just a code transformation problem. It is a systems understanding problem.

If a team uses AI to accelerate changes without paying down quality debt, it may end up creating a larger modernization backlog. For example:

  • A framework upgrade succeeds syntactically but preserves obsolete architectural patterns.
  • Generated tests lock in current behavior without distinguishing intended behavior from accidental behavior.
  • Dependency updates are applied inconsistently across services.
  • New code follows the style of nearby legacy code instead of the target architecture.
  • Documentation is generated once but not maintained as the system changes.

The result is modernization rework. The team moves quickly, but each wave of change leaves behind inconsistencies that must be cleaned up later.

This connects with broader discussion in the software delivery community. InfoQ’s “AI-Assisted Software Delivery: From Code to Production” emphasizes that AI-assisted development must be considered across the delivery lifecycle, not only at code generation time. Similarly, The New Stack’s discussion of whether an AI agent needs an LLM to decide every next step points to a growing concern: agentic workflows can become unnecessarily expensive or complex when systems lack clear structure and deterministic pathways.

The practical implication is that modernization strategy should include code health as a first-class AI enablement activity.

Treat Refactoring as an Operational Cost Control

For years, refactoring has been framed as technical hygiene: important, but easy to defer. In AI-assisted delivery, refactoring becomes an operational cost control.

Better structure reduces the amount of context agents need. Stronger tests reduce the number of manual review cycles. Clear documentation reduces clarification prompts. Consistent patterns reduce drift. Modular boundaries reduce the blast radius of generated changes.

That means code quality investments can be evaluated in financial and operational terms, not only engineering aesthetics. A refactoring effort that reduces repeated agent failures, review churn, regression risk, and token consumption has a measurable delivery impact.

For engineering leaders, this is a helpful way to justify maintenance work. The question is no longer, “Can we afford to spend time cleaning this up?” It becomes, “Can we afford to keep paying an AI and our engineers to repeatedly rediscover the same complexity?”

Practical Implications for Engineering Teams

1. Add Code Health to Your AI Adoption Plan

Do not roll out AI coding agents as a standalone productivity initiative. Pair the rollout with a code health program. Identify the repositories where AI assistance is likely to produce the most value, then assess whether those repositories have enough structure, tests, and documentation to support reliable agent work.

A lightweight readiness review might include:

  • Test coverage for critical paths
  • Build and test reliability
  • Clear module ownership
  • Consistent naming and patterns
  • Current dependency versions
  • Useful README and architecture notes
  • Known hotspots and high-churn files

The goal is not perfection. The goal is to make the codebase legible to both humans and AI systems.

2. Prioritize Tests Where Agents Will Operate

Test coverage is one of the strongest controls for AI-assisted development. Agents can generate code quickly, but tests define the guardrails. Without tests, human reviewers must manually infer whether the change is safe.

Start by improving coverage around areas where agents are most likely to work: repetitive bug fixes, dependency upgrades, API changes, and modernization tasks. Characterization tests are especially useful for legacy systems because they capture existing behavior before deeper refactoring begins.

3. Reduce Context Size Through Modularity

Large, tangled modules are expensive for AI to understand. Smaller modules with clear interfaces reduce token usage and improve accuracy because agents can reason locally.

Look for boundaries that can be extracted gradually:

  • Business rules separated from transport concerns
  • Data access isolated behind repositories or services
  • Shared utilities consolidated and documented
  • Deprecated paths removed instead of preserved indefinitely
  • Feature-specific logic grouped in predictable locations

The payoff is not only cleaner architecture. It is lower-cost AI interaction.

4. Make Documentation Executable Where Possible

Documentation helps agents, but stale documentation can mislead them. Favor documentation that is close to the code and reinforced by automation: tests, examples, schemas, OpenAPI specs, migration guides, and decision records.

Short architecture decision records can be particularly helpful. They tell both engineers and agents why a pattern exists, not just what the code currently does.

5. Track AI Delivery Quality, Not Just AI Usage

Measuring how often developers use AI tools is not enough. Track whether AI-assisted work is improving or degrading maintainability.

Useful indicators include:

  • Review cycles per AI-assisted pull request
  • Rework rate after merge
  • Defect rate in AI-touched areas
  • Test coverage change over time
  • Complexity and duplication trends
  • Frequency of agent edits outside the intended scope
  • Token usage for common maintenance tasks

If velocity rises but rework and complexity rise with it, the organization is not gaining sustainable speed.

How Vibgrate Thinks About AI-Ready Modernization

At Vibgrate, we see software maintenance and modernization as the foundation for durable engineering velocity. AI tools can accelerate upgrades, refactors, dependency cleanup, and test creation—but only when the codebase provides enough structure for those tools to operate safely.

That means AI readiness should be part of modernization planning. Before a major upgrade, teams should identify quality debt that will increase migration risk. Before introducing agentic workflows, teams should strengthen the areas where agents will work most often. Before measuring productivity gains, teams should establish whether those gains are sustainable.

Healthy code does not eliminate the need for human judgment. It makes human judgment go further by reducing noise, ambiguity, and repetitive rediscovery.

Conclusion: The Future of AI Delivery Belongs to Maintainable Systems

Agentic AI can increase engineering velocity, but it does not repeal the laws of software maintenance. Complexity still compounds. Weak tests still slow releases. Poor modularity still increases risk. Stale documentation still misleads.

The difference now is that code quality debt has a more visible operational cost: more tokens, more drift, more review time, and more modernization rework. Teams that treat healthy code as AI infrastructure will get more reliable value from coding agents than teams that treat AI as a shortcut around maintenance.

The next phase of AI-assisted software delivery will not be won by the teams that generate the most code. It will be won by the teams whose systems are easiest for humans and agents to understand, change, test, and modernize.

Vibgrate CLI

See a real scan run

A replay of the actual CLI running against our test repositories — live progress, real findings, a genuine DriftScore. Nothing executes in your browser.

Replay
demo@vibgrate — bash
❯ npx @vibgrate/cli scan
 
╭──────────────────────────────────────────╮
│ Vibgrate Drift Report │
╰──────────────────────────────────────────╯
 
── node-turborepo (node) .
Runtime: >=18.0.0 (8 majors behind)
Frameworks:
Turbo: 1.13.4 → 2.11.13 (1 behind)
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Dependencies:
1 current 1 1-behind 3 2+ behind 1 unknown
 
── @repo/admin (node) apps/admin
Frameworks:
TanStack Query: 5.108.4 → 5.108.4 (current)
React: 18.3.1 → 19.3.1 (1 behind)
React DOM: 18.3.1 → 19.3.1 (1 behind)
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Vite: 5.4.21 → 8.4.1 (3 behind)
Dependencies:
3 current 9 1-behind 3 2+ behind 4 unknown
 
── @repo/api (node) apps/api
Frameworks:
Express: 4.22.3 → 5.3.0 (1 behind)
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Vitest: 1.6.1 → 5.1.2 (4 behind)
Dependencies:
7 current 4 1-behind 4 2+ behind 4 unknown
 
── @repo/web (node) apps/web
Frameworks:
Next.js: 14.2.35 → 16.5.0 (2 behind)
React: 18.3.1 → 19.3.1 (1 behind)
React DOM: 18.3.1 → 19.3.1 (1 behind)
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Dependencies:
2 current 6 1-behind 3 2+ behind 5 unknown
 
── @repo/config (node) packages/config
Frameworks:
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Dependencies:
2 current 2 1-behind 5 2+ behind 0 unknown
 
── @repo/database (node) packages/database
Frameworks:
Prisma: 5.22.0 → 7.10.1 (2 behind)
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Dependencies:
1 current 0 1-behind 3 2+ behind 1 unknown
 
── @repo/types (node) packages/types
Frameworks:
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Dependencies:
0 current 0 1-behind 1 2+ behind 1 unknown
 
── @repo/ui (node) packages/ui
Frameworks:
React: 18.3.1 → 19.3.1 (1 behind)
TypeScript: 5.9.3 → 7.0.2 (2 behind)
React: 18.3.1 → 19.3.1 (1 behind)
Dependencies:
1 current 4 1-behind 1 2+ behind 1 unknown
 
── @repo/utils (node) packages/utils
Frameworks:
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Vitest: 1.6.1 → 5.1.2 (4 behind)
Dependencies:
0 current 1 1-behind 2 2+ behind 1 unknown
 
Tech Stack
Frontend: React, React DOM
Meta-frameworks: Next.js
Bundlers: tsx, Turbo, Vite
CSS / UI: Autoprefixer, PostCSS, Tailwind CSS
Backend: Express
ORM / Database: Prisma, Prisma Client
Testing: Vitest
Lint & Format: ESLint, ESLint Prettier, ESLint React, Prettier, typescript-eslint
 
Services & Integrations
Auth: JWT 9.0.3
Databases: Prisma 5.22.0
 
TypeScript
v5.3.3 · strict ✔ · MIXED · target: ES2022
 
Build & Deploy
Package Managers: pnpm
Monorepo: npm-workspaces, pnpm-workspaces, turbo
 
Product Purpose Signals
Frameworks: react, nextjs
Evidence: 177
Top Signals:
- [heading] Dashboard (apps/admin/src/pages/Dashboard.tsx)
- [title] Revenue Overview (apps/admin/src/pages/Dashboard.tsx)
- [copy] workspace:* (packages/ui/package.json)
- [copy] ./dist (packages/ui/tsconfig.json)
- [copy] ./src/index.ts (packages/ui/package.json)
- [copy] @repo/config/tsconfig-base.json (packages/ui/tsconfig.json)
- [copy] @repo/ui (packages/ui/package.json)
- [copy] #3b82f6 (apps/admin/src/pages/Dashboard.tsx)
Unknowns:
- No pricing or billing evidence found.
- No integrations/connectors evidence found.
- No route structure evidence found.
 
Security Posture
Lockfile ✖ · node_modules ✔
 
Platform
Native modules: turbo
 
Code Quality
Files: 36 · Functions: 183 · Avg complexity: 2.62 · Avg length: 21.13 lines
Max nesting: 2 · Circular deps: 0 · Dead code: 0%
God files: apps/admin/src/pages/Products (448 lines)
 
Database Schema
postgresql · 8 models · 1 enum
Models: Address, CartItem, Category, Order, OrderItem (+3 more)
 
Findings (16 errors, 11 warnings)
✖ @types/node is 6 major versions behind (spec: ^20.11.0, latest: 26.6.11).
vibgrate/dependency-major-lag in .
✖ 60% of dependencies are 2+ major versions behind in node-turborepo.
vibgrate/dependency-rot in .
✖ Node.js runtime ">=18.0.0" reached end-of-life on 2025-04-30 (latest: 26.0.0).
vibgrate/runtime-eol in .
✖ vite is 3 major versions behind (spec: ^5.0.12, latest: 8.4.1).
vibgrate/dependency-major-lag in apps/admin
✖ Vite is 3 major versions behind (current: 5.4.21, latest: 8.4.1).
vibgrate/framework-major-lag in apps/admin
✖ @types/node is 6 major versions behind (spec: ^20.11.0, latest: 26.6.11).
vibgrate/dependency-major-lag in apps/api
✖ vitest is 4 major versions behind (spec: ^1.2.1, latest: 5.1.2).
vibgrate/dependency-major-lag in apps/api
✖ Vitest is 4 major versions behind (current: 1.6.1, latest: 5.1.2).
vibgrate/framework-major-lag in apps/api
✖ @types/node is 6 major versions behind (spec: ^20.11.0, latest: 26.6.11).
vibgrate/dependency-major-lag in apps/web
✖ eslint-plugin-react-hooks is 3 major versions behind (spec: ^4.6.0, latest: 7.1.1).
vibgrate/dependency-major-lag in packages/config
✖ 56% of dependencies are 2+ major versions behind in @repo/config.
vibgrate/dependency-rot in packages/config
✖ 75% of dependencies are 2+ major versions behind in @repo/database.
vibgrate/dependency-rot in packages/database
✖ 100% of dependencies are 2+ major versions behind in @repo/types.
vibgrate/dependency-rot in packages/types
✖ vitest is 4 major versions behind (spec: ^1.2.1, latest: 5.1.2).
vibgrate/dependency-major-lag in packages/utils
✖ 67% of dependencies are 2+ major versions behind in @repo/utils.
vibgrate/dependency-rot in packages/utils
✖ Vitest is 4 major versions behind (current: 1.6.1, latest: 5.1.2).
vibgrate/framework-major-lag in packages/utils
⚠ TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in .
⚠ TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in apps/admin
⚠ TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in apps/api
⚠ Next.js is 2 major versions behind (current: 14.2.35, latest: 16.5.0).
vibgrate/framework-major-lag in apps/web
⚠ TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in apps/web
⚠ TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in packages/config
⚠ Prisma is 2 major versions behind (current: 5.22.0, latest: 7.10.1).
vibgrate/framework-major-lag in packages/database
⚠ TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in packages/database
⚠ TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in packages/types
⚠ TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in packages/ui
⚠ TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in packages/utils
 
╭──────────────────────────────────────────╮
│ Top Priority Actions │
╰──────────────────────────────────────────╯
 
1. Upgrade EOL runtime in node-turborepo
End-of-life runtimes no longer receive security patches and block ecosystem upgrades.
./.
>=18.0.0 → 26.0.0 (8 majors behind)
Impact: −10 drift points (runtime & EOL)
 
2. Fix security posture: no lockfile found
Without a lockfile, installs are non-deterministic. Run the install command to generate one and commit it.
./
Missing: package-lock.json, pnpm-lock.yaml, or yarn.lock
 
3. Upgrade Vitest 1.6.1 → 5.1.2 in @repo/api (+2 more)
4 major versions behind. Major framework drift increases breaking change risk and blocks access to security fixes and performance improvements.
./apps/api
Vitest: 1.6.1 → 5.1.2 (4 majors behind)
./packages/utils
Vitest: 1.6.1 → 5.1.2 (4 majors behind)
./apps/admin
Vite: 5.4.21 → 8.4.1 (3 majors behind)
Impact: −5–15 drift points
 
4. Reduce dependency rot in @repo/types (100% severely outdated)
1 of 1 dependencies are 2+ majors behind. Run `npm outdated` and prioritise packages with known CVEs or breaking API changes.
./packages/types
typescript: 5.9.3 → 7.0.2 (2 majors behind)
Impact: −5–10 drift points
 
5. Reduce dependency rot in @repo/database (75% severely outdated)
3 of 4 dependencies are 2+ majors behind. Run `npm outdated` and prioritise packages with known CVEs or breaking API changes.
./packages/database
@prisma/client: 5.22.0 → 7.10.1 (2 majors behind)
prisma: 5.22.0 → 7.10.1 (2 majors behind)
typescript: 5.9.3 → 7.0.2 (2 majors behind)
Impact: −5–10 drift points
 
╭──────────────────────────────────────────╮
│ Architecture Layers │
╰──────────────────────────────────────────╯
 
Archetype: nextjs (80% confidence)
Files classified: 24 (11 unclassified)
Folders classified: 8
apps/admin/src presentation 100% 4 files
apps/admin/src/pages presentation 100% 2 files
apps/api/src/middleware middleware 100% 2 files
apps/api/src/routes routing 100% 2 files
apps/web/src/app presentation 100% 4 files
apps/web/src/app/products presentation 100% 2 files
apps/web/src/app/products/[id] presentation 100% 1 file
packages/ui/src presentation 100% 6 files
Unclassified source (sample): 11
 
presentation 15 files drift ████████████████████ 100 risk high
routing 4 files drift ████████████████████ 100 risk high
middleware 2 files drift ███████▍░░░░░░░░░░░░ 37 risk moderate
config 2 files drift ░░░░░░░░░░░░░░░░░░░░ 0 risk none
shared 1 file drift ████████████████████ 100 risk high
 
╭──────────────────────────────────────────╮
│ DriftScore Summary │
╰──────────────────────────────────────────╯
 
DriftScore: 70/100
Risk Level: HIGH
Projects: 9
Classified: 8 nano · 1 micro · 0 small · 0 standard
Billable: 0.42 · 9 detected → 0.42 billable projects (micro-project pricing)
0.1 micro · 0.32 nano
These fractions add up across repositories, then round down to whole billable projects.
 
Score Breakdown
Runtime: ████████████████████ 100
Frameworks: ███████████▊░░░░░░░░ 59
Dependencies: ███████▏░░░░░░░░░░░░ 36
EOL Risk: ████████████████████ 100
 
Scanned at 2026-12-04T09:51:34.300Z · 5.0s · 286 files scanned · 56 workspace files · 27 dirs
❯
Press Run to start.