patterns-explicit-variants — Claude Code rule
patterns-explicit-variants — a rule that pushes one component per mode instead of a single component buried under boolean props. The call site then says what renders.
MIT ★ 7,191 updated 2026-10-24
.claude/rules/patterns-explicit-variants.mdWhat patterns-explicit-variants does
The rule goes after components that branch on flags. Rather than letting isThread, isEditing and showAttachments pile up on one Composer, it asks for ThreadComposer, EditMessageComposer and ForwardMessageComposer as separate pieces. Each one spells out its own case.
Shared parts still get reused. A variant wraps its provider and builds the body from Composer.Frame, Composer.Input and Composer.Footer, adding the fields and buttons that case needs. Reading the file tells you which state it relies on, what it draws and which actions it exposes. Impossible states go away because there is no prop matrix left to get wrong.
It ships as a markdown file at .claude/rules/patterns-explicit-variants.md. Nothing enforces it at build time, so the model has to actually read it in context. Components that already carry a dozen flags will not rewrite themselves; that work stays manual.
What it helps with
- split a flag-heavy component into one piece per mode
- drop boolean props that hide what the component renders
- reuse shared layout between variants
- get rid of unreachable UI states
- read a component call and know its state and actions
Example prompts for the agent
Composerhas grownisThread,isEditingandshowAttachments. Split it into explicit variants followingpatterns-explicit-variants.- Build separate components for thread, edit and forward, and share the frame and footer parts.
- Check the new components for leftover booleans that switch modes.
How to install patterns-explicit-variants
Manually: put the files in place
.claude/rules/patterns-explicit-variants.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/patterns-explicit-variants.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/patterns-explicit-variants.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/patterns-explicit-variants.mdManually: put the files in place
.clinerules/patterns-explicit-variants.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about patterns-explicit-variants
How to install patterns-explicit-variants in Claude Code?
Place the rule file in your project at .claude/rules/patterns-explicit-variants.md.
What does patterns-explicit-variants do?
It turns a single component with many boolean props into separate variant components that each compose the parts they need.
What makes a variant different from a component with flags?
Each variant declares its provider, the UI it includes and the actions it offers. There are no flag combinations to reason about.
Source text
patterns-explicit-variants.md · MIT
---
title: Create Explicit Component Variants
impact: MEDIUM
impactDescription: self-documenting code, no hidden conditionals
tags: composition, variants, architecture
---
## Create Explicit Component Variants
Instead of one component with many boolean props, create explicit variant
components. Each variant composes the pieces it needs. The code documents
itself.
**Incorrect (one component, many modes):**
```tsx
// What does this component actually render?
<Composer
isThread
isEditing={false}
channelId='abc'
showAttachments
showFormatting={false}
/>
```
**Correct (explicit variants):**
```tsx
// Immediately clear what this renders
<ThreadComposer channelId="abc" />
// Or
<EditMessageComposer messageId="xyz" />
// Or
<ForwardMessageComposer messageId="123" />
```
Each implementation is unique, explicit and self-contained. Yet they can each
use shared parts.
**Implementation:**
```tsx
function ThreadComposer({ channelId }: { channelId: string }) {
return (
<ThreadProvider channelId={channelId}>
<Composer.Frame>
<Composer.Input />
<AlsoSendToChannelField channelId={channelId} />
<Composer.Footer>
<Composer.Formatting />
<Composer.Emojis />
<Composer.Submit />
</Composer.Footer>
</Composer.Frame>
</ThreadProvider>
)
}
function EditMessageComposer({ messageId }: { messageId: string }) {
return (
<EditMessageProvider messageId={messageId}>
<Composer.Frame>
<Composer.Input />
<Composer.Footer>
<Composer.Formatting />
<Composer.Emojis />
<Composer.CancelEdit />
<Composer.SaveEdit />
</Composer.Footer>
</Composer.Frame>
</EditMessageProvider>
)
}
function ForwardMessageComposer({ messageId }: { messageId: string }) {
return (
<ForwardMessageProvider messageId={messageId}>
<Composer.Frame>
<Composer.Input placeholder="Add a message, if you'd like." />
<Composer.Footer>
<Composer.Formatting />
<Composer.Emojis />
<Composer.Mentions />
</Composer.Footer>
</Composer.Frame>
</ForwardMessageProvider>
)
}
```
Each variant is explicit about:
- What provider/state it uses
- What UI elements it includes
- What actions are available
No boolean prop combinations to reason about. No impossible states.
© tech-leads-club · MIT · tech-leads-club/agent-skills