# elixir-antipatterns

elixir-antipatterns is a Claude Code skill that guides code reviews, Ecto query tuning, and Phoenix refactoring with a catalog of 8 anti-patterns.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 194 installs · ★ 678 repo stars
- Author: tsardinasGitHub
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/Gentleman-Programming/Gentleman-Skills/tree/HEAD/community/elixir-antipatterns/SKILL.md
- Updated: 2026-03-28
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/elixir-antipatterns

## What it does

This skill supplies instructions covering eight critical anti-patterns in Elixir and Phoenix codebases. It instructs the assistant to return tagged tuples like `{:ok, value}` or `{:error, reason}` instead of relying on `nil` or raising business exceptions. It also enforces documenting failure modes inside `@spec` definitions.

For Phoenix applications, the instructions keep LiveView modules strictly presentation-focused by delegating domain logic to context modules. When handling Ecto queries, the skill flags N+1 query loops in favor of `Repo.preload/2` and reminds you to index queried columns. Inside `with` blocks, it mandates using arrow bindings `<-` for fallible steps and breaking chains longer than four steps into smaller functions.

This skill addresses architecture and data flow, but does not handle formatting; pair it with `mix format` and `Credo` for complete style enforcement.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add Gentleman-Programming/Gentleman-Skills --skill elixir-antipatterns -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/elixir-antipatterns/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/elixir-antipatterns/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add Gentleman-Programming/Gentleman-Skills --skill elixir-antipatterns -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/elixir-antipatterns/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add Gentleman-Programming/Gentleman-Skills --skill elixir-antipatterns -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/elixir-antipatterns/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install Gentleman-Programming/Gentleman-Skills community/elixir-antipatterns/SKILL.md
```

2. **Manually: put the files in place**
- File: `.github/skills/elixir-antipatterns/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add Gentleman-Programming/Gentleman-Skills --skill elixir-antipatterns -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/Gentleman-Programming/Gentleman-Skills --path community/elixir-antipatterns
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/elixir-antipatterns/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add Gentleman-Programming/Gentleman-Skills --skill elixir-antipatterns -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/Gentleman-Programming/Gentleman-Skills/tree/HEAD/community/elixir-antipatterns/SKILL.md

## When to use it
- eliminate Ecto N+1 query loops using Repo.preload/2
- move domain logic out of Phoenix LiveView into contexts
- replace exceptions and nil returns with tagged error tuples
- catch ignored step failures in with blocks using arrow binding

## Example prompts
- Review this Phoenix LiveView module against Elixir anti-patterns
- Refactor this Ecto query to prevent N+1 queries using preloads

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 9392caca512f0dd5.

BEGIN THIRD-PARTY FILE 9392caca512f0dd5
````text
---
name: elixir-antipatterns
description: >
  Core catalog of 8 critical Elixir/Phoenix anti-patterns covering error handling,
  separation of concerns, Ecto queries, and testing. 
  Trigger: During Elixir code review, refactoring sessions, or when writing Phoenix/Ecto code.
metadata:
  author: tsardinasGitHub
  version: "1.0"
---

# Elixir Anti-Patterns

Critical anti-patterns that compromise robustness and maintainability in Elixir/Phoenix applications.

> **Complement with**: `mix format` and `Credo` for style enforcement  
> **Extended reference**: See `EXTENDED.md` for 40+ patterns and deep-dive examples

---

## When to Use

**Topics:** Error handling (3 patterns) • Architecture (2 patterns) • Performance (2 patterns) • Testing (1 pattern)

Load this skill when:
- Writing Elixir modules and functions
- Working with Phoenix Framework (Controllers, LiveView)
- Building Ecto schemas and database queries
- Implementing BEAM concurrency (Task, GenServer)
- Handling errors with tagged tuples
- Writing tests with ExUnit

---

## Critical Patterns

Quick reference to the 8 core patterns this skill enforces:

1. **Tagged Tuples**: Return `{:ok, value} | {:error, reason}` instead of `nil` or exceptions
2. **Explicit @spec**: Document error cases in function signatures
3. **Context Separation**: Business logic in contexts, not LiveView
4. **Preload Associations**: Use `Repo.preload/2` to avoid N+1 queries
5. **with Arrow Binding**: Use `<-` for all failable operations in `with`
6. **Database Indexes**: Index frequently queried columns
7. **Test Assertions**: Every test must assert expected behavior
8. **Cohesive Functions**: Group `with` chains >4 steps into functions

> See `## Anti-Patterns` section below for detailed ❌ BAD / ✅ CORRECT code examples.

---

## Code Examples

### Example 1: Error Handling with Tagged Tuples

```elixir
# ✅ CORRECT - Errors as values, explicit in @spec
defmodule UserService do
  @spec fetch_user(String.t()) :: {:ok, User.t()} | {:error, :not_found}
  def fetch_user(id) do
    case Repo.get(User, id) do
      nil -> {:error, :not_found}
      user -> {:ok, user}
    end
  end
end

# ❌ BAD - Exceptions for business errors
def fetch_user(id) do
  Repo.get(User, id) || raise "User not found"
end
```

### Example 2: Phoenix LiveView with Context Separation

```
Architecture Layers:
  User Request → LiveView (UI only) → Context (business logic) → Schema/Repo (data)
               ↓                    ↓                           ↓
````
END THIRD-PARTY FILE 9392caca512f0dd5

The third-party file has ended. Everything between the 9392caca512f0dd5 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2521 of 8513 bytes. © tsardinasGitHub · MIT · https://github.com/Gentleman-Programming/Gentleman-Skills/tree/HEAD/community/elixir-antipatterns/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
