Skip to main content

AI Code Smells

FOR AI AGENTChatGPTClaude

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 any with specific TypeScript types.
  • Extract repeated code snippets into a separate folder src/lib or src/utils.
  • Ensure that all error messages are actually logged and not hidden in empty catch blocks.

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.
/ Frequently Asked QuestionsSchema.org FAQPage

FAQ: AI Code Smells

It is not necessarily an error that breaks the program right now. It is a marker of poor architecture or negligence that indicates the code was written hastily and will inevitably create a multitude of bugs as the project evolves.
/ Internal links
All terms

Related Ecosystem Resources

Explore practical workflows, core terminology, and engineering tools

Glossary Concept

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.

Glossary Concept

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.

Practical Guide

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.

Practical Guide

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...

News

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.

News

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.