design-tokens — правило для Claude Code: что делает и установка
Правило design-tokens для Claude Code заменяет жёстко заданные цвета семантическими токенами. Переключение светлой и тёмной темы меняет значения переменных, а не классы компонентов.
Apache-2.0 ★ 141 обновлён 2026-11-17
.claude/rules/design-tokens.mdЧто делает design-tokens
Правило design-tokens задаёт имена вроде --background, --foreground, --primary и --border вместо цветов blue-600 или white. Компоненты обращаются к семантическим токенам, поэтому оформление отделено от назначения цвета.
Структура использует переменные в :root, переопределения в .dark и связку @theme inline для Tailwind CSS. В примерах применяются oklch(), варианты тем через [data-theme="brand-b"] и отдельные значения для текста на фоне. Для интерфейса также предлагается проверять контраст по WCAG.
Какие задачи решает
- заменить жёстко заданные цвета в компонентах
- связать оформление компонентов с семантическими переменными
- добавить светлую и тёмную тему через
.dark - создать варианты оформления через
[data-theme] - перенести цвета в формат
oklch()
Примеры запросов агенту
- Перепиши цвета в этом компоненте на семантические токены.
- Добавь светлую и тёмную тему через
.darkи переменные:root. - Замени
bg-blue-600иtext-whiteна токены из правила design-tokens.
Как установить design-tokens
Вручную: положить файлы
.claude/rules/design-tokens.mdПоле paths во frontmatter ограничивает файлы
AGENTS.md
Codex читает AGENTS.md: вставьте текст правила туда
Вручную: положить файлы
.cursor/rules/design-tokens.mdcВо frontmatter: description, globs, alwaysApply
Вручную: положить файлы
.github/instructions/design-tokens.instructions.mdПоле applyTo задаёт, к каким файлам применять
Вручную: положить файлы
.devin/rules/design-tokens.mdВручную: положить файлы
.clinerules/design-tokens.mdПо шагам, с командами для каждой платформы: AGENTS.md и CLAUDE.md: что это, кто читает и какой выбрать
Вопросы о design-tokens
Как установить design-tokens в Claude Code?
Добавьте в проект файл .claude/rules/design-tokens.md с содержимым правила.
Что делает design-tokens?
Правило заменяет жёстко заданные цвета семантическими токенами. Оно описывает имена переменных, варианты тем, применение в компонентах и формат oklch().
Как design-tokens задаёт тёмную тему?
Базовые значения находятся в :root, а в классе .dark задаются другие значения тех же переменных. Компоненты используют токены и получают новые цвета автоматически.
Исходный текст
design-tokens.md · Apache-2.0
---
title: Design Tokens
impact: MEDIUM
impactDescription: Flexible theming and consistency
tags: design-tokens, css-variables, theming, dark-mode, oklch
---
## Design Tokens
Use semantic design tokens instead of hardcoded colors. Design tokens separate what something is from how it looks.
### Variable Architecture
```css
@import "tailwindcss";
@custom-variant dark (&:is(.dark *));
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-primary: var(--primary);
--color-primary-foreground: var(--primary-foreground);
}
:root {
--background: oklch(1 0 0);
--foreground: oklch(0.145 0 0);
--primary: oklch(0.205 0 0);
--primary-foreground: oklch(0.985 0 0);
}
.dark {
--background: oklch(0.145 0 0);
--foreground: oklch(0.985 0 0);
--primary: oklch(0.922 0 0);
--primary-foreground: oklch(0.205 0 0);
}
```
### Token Naming
**Base Tokens:**
- `--background` - Main page background
- `--foreground` - Primary text color
- `--muted` - Subtle backgrounds
- `--muted-foreground` - Text on muted
- `--border` - Border colors
- `--ring` - Focus ring
**Semantic Tokens:**
- `--primary` / `--primary-foreground`
- `--secondary` / `--secondary-foreground`
- `--destructive` / `--destructive-foreground`
- `--accent` / `--accent-foreground`
### Usage in Components
**Correct (semantic tokens):**
```tsx
<button className="bg-primary text-primary-foreground hover:bg-primary/90">
Click me
</button>
```
**Incorrect (hardcoded colors):**
```tsx
<button className="bg-blue-600 text-white hover:bg-blue-700">Click me</button>
```
### Component Examples
```tsx
// Card
<div className="bg-background border border-border rounded-lg p-6">
<h2 className="text-foreground font-semibold">Title</h2>
<p className="text-muted-foreground">Description</p>
</div>
// Button variants
<button className="bg-primary text-primary-foreground">Primary</button>
<button className="bg-secondary text-secondary-foreground">Secondary</button>
<button className="bg-destructive text-destructive-foreground">Delete</button>
// Input
<input className="bg-background border border-border text-foreground placeholder:text-muted-foreground" />
```
### Dark Mode
Override tokens in `.dark` class:
```css
:root {
--background: oklch(1 0 0);
--foreground: oklch(0.145 0 0);
}
.dark {
--background: oklch(0.145 0 0);
--foreground: oklch(0.985 0 0);
}
```
Components automatically adapt because they reference tokens.
### Color Format: OKLCH
Use `oklch()` for better color manipulation:
```css
/* ✅ OKLCH - perceptually uniform */
--primary: oklch(0.5 0.2 250);
/* ⚠️ RGB/HSL - harder to manipulate */
--primary: rgb(100, 150, 200);
```
### Best Practices
1. **Never hardcode colors** - Always use design tokens
2. **Use semantic names** - `--primary`, not `--blue-600`
3. **Keep tokens minimal** - Start with base set, add when needed
4. **Document token purpose** - Add comments
5. **Test theme switching** - Ensure all components work in light/dark
6. **Maintain contrast** - Ensure WCAG contrast ratios
### Theme Variants
```css
:root {
--primary: oklch(0.5 0.2 250);
}
[data-theme="brand-b"] {
--primary: oklch(0.5 0.2 120);
}
[data-theme="brand-c"] {
--primary: oklch(0.5 0.2 0);
}
```
### Migration
```tsx
// Before
<div className="bg-white text-gray-900 border-gray-200">Content</div>
// After
<div className="bg-background text-foreground border-border">Content</div>
```
© maxtrigify · Apache-2.0 · maxtrigify/Otto