Skip to content
gentic.news — AI News Intelligence Platform
Connecting to the Living Graph…

Listen to today's AI briefing

Daily podcast — 5 min, AI-narrated summary of top stories

Developer typing code in an IDE with a CLAUDE.md file open, showing architecture rules for an AI assistant, while a…
AI ResearchScore: 80

How to Build Architecture Guardrails in CLAUDE.md

Add a decision matrix to CLAUDE.md to stop Claude Code from mixing legacy and new architecture patterns during migrations. This technique from a 827-commit Flutter project cut migration time ~30%.

·10h ago·3 min read··3 views·AI-Generated·Report error
Share:
Source: dev.tovia devto_claudecodeCorroborated
How do I prevent Claude Code from mixing legacy and new architecture patterns during a codebase migration?

Add a decision matrix to your CLAUDE.md file that maps task intent (new feature, bug fix, migration) to the correct architecture pattern. This prevents the AI from mixing legacy and new patterns, a common source of production bugs.

TL;DR

A decision matrix in CLAUDE.md prevents Claude Code from 'improving' code it shouldn't touch, saving ~30% migration time.

Key Takeaways

  • Add a decision matrix to CLAUDE.md to stop Claude Code from mixing legacy and new architecture patterns during migrations.
  • This technique from a 827-commit Flutter project cut migration time ~30%.

What Changed — The Real Problem with AI-Assisted Migrations

When you ask Claude Code to fix a bug in legacy code, its default instinct is to "improve" it. It sees a try/catch block and wants to refactor it into a fancier error-handling pattern. That instinct is correct for new features — and catastrophic during a migration.

One developer documented this exact problem across 827 commits in a Flutter e-commerce app for a Swiss retailer. The app had an 85% crash-free rate and three different error handling styles. The fix wasn't a smarter model. It was a CLAUDE.md file with architecture guardrails.

What It Means For You — Decision Matrices Over Guidelines

Most CLAUDE.md files list architecture rules like "use Clean Architecture" or "prefer Riverpod for state management." That's not enough. The AI needs conditional logic — a decision matrix that tells it which pattern to use depending on what it's doing.

Here's the simplified decision matrix from that production project:

## Architecture

This project uses Clean Architecture with feature-first organization.

![Cover image for AI-Assisted Flutter Development: Claude Code in Production](https://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fkhal.it%2Fblog%2Fai-assisted-development-production-flutter.webp)


### Decision Matrix
- Touching existing unmigrated code? -> Follow legacy patterns
- Writing a new feature? -> Use Clean Architecture
- Migrating an existing feature? -> Follow migration checklist

### Error Handling
- New code: TaskEither<AppFailure, T> from fpdart
- Legacy code: existing try/catch (do NOT refactor)

### State Management
- New features: Riverpod with code generation
- AsyncNotifier for async state
- Do NOT use ChangeNotifier, StateNotifier, or Bloc

The key insight: the decision matrix is not documentation for humans. Humans have context from standups and PR reviews. This is documentation for the AI — explicit, unambiguous, with decision trees instead of guidelines.

Try It Now — Build Your Own Guardrails

Step 1: Map your codebase's architectural states

Identify every valid pattern currently in production. For the Flutter app, that meant:

  • Legacy code: try/catch, ChangeNotifier
  • New code: TaskEither, AsyncNotifier with Riverpod
  • Transition code: half-migrated features (follow migration checklist)

Step 2: Create custom skills for each mode

Custom skills are slash commands in Claude Code that override baseline context. Create three:

/migration — Enforces a strict sequence (domain layer first, then data, then presentation, then tests).

/legacy-code — "Follow existing patterns. Do not introduce Clean Architecture imports. Match the style of surrounding code."

/new-feature — "Use Clean Architecture with Riverpod and TaskEither. Follow the project's current conventions."

Step 3: Test with a real task

Ask Claude Code to fix a bug in legacy code without the guardrails. Then ask again with /legacy-code active. Compare the diffs. The second version should only touch the bug, not refactor surrounding code.

Why This Works — The Token Economics of Context

The AI's instinct to "improve" code comes from its training data, where writing clean code is rewarded. During a migration, "best code possible" is context-dependent. A bug fix in unmigrated code should follow legacy patterns. The same logic written during migration should follow the new architecture. No model training covers that distinction — it has to be configured per project.

The result from this production project: ~30% faster migration timeline. Not because the AI wrote perfect code, but because it handled the mechanical parts while the developer made decisions requiring judgment.


Source: dev.to

Source: gentic.news · · author= · citation.json

AI-assisted reporting. Generated by gentic.news from multiple verified sources, fact-checked against the Living Graph of 4,300+ entities. Edited by Ala SMITH.

Following this story?

Get a weekly digest with AI predictions, trends, and analysis — free.

AI Analysis

**What Claude Code users should do differently:** First, audit your existing `CLAUDE.md`. If it only lists rules without conditional logic, add a decision matrix that maps task types (bug fix, new feature, migration) to specific architecture patterns. This single change prevents the most common production issue with AI-assisted coding: pattern inconsistency. Second, create custom skills for each architectural mode in your codebase. The `/legacy-code` skill is the hardest to get right but delivers the most value. It overrides the AI's default "improve everything" behavior. Test it by asking for a bug fix in legacy code — the diff should only change the bug, not refactor surrounding code. Third, use the decision matrix pattern even on greenfield projects. As your codebase evolves, you'll have legacy code within months. Setting up guardrails early means you never have to retrain the AI's behavior mid-project.
This story is part of
Claude Code's Campus Conquest Flips Anthropic's Talent Pipeline, Leaving Google's Academic Edge in Doubt
Viral adoption at MIT and Stanford transforms Claude Code from product into recruiting funnel, threatening Google's long-held research talent dominance
Compare side-by-side
Claude Code vs Flutter
Enjoyed this article?
Share:

AI Toolslive

Five one-click lenses on this article. Cached for 24h.

Pick a tool above to generate an instant lens on this article.

Related Articles

From the lab

The framework underneath this story

Every article on this site sits on top of one engine and one framework — both built by the lab.

More in AI Research

View all