Code Smells in AI-Generated Code: 7 Signals to Stop and Rewrite
AI-written code that runs isn't necessarily good code. This guide covers 7 smells specific to generated code — defensive overkill, apologetic comments, ghost abstractions, and more — each with detection tips and fixes, so you catch them before they fossilize.

Running and well-written are two different things
AI-generated code has a signature trait: it looks fine on first read and becomes a minefield in three months. AI optimizes for "passing right now," not "maintainable long-term." The 7 smells below are the most common in AI code — smell any of them and it's worth stopping to fix. Earlier is cheaper.
1. Defensive overkill: try/catch as cure-all
AI loves wrapping every function in try/catch, then just logging inside the catch. Result: errors get swallowed, and when production breaks you can't even find a stack trace. Fix: delete the "just in case" catches; handle exceptions centrally at boundaries (API entry points, queue consumers).
2. Apologetic comments: code explaining why it's bad
"Using a trick here, temporary" / "TODO: optimize later" — when AI writes comments like these, it knows the code is questionable and chose to paper over it. Don't let them slide: fix it now or convert it into a tracked issue. A TODO in a comment that survives a week is effectively permanent.
3. Ghost abstractions: 'generic' designs used exactly once
AI loves premature abstraction: an interface with one implementation, a factory called from one place, ten config fields reserved "for the future." YAGNI applies hard here: delete every abstraction with no second use case today; add it back when actually needed — when you'll understand the requirements better anyway.
4. Copy-paste variants: three functions 90% identical
Ask AI to "write a similar one" and the laziest move is duplicating with two lines changed. In three months a logic change means editing three places — and you'll miss one. Fix: extract a parameterized single function, or at least have AI run a "duplication check" on its own output.
5. Type gymnastics: the great any escape in TypeScript
Faced with complex types, AI's first instinct is as any — "make it run first." Once any gets in, the type system goes blind there and all future refactors rely on eyeballs. Fix: treat any as a compile error — every any needs a comment explaining why it's temporarily bypassed and when the real type lands.
6. Config explosion: the env file is longer than the code
AI tends to make everything configurable: thresholds, flags, strategies all stuffed into environment variables. At deploy time nobody knows which are required or what the defaults are. Fix: separate "only known at deploy time" (secrets, URLs) from "fine as constants" (retry counts, timeouts) — hardcode the latter.
7. Theatrical tests: assertTrue(true)
The most dangerous one. AI-written tests often cover only the happy path, assert vaguely, or mock the very thing under test — all green, all wrong. Fix: for every PR, make AI answer three questions — what does this test verify? If I break the implementation, does the test go red? Are edge cases covered? Can't answer? Rewrite the tests.
The one-line summary
AI writes code 10x your speed — and manufactures technical debt at 10x too. Build the habit: every time AI hands you code, scan this list. Five minutes now saves a lost weekend three months later.
Comments (0)
Related articles
OpenSSH 9.6p1, zero packages: ed25519 256-bit + RSA 4096-bit keys, private 600, public 644, 1 identity in the agent, config resolving to deploy@192.0.2.10:2222. ssh-copy-id and real login not verified here — no sshd on this machine.
tmux 3.4, zero packages: 1 session, 2 windows, 3 panes; the logs window prints 1 to 5, editor panes report ready. Detach with Ctrl-b d, reattach with tmux attach — the session outlives the connection. Mouse, prefix key and history limit in ~/.tmux.conf included.
GCC 13.3.0, C17, zero packages: a first C program, sizeof results 1/2/4/8/8/4/8/8, sum 1..100 is 5050, 10! is 3628800, 8 numbers sorted, 3 books total 1088 pages, 3 file lines and 70 chars read back. Preprocessing alone expands 3 lines to 815.