# Assigns Audit

Inspect LiveView socket assigns for memory bloat, missing temporary_assigns, unused...

- Repository: https://github.com/oliver-kriska/claude-elixir-phoenix (572 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-10-30
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add oliver-kriska/claude-elixir-phoenix --skill assigns-audit -g -a claude-code -y`
Codex: `npx skills add oliver-kriska/claude-elixir-phoenix --skill assigns-audit -g -a codex -y`
Cursor: `npx skills add oliver-kriska/claude-elixir-phoenix --skill assigns-audit -g -a cursor -y`
Gemini CLI: `npx skills add oliver-kriska/claude-elixir-phoenix --skill assigns-audit -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add oliver-kriska/claude-elixir-phoenix`

## Description

Inspect LiveView socket assigns for memory bloat, missing temporary_assigns, unused assigns, unbounded lists needing streams, memory estimates. Use when LiveView memory grows or you need to add temporary_assigns.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# LiveView Assigns Audit

Analyze LiveView socket assigns for memory efficiency, clarity, and best practices.

## Iron Laws - Never Violate These

1. **Use streams for lists > 100 items** - Never store large lists directly in assigns
2. **Use temporary_assigns for transient data** - Flash messages, temp errors, notifications
3. **Preload only needed fields** - Don't store full Ecto schemas when only needing subset
4. **Initialize all assigns in mount** - Never access assigns that might not exist
5. **NEVER modify assigns or code during audit**, this is a read-only diagnostic; report findings only

## Quick Audit Commands

### Extract All Assigns

Use Grep to find all `assign(` and `assign_new(` calls in the target LiveView file.

### Find Large Data Patterns

Use Grep to find large data patterns: lists stored in assigns (`assign.*\[\]`, `assign.*Repo\.all`) and full schema storage (`assign.*Repo\.get`) in the target file.

## Audit Checklist

### 1. Memory Issues

| Pattern | Problem | Solution |
|---------|---------|----------|
| `assign(:items, Repo.all(...))` | Unbounded list | Use `stream/3` |
| `assign(:user, Repo.get!(...))` | Full schema | Select only needed fields |
| `assign(:file_data, binary)` | Large binary | Store reference, not data |
| Nested preloads | Excessive data | Preload only what's rendered |

### 2. Missing temporary_assigns

Should use `temporary_assigns`:

- Flash messages
- Form errors after submission
- One-time notifications
- Upload progress

```elixir
def mount(_params, _session, socket) do
  {:ok, socket, temporary_assigns: [flash_message: nil]}
end
```

### 3. Unused Assigns

Search for assigns defined but never used in templates:

Use Grep to extract all assign names (`assign\(:(\w+)`) from the LiveView file, then use Grep to find all `@\w+` references in the corresponding `.heex` template. Compare to find unused assigns.

### 4. Missing Initialization

The rest: https://github.com/oliver-kriska/claude-elixir-phoenix/blob/HEAD/plugins/elixir-phoenix/skills/assigns-audit/SKILL.md
