為何AI在現有程式碼庫上表現更佳

為何AI在現有程式碼庫上表現更佳

Hacker News·

與普遍觀念相反,AI輔助編碼在既有(棕地)程式碼庫上的表現優於全新(綠地)專案。現有程式碼能為AI提供學習的模式和範例,帶來更一致且架構良好的開發,而空白畫布則會導致程式碼碎片化。

Image

Why AI works better on existing codebases

The common belief is that AI-assisted coding works best on greenfield projects. My experience says otherwise.

There's a common belief that AI-assisted coding works best on greenfield projects. Start fresh, let the AI generate everything from scratch, avoid the baggage of legacy code.

My experience says otherwise. After a year of AI-assisted development, I've found that brownfield projects (established codebases) give AI a significant advantage over greenfield ones.

Image

The blank canvas problem

When you point AI at an empty repository, it has nothing to reference. No patterns to follow. No conventions to match. No examples to learn from.

The result: the AI invents patterns. And it invents different patterns for the same things in different places. One form uses React Hook Form with Zod. Another uses native form handling with manual validation. A third mixes both. Each file looks plausible in isolation, but the same capability is implemented three different ways.

You end up with a Frankenstein codebase. Technically functional, architecturally fragmented.

How codebase indexing works

Tools like Cursor don't just read your code. They index it into semantic embeddings. Functions, classes, and logical blocks get chunked and vectorized. When you ask for something, the tool searches by meaning, not just text matching.

More code means a richer index. The AI can find relevant patterns, understand how similar problems were solved before, and extend existing approaches consistently.

An empty repo gives the AI nothing to search. A populated codebase gives it a library of working examples.

What existing code provides

Brownfield projects give AI several advantages:

Working examples. The AI can see how you handle authentication, structure API responses, manage state, format errors. It doesn't have to guess. It has references.

Established conventions. Import paths, file naming, folder structure, code style. These patterns exist in the codebase. The AI picks them up and follows them.

Real implementations to extend. Adding a new feature that's similar to an existing one? The AI can find that similar feature and mirror its approach. Consistency comes naturally.

Context for decisions. The codebase reveals architectural choices. The AI understands that you use Server Actions for mutations, React Query for data fetching, Zod for validation. It doesn't suggest alternatives that don't fit.

The quality caveat

One important caveat: the existing codebase needs to be reasonably good quality.

AI uses your code as a reference. If the existing code is messy, inconsistent, or poorly structured, AI produces more of the same. It learns from what's there, good or bad.

This cuts both ways. A well-architected codebase compounds AI productivity. A poorly-architected one compounds technical debt.

Before leaning heavily on AI assistance, consider whether your codebase is a pattern you want replicated.

Making brownfield work

For established projects, take time to explain the architecture using rules (Cursor Rules, Claude Skills, Windsurf Rules, Copilot Instructions, whatever your tool calls them).

The codebase shows the AI what patterns exist. Rules tell it which patterns to prioritize and when to use each one.

Think of it this way: the codebase is the textbook. Rules are the study guide highlighting what matters.

Good rules for brownfield projects:

The combination of rich codebase context and explicit rules gives AI everything it needs to extend your system consistently. I wrote more about writing effective rules in a previous post.

Making greenfield work

If you're starting fresh, don't hand the blank canvas to AI immediately.

Build the first features manually. Create the folder structure, set up the core abstractions, implement a few representative features end-to-end. Even 10-20 well-structured files changes AI output dramatically compared to an empty repo.

Once you have working examples, write rules that capture what you built. Then let AI scale. New features follow established approaches. The codebase grows coherently.

When AI makes mistakes, improve your rules. Over time, mistakes decrease and velocity increases.

The counterintuitive truth

Starting with an existing codebase isn't a limitation for AI-assisted development. It's an advantage.

The baggage that slows down manual coding (understanding existing patterns, matching conventions, maintaining consistency) becomes an asset when AI can index and learn from it.

Greenfield freedom sounds appealing. But without constraints, AI produces chaos. Brownfield constraints guide AI toward coherence.

Go brown, not green, for AI.

Image

Written by

Roni Ström

Founder

More from the blog

From fragmented code to consistent output with AI rules

Most developers use AI without structured guidance. Here's how capability-specific rules change everything.

Image

Image

SaaS products and consulting services.

Quick Links

Products

© 2026 Ström Capital Oy. All rights reserved.

Business ID: 3466634-5 · E-invoice: 003734666345 · Operator: 003723327487 (APIX)

Hacker News

相關文章

  1. 透過AI規則,從零散程式碼邁向一致性輸出

    3 個月前

  2. 善用參考文檔工具與AI代理

    3 個月前

  3. 從AI程式碼輔助中獲益的團隊有何不同之處

    4 個月前

  4. 讓 AI 說其母語

    4 個月前

  5. 輕量級註解規範,強化人機協作程式碼開發

    3 個月前