AI Code Smells
Typical antipatterns and markers of synthetic code ('code smells' from AI). Excessive obvious comments, utility duplication in every file, fake mocks, and nonsensical try-catch blocks that indicate unchecked generation.
1. Concept Overview & Systemic Problem
Any experienced Senior Engineer can, within 5 seconds during an interview or repository audit, say: “This code was written by someone who knows what they are doing, while this one was just blindly copied from a chatbot without any review.”
Artificial intelligence writes quickly, but it has specific manners and "bad habits" that are referred to in the industry as AI Code Smells.
Understanding these markers is essential for every newcomer: it will help you timely clean your project of synthetic debris and appear as a professional developer in the eyes of colleagues and clients.
2. Key Markers of AI-Generated Code
┌─────────────────────────────────────────────────────────────┐
│ TOP 4 AI CODE SMELLS │
├─────────────────────────────────────────────────────────────┤
│ 1. 📢 Obvious Captain Comments: │
│ // Assigning a value to variable a │
│ const a = 10; // This is the number ten │
├─────────────────────────────────────────────────────────────┤
│ 2. 🖨️ Utility Duplication in Every File: │
│ Instead of importing a common function `formatDate()`, │
│ AI copies the same function across 15 lines in 7 │
│ different components │
├─────────────────────────────────────────────────────────────┤
│ 3. 🙈 Empty Error Handling Blocks: │
│ try { doSomething(); } catch (e) { /* do nothing */ } │
│ (An error occurs, but you will never know about it) │
├─────────────────────────────────────────────────────────────┤
│ 4. 🤹 Overcomplicating Simple Tasks: │
│ Creating 3 classes, a factory, and an interface for │
│ a single mathematical operation of adding two numbers │
└─────────────────────────────────────────────────────────────┘
3. Transforming Synthetic Code into Professional Code
Compare the two code snippets:
❌ Before (Typical Raw AI Output):
// Function that checks the user
function checkUser(user: any) {
try {
// If the user exists
if (user != null) {
// Return true
return true;
}
} catch (err) {
console.log("Error");
}
return false;
}
✅ After (Cleaned Engineering Code):
export function isUserActive(user: User | null): boolean {
return Boolean(user?.isActive);
}
4. Project Cleanup Checklist Before Release
- Remove all obvious comments that repeat what is already stated in the variable name.
- Check types: replace all careless
anywith specific TypeScript types. - Extract repeated code snippets into a separate folder
src/liborsrc/utils. - Ensure that all error messages are actually logged and not hidden in empty
catchblocks.
5. Pitfalls, Common Mistakes & Security
- Overlooking AI Patterns: Failing to recognize AI Code Smells can lead to technical debt and maintenance challenges.
- Ignoring Code Reviews: Relying solely on AI-generated code without human review can introduce subtle bugs and architectural flaws.
- Neglecting Documentation: AI-generated code often lacks context; ensure that documentation is thorough to aid future developers.
FAQ: AI Code Smells
Related terms
Diff-First Mindset: The Art of Reviewing Changes
A fundamental paradigm shift for developers in the AI era (Diff-First Mindset). Transitioning from mechanical text entry to rapid visual assessment of red and green highlighted code changes (git diff) before approval.
AI as Code Reviewer (Bug Detection Before Release)
A methodology for utilizing language models as a stringent senior engineer for automated code audits (Code Review). It identifies hidden security vulnerabilities, memory leaks, and architectural bugs before the software rollout.
AI Slop: Codebase Contamination
A systemic phenomenon of codebase degradation due to the mass addition of low-quality, verbose, overly complex, or duplicated code generated by language models without architectural oversight.
Related Ecosystem Resources
Explore practical workflows, core terminology, and engineering tools
Continuous AI Refactoring
The practice of regular background updates to the codebase by autonomous AI agents: cleaning dead code, migrating outdated APIs, optimizing performance, and addressing technical debt.
AI Refactoring: Safely Refreshing Legacy Code Without Changing Its Logic
A methodology for improving the internal structure, readability, and performance of existing Legacy Code using language models without altering its external behavior. It enables breaking down large spaghetti functions into neat modules and converting old JavaScript to modern TypeScript.
Claude Code Projects: How a Single AI Orchestrates a Team of Autonomous Agents
A deep dive into Claude Code Projects: Coordinator and Threads architecture, parallel branches, shared memory via MEMORY.md, and cloud agent management.
15 Prompts for Creating Agents in Claude Code
Claude Code can work not only through the main dialogue but also via subagents — separate configurations with their own system prompt, a limited set of tools, and, if necessary, a...
Claude Code cuts background subagent status update costs by 99%
In the CLI version of Claude Code, status updates for background subagents now use Haiku 5.5 based on short notes, reducing limit consumption.
OpenCode claims 30x more DeepSeek usage for the same cost
OpenCode co-founder Dax said the team found a way to significantly improve DeepSeek usage efficiency, turning a $10 spend into what previously cost $300.