Back to Guides
Problem-Solving

Stop Your AI from Writing Code You Have to Rewrite

The AI isn't bad at coding. It's bad at coding your way. Here's the system to fix that.

Last updated: 2026-07-01

What 'bad code' actually means for AI agents

AI-generated "bad code" is almost never syntactically wrong. It compiles. It runs. But it violates your team's conventions: wrong folder, wrong naming pattern, wrong export style, missing types, unnecessary any, default exports where named exports are required. These violations are invisible to the compiler but cause real pain in code review and maintenance.

The two-layer fix

Layer 1: Rules file (CLAUDE.md / .cursor/rules / AGENTS.md) -runs before code generation, tells the agent what your standards are. Layer 2: ESLint / TypeScript config -runs after code generation, catches violations the rules file missed. Both are necessary. The rules file reduces violations; the linter is the safety net. Most teams have Layer 2 but skip Layer 1.

The 20% of rules that fix 80% of the problems

Based on the most common AI coding anti-patterns: (1) Export style -named exports vs default exports. AI agents default to default exports; most modern React codebases prefer named. (2) any usage -AI reaches for any when types get complex. Explicit prohibition fixes this. (3) File placement -AI puts everything in obvious folders. Your feature-based structure requires explicit mapping. (4) Boolean naming -AI names booleans loading, error, open. You want isLoading, hasError, isOpen. (5) Null vs undefined -pick one and encode it.

Getting started

The fastest path: look at your last 5 code review comments where you corrected AI-generated code. Those are your highest-priority rules. Encode exactly those corrections into CLAUDE.md. Within a day, your most common violations disappear.

CLAUDE.md
# Project Rules

## Exports
- ALWAYS named exports: export function X() {}
- NEVER default exports for components or hooks.

## TypeScript  
- No `any`. Use `unknown` and narrow, or fix the type properly.
- No implicit any -tsconfig strict: true is non-negotiable.

## Booleans
- Name booleans with isX / hasX / canX / shouldX prefix.
  ✓ const isLoading = true
  ✗ const loading = true

## File Placement
- Components used in 1 place: colocate next to the feature.
- Components used in 2+ places: src/components/
- Never create pages/ -App Router project.

## Values
- Never use `null`. Only `undefined` for absent values.

Generate rules based on your stack in 3 minutes

standarx generates a rules file pre-loaded with the conventions that matter most for your specific framework, language, and libraries.

Generate my rules file