state-ground-truth — правило для Claude Code: состояние, а не визуал
Правило state-ground-truth, которое запрещает хранить в состоянии производные визуальные значения. Учит агента разделять факт и его отображение.
MIT ★ 1 216 обновлён 2026-10-24
/plugin marketplace add fcakyon/claude-codex-settings
/plugin install react-skills@claude-settingsЧто делает state-ground-truth
Правило state-ground-truth заставляет агента хранить в useState и Reanimated shared values только фактическое состояние: нажато, открыто, прогресс. Визуальные значения — scale, opacity, translateY — должны вычисляться из этого состояния через интерполяцию или простое выражение.
Пример из правила: вместо scale = 0.95 при нажатии храним pressed = 1, а масштаб получаем через interpolate(pressed.get(), [0, 1], [1, 0.95]). Для React то же самое: height = isExpanded ? 200 : 0 вместо хранения height в отдельном useState и синхронизации через useEffect.
Аргументы правила: один источник правды упрощает отладку — pressed = 1 понятнее, чем scale = 0.95. Расширять анимацию проще: opacity, rotation и другие эффекты берутся из того же состояния. Установка через маркетплейс: сначала /plugin marketplace add fcakyon/claude-codex-settings, потом /plugin install react-skills@claude-settings, файл правила — .claude/rules/state-ground-truth.md.
Какие задачи решает
- Разделить фактическое состояние и производный визуал
- Убрать лишние
useEffectдля синхронизации значений - Упростить добавление новых анимаций к существующему состоянию
- Сделать отладку состояний понятнее через осмысленные имена
Примеры запросов агенту
- Проверь этот компонент: состояние должно отражать факт, а не визуал
- Перепиши анимацию нажатия, чтобы хранить
pressed, а неscale - Найди места, где
useStateхранит производные значения, и упрости их
Как установить state-ground-truth
1Через маркетплейс плагинов
/plugin marketplace add fcakyon/claude-codex-settings/plugin install react-skills@claude-settings2Вручную: положить файлы
.claude/rules/state-ground-truth.mdПоле paths во frontmatter ограничивает файлы
AGENTS.md
Codex читает AGENTS.md: вставьте текст правила туда
Вручную: положить файлы
.cursor/rules/state-ground-truth.mdcВо frontmatter: description, globs, alwaysApply
Вручную: положить файлы
.github/instructions/state-ground-truth.instructions.mdПоле applyTo задаёт, к каким файлам применять
Вручную: положить файлы
.devin/rules/state-ground-truth.mdВручную: положить файлы
.clinerules/state-ground-truth.mdПо шагам, с командами для каждой платформы: AGENTS.md и CLAUDE.md: что это, кто читает и какой выбрать
Вопросы о state-ground-truth
Как установить state-ground-truth в Claude Code?
Выполните /plugin marketplace add fcakyon/claude-codex-settings, затем /plugin install react-skills@claude-settings. Правило появится в .claude/rules/state-ground-truth.md.
Что делает правило state-ground-truth?
Оно требует, чтобы useState и Reanimated shared values хранили только фактическое состояние — pressed, progress, isOpen. Визуальные значения вроде scale или opacity должны вычисляться из состояния через интерполяцию.
Применяется ли правило к обычному React без Reanimated?
Да. В правиле есть пример с React: вместо хранения height в отдельном useState и обновления через useEffect, значение вычисляется напрямую из isExpanded.
Исходный текст
state-ground-truth.md · MIT
---
title: State Must Represent Ground Truth
impact: HIGH
impactDescription: cleaner logic, easier debugging, single source of truth
tags: state, derived-state, reanimated, hooks
---
## State Must Represent Ground Truth
State variables—both React `useState` and Reanimated shared values—should
represent the actual state of something (e.g., `pressed`, `progress`, `isOpen`),
not derived visual values (e.g., `scale`, `opacity`, `translateY`). Derive
visual values from state using computation or interpolation.
**Incorrect (storing the visual output):**
```tsx
const scale = useSharedValue(1)
const tap = Gesture.Tap()
.onBegin(() => {
scale.set(withTiming(0.95))
})
.onFinalize(() => {
scale.set(withTiming(1))
})
const animatedStyle = useAnimatedStyle(() => ({
transform: [{ scale: scale.get() }],
}))
```
**Correct (storing the state, deriving the visual):**
```tsx
const pressed = useSharedValue(0) // 0 = not pressed, 1 = pressed
const tap = Gesture.Tap()
.onBegin(() => {
pressed.set(withTiming(1))
})
.onFinalize(() => {
pressed.set(withTiming(0))
})
const animatedStyle = useAnimatedStyle(() => ({
transform: [{ scale: interpolate(pressed.get(), [0, 1], [1, 0.95]) }],
}))
```
**Why this matters:**
State variables should represent real "state", not necessarily a desired end
result.
1. **Single source of truth** — The state (`pressed`) describes what's
happening; visuals are derived
2. **Easier to extend** — Adding opacity, rotation, or other effects just
requires more interpolations from the same state
3. **Debugging** — Inspecting `pressed = 1` is clearer than `scale = 0.95`
4. **Reusable logic** — The same `pressed` value can drive multiple visual
properties
**Same principle for React state:**
```tsx
// Incorrect: storing derived values
const [isExpanded, setIsExpanded] = useState(false)
const [height, setHeight] = useState(0)
useEffect(() => {
setHeight(isExpanded ? 200 : 0)
}, [isExpanded])
// Correct: derive from state
const [isExpanded, setIsExpanded] = useState(false)
const height = isExpanded ? 200 : 0
```
State is the minimal truth. Everything else is derived.
© fcakyon · MIT · fcakyon/claude-codex-settings