Skip to main content
rule CX Codex

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

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/patterns-explicit-variants.md
Open on GitHub

What 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

  • Composer has grown isThread, isEditing and showAttachments. Split it into explicit variants following patterns-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.md

The paths frontmatter field limits the files

Step 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

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set130

The whole set →
server-cache-react server-cache-react instructs the assistant to deduplicate server-side operations with React.cache() and prevent cache misses from inline object arguments. CX Codex +1 ★ 7,191repo stars architecture-avoid-boolean-props The architecture-avoid-boolean-props rule keeps component variants out of boolean props and moves them into composition. Use it when conditional UI branches start spreading across a component. CX Codex +1 ★ 7,191repo stars rendering-hydration-no-flicker rendering-hydration-no-flicker prevents server render failures and interface flickering when displaying content tied to browser storage. CX Codex +1 ★ 7,191repo stars bundle-barrel-imports The bundle-barrel-imports rule steers imports away from barrel files and toward source modules. It helps when a package exposes many re-exports and slows loading. CX Codex +1 ★ 7,191repo stars async-suspense-boundaries async-suspense-boundaries guides Claude Code to place data fetching behind Suspense boundaries so headers, sidebars, and layout shells render without blocking. CX Codex +1 ★ 7,191repo stars architecture-compound-components The architecture-compound-components rule describes splitting complex UI components into pieces that share state through context. It fits components that have accumulated render props and conditional options. CX Codex +1 ★ 7,191repo stars state-decouple-implementation state-decouple-implementation — a Claude Code rule that keeps state management inside providers and exposes only a context interface to UI components. Swap useState for Zustand or a server sync without touching a single UI file. CX Codex +1 ★ 7,191repo stars rerender-functional-setstate The rerender-functional-setstate rule recommends functional state updates when the next React value depends on the current one. It helps callbacks avoid stale state and unnecessary dependencies. CX Codex +1 ★ 7,191repo stars

Project sponsors

Companies that keep this analytics open