Skip to main content
rule CX Codex

architecture-compound-components — Claude Code rule: purpose and setup

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.

MIT ★ 7,191 updated 2026-10-24

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

What architecture-compound-components does

The rule separates a complex component into a Provider, a frame, and smaller pieces such as an input, submit button, or footer. Each piece reads shared state and actions from context instead of receiving them through props. Consumers choose which pieces to compose, without hidden conditionals.

A parent Provider supplies state, actions, and metadata. The same component structure can then be used with different dependencies. The parts need a Provider supplying the shared values.

The example uses a Composer built with React and TypeScript: its input updates state through an action, while its submit button calls the submit action. To install the rule in Claude Code, add .claude/rules/architecture-compound-components.md to the project.

What it helps with

  • split a monolithic component into composable pieces
  • share component state through context
  • build an interface from selected pieces without hidden conditions
  • reuse a component structure with different dependencies

Example prompts for the agent

  • Refactor the Composer into smaller components that share state through context.
  • Replace the component's render callbacks and boolean options with a Provider, Frame, Input, and Footer.
  • Show how to pass state and actions through a Provider and compose a form from selected pieces.

How to install architecture-compound-components

Manually: put the files in place

.claude/rules/architecture-compound-components.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 architecture-compound-components

How do I install architecture-compound-components in Claude Code?

Add the rule at .claude/rules/architecture-compound-components.md.

What does architecture-compound-components do?

It recommends splitting complex components into pieces that access shared state through context. Consumers choose which pieces make up the interface.

How do the component pieces get state and actions?

A parent Provider supplies state, actions, and metadata through shared context. The pieces access that context rather than receiving those values as props.

Source text

architecture-compound-components.md · MIT
---
title: Use Compound Components
impact: HIGH
impactDescription: enables flexible composition without prop drilling
tags: composition, compound-components, architecture
---

## Use Compound Components

Structure complex components as compound components with a shared context. Each
subcomponent accesses shared state via context, not props. Consumers compose the
pieces they need.

**Incorrect (monolithic component with render props):**

```tsx
function Composer({
  renderHeader,
  renderFooter,
  renderActions,
  showAttachments,
  showFormatting,
  showEmojis,
}: Props) {
  return (
    <form>
      {renderHeader?.()}
      <Input />
      {showAttachments && <Attachments />}
      {renderFooter ? (
        renderFooter()
      ) : (
        <Footer>
          {showFormatting && <Formatting />}
          {showEmojis && <Emojis />}
          {renderActions?.()}
        </Footer>
      )}
    </form>
  )
}
```

**Correct (compound components with shared context):**

```tsx
const ComposerContext = createContext<ComposerContextValue | null>(null)

function ComposerProvider({ children, state, actions, meta }: ProviderProps) {
  return (
    <ComposerContext value={{ state, actions, meta }}>
      {children}
    </ComposerContext>
  )
}

function ComposerFrame({ children }: { children: React.ReactNode }) {
  return <form>{children}</form>
}

function ComposerInput() {
  const {
    state,
    actions: { update },
    meta: { inputRef },
  } = use(ComposerContext)
  return (
    <TextInput
      ref={inputRef}
      value={state.input}
      onChangeText={(text) => update((s) => ({ ...s, input: text }))}
    />
  )
}

function ComposerSubmit() {
  const {
    actions: { submit },
  } = use(ComposerContext)
  return <Button onPress={submit}>Send</Button>
}

// Export as compound component
const Composer = {
  Provider: ComposerProvider,
  Frame: ComposerFrame,
  Input: ComposerInput,
  Submit: ComposerSubmit,
  Header: ComposerHeader,
  Footer: ComposerFooter,
  Attachments: ComposerAttachments,
  Formatting: ComposerFormatting,
  Emojis: ComposerEmojis,
}
```

**Usage:**

```tsx
<Composer.Provider state={state} actions={actions} meta={meta}>
  <Composer.Frame>
    <Composer.Header />
    <Composer.Input />
    <Composer.Footer>
      <Composer.Formatting />
      <Composer.Submit />
    </Composer.Footer>
  </Composer.Frame>
</Composer.Provider>
```

Consumers explicitly compose exactly what they need. No hidden conditionals. And the state, actions and meta are dependency-injected by a parent provider, allowing multiple usages of the same component structure.

© tech-leads-club · MIT · tech-leads-club/agent-skills

Similar IDE rules

All IDE rules for Frontend and UI →
design-system-compound-components alexj11324 design-system-compound-components is a Claude Code rule that forbids raw string children in non-text components. It enforces compound structures like ButtonText and ButtonIcon across the design system. CX Codex +1 ★ 88repo stars compound-pattern patterns.dev compound-pattern teaches the agent the compound component pattern for shared implicit state. Useful for tabs, accordions and dropdowns whose parts must coordinate without explicit props. CX Codex +1 1,100installs sort-components rerun-build The sort-components Claude Code skill sorts UI components into folders by feature. It activates when adding a component or reorganizing apps/ui/components/. CX Codex +1 ★ 1,120repo stars components-build components.build components-build is a Claude Code skill for building, reviewing, and refactoring reusable React components with the components.build specification. It activates for work on component APIs, accessibility, styling, and TypeScript props. CX Codex +1 ★ 141repo stars react-component-architecture aj-geddes react-component-architecture — a skill that tells your coding agent how to structure React components: function components, hooks, composition and TypeScript. Useful once a shared component library starts growing. CX Codex +1 687installs building-components vercel building-components is a Claude Code skill for designing accessible UI components, composable APIs, design tokens, and documentation. CX Codex +1 15,400installs

From the same set130

The whole set →
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 patterns-explicit-variants 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. 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 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 state-lift-state state-lift-state — a Claude Code rule that moves React state into a provider component, so siblings outside the main UI read and update it without prop drilling or refs. CX Codex +1 ★ 7,191repo stars js-batch-dom-css js-batch-dom-css prevents layout thrashing by separating style updates from layout queries. Helps Claude write performant DOM and React code. CX Codex +1 ★ 7,191repo stars

Project sponsors

Companies that keep this analytics open