What goes where
A coding agent reads instructions from a handful of files. Putting the right rule in the right file is most of the work, because rules in the wrong place are either ignored or loaded on every request and crowd out the code.
| File | Read by | Put here |
|---|---|---|
CLAUDE.md | Claude Code, at the start of every session | Project facts, commands, hard rules. Keep it under about 150 lines |
.cursor/rules/*.mdc | Cursor (current format: one rule per file, with front matter) | Scoped rules that attach by file glob, such as SwiftUI rules for **/*.swift |
.cursorrules | Cursor (legacy single file, still read) | The same content, if you want one file |
AGENTS.md | Codex and several other agents | A copy of, or pointer to, CLAUDE.md |
DESIGN.md | Any agent you point at it | The visual system: tokens, type scale, spacing, component rules |
.claude/settings.json, .cursor/hooks.json | The harness, not the model | Hooks that run commands, such as a pre-submission scan |
Two principles shape the pack below. Write rules as checks an agent can verify ("no literal colors in views"), not as taste ("make it beautiful"). And keep visual decisions out of the rules file: they live in DESIGN.md, where they can be swapped without touching architecture rules.
CLAUDE.md for a SwiftUI app
Copy this into the repository root and replace the bracketed parts.
# [App Name]
iOS app in SwiftUI. Minimum target iOS 17. Swift 6, strict concurrency.
## Commands
- Build: `xcodebuild -scheme [Scheme] -destination 'platform=iOS Simulator,name=iPhone 16' build`
- Test: `xcodebuild -scheme [Scheme] -destination 'platform=iOS Simulator,name=iPhone 16' test`
- Preflight: `stringer-preflight .` (must print CLEAR or WARN before any archive)
## Architecture
- Feature folders: `Features/<Name>/{<Name>View.swift, <Name>Model.swift}`.
- State: `@Observable` models owned with `@State`; pass down with `@Bindable` or the environment.
Do not add ObservableObject, @Published or Combine to new code.
- Navigation: one `NavigationStack` per tab with a typed `enum Route: Hashable`.
- Persistence: SwiftData. Network: `URLSession` with async/await. No third-party
networking or state libraries without asking first.
- Views are small: extract a subview when `body` passes about 40 lines.
## Design (read DESIGN.md before any UI work)
- Every color, font size, radius and spacing value comes from `Theme.swift`,
which mirrors DESIGN.md. No literal hex values, `.blue`, or magic numbers in views.
- Support light and dark, and Dynamic Type up to accessibility sizes.
- Never add: purple-to-blue gradients, glassmorphism on everything, emoji as icons,
a card around every element, centered body text. Use SF Symbols for icons.
- Every tappable element is at least 44x44 pt and has an accessibility label.
## Motion
- Use spring animations (`.snappy`, `.smooth`, or an explicit `spring(duration:bounce:)`).
- Animate transforms and opacity. Do not animate layout inside lists.
- Respect `accessibilityReduceMotion`.
## App Store rules (do not break these)
- Purchases use StoreKit 2. Paywalls show the billed price, renewal terms,
Terms and Privacy links, and Restore Purchases.
- Any account creation ships with in-app account deletion.
- Every permission has a specific purpose string in Info.plist before the API is called.
- Data sent to an AI provider needs a disclosure and consent screen first.
- No `localhost`, staging hosts, API secrets, "Lorem ipsum" or bypass flags
outside `#if DEBUG`.
## Working agreement
- Make the smallest change that solves the task. Do not rename, reformat or
delete unrelated code.
- Build after every change and fix warnings you introduced.
- Ask before adding a dependency, a new target or a new permission.Cursor rules: the current format and the legacy file
Cursor now reads project rules from .cursor/rules/, one .mdc file per rule, each with front matter that says when it applies. Scoping keeps Swift rules out of the context when the agent is editing a JSON file.
.cursor/rules/swiftui.mdc:
---
description: SwiftUI architecture and style rules for this app
globs: **/*.swift
alwaysApply: false
---
- Target iOS 17+. Use `@Observable`, `@State`, `@Bindable`, `NavigationStack`.
Never introduce ObservableObject, @Published, NavigationView or UIKit wrappers
unless the file already uses them.
- Read DESIGN.md before creating or restyling a view. All colors, fonts, radii
and spacing come from `Theme.swift`. No literal values in views.
- Use SF Symbols, not emoji, for icons. Minimum tap target 44x44 pt.
- Use async/await. No completion handlers in new code. Mark UI code `@MainActor`.
- Every new view gets a `#Preview` in light and dark.
- Do not add packages. Ask first..cursor/rules/app-store.mdc:
---
description: App Store review guardrails that apply to every change
alwaysApply: true
---
- Never hardcode API secrets, localhost or staging URLs outside `#if DEBUG` / `__DEV__`.
- Purchases: StoreKit 2 or RevenueCat only. A paywall must show the billed price,
auto-renewal terms, Terms of Use, Privacy Policy and Restore Purchases.
- New permission API usage requires its purpose string in Info.plist or app.json
in the same change.
- Sign-up requires in-app account deletion. Social login requires Sign in with Apple.
- Before any `eas submit`, `fastlane deliver` or `xcodebuild archive`,
run `stringer-preflight .` and stop if the verdict is BLOCKED.If you prefer the single legacy file, concatenate the bullet lists into .cursorrules at the repository root. Cursor still reads it, but it is loaded for every request and cannot be scoped.
The Expo and React Native variant
Swap the SwiftUI section for this in either file:
## Stack
Expo SDK [version], React Native new architecture, TypeScript strict, Expo Router.
## Rules
- Components are function components with typed props. No `any`.
- Styling: `StyleSheet.create` with tokens from `theme.ts`, which mirrors DESIGN.md.
No inline hex values or magic numbers.
- Lists use FlashList or FlatList with stable keys. Never map inside a ScrollView
for more than about 20 rows.
- Animations use Reanimated worklets on the UI thread and Gesture Handler for
gestures. Never drive animation from React state updates.
- Native config lives in `app.json` / `app.config.ts`: permissions go through config
plugins with real purpose strings, and privacy manifest entries under
`ios.privacyManifests`.
- Use `expo-secure-store` for tokens. Nothing secret in `EXPO_PUBLIC_` variables.
- Commands: `npx expo start`, `npx tsc --noEmit`, `npx expo-doctor`,
`eas build -p ios --profile production`.Pair the rules with a DESIGN.md
The rules say "follow DESIGN.md". The agent then needs one worth following. A useful spec has color roles for light and dark with hex values, a type scale with sizes and weights, a spacing scale, radii, component rules and a short list of prohibitions. Writing one from scratch takes a designer an afternoon.
The styles gallery has 301 ready-made ones (162 light, 139 dark), each derived from a real iOS visual direction and shipped with four reference screens. Save one into the repository:
# Pick a style at https://stringers.io/en/styles/ and save its spec
curl -s https://stringers.io/styles/cards/oat-margin.md -o DESIGN.mdOr install the skill and let the agent do the picking and fetching:
npx skills add komako-workshop/stringersThen ask: "redesign this screen with stringers". The agent proposes three contrasting styles, you choose one, and it writes the UI against that DESIGN.md without removing existing features. The DESIGN.md guide explains the anatomy of the file, and the SwiftUI styles guide shows how to turn the tokens into a Theme.swift.
Motion that holds 60fps
Agents asked to "add a nice animation" tend to produce a 0.3-second ease-in-out on everything, or a layout animation that drops frames in a list. Two things fix it: the motion rules in the files above, and working reference code.
The motion library has 100 mobile motions recorded at 60fps on a real device, each with runnable SwiftUI source and most with an Expo and Reanimated version. Copy the one you need into the agent's context instead of describing it. A reference implementation is a far tighter constraint than an adjective.
The underlying rules, for when you write your own:
- Animate
transformandopacity. Changing size or position inside a scrolling list forces layout on every frame. - In SwiftUI, prefer springs and keep
matchedGeometryEffectto a handful of elements. - In React Native, keep the animation on the UI thread: shared values and worklets, never
setStateper frame. - Test on the oldest device you support, in a release build. The simulator and debug builds do not show real frame times.
Add a pre-submission hook
Rules in a markdown file are advice, and a model can forget advice. A hook is enforced by the harness. stringer-preflight is a single-file, read-only scanner with 26 App Store rejection rules, and its hook mode inspects each shell command and blocks only submission and archive commands while a blocker remains.
Install it once:
curl -fsSL https://raw.githubusercontent.com/komako-workshop/stringers/main/cli/stringer-preflight -o ~/.local/bin/stringer-preflight
chmod +x ~/.local/bin/stringer-preflightClaude Code, in .claude/settings.json:
{
"hooks": {
"PreToolUse": [
{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "stringer-preflight --hook" }] }
]
}
}Cursor, in .cursor/hooks.json:
{ "version": 1, "hooks": { "beforeShellExecution": [{ "command": "stringer-preflight --hook" }] } }Now eas submit, fastlane deliver, xcodebuild archive and flutter build ipa are scanned first, and every other command passes straight through. If you must override once, prefix the command with STRINGER_PREFLIGHT_OK=1. The preflight page lists every rule.
Checklist: a repository an agent can ship from
- [ ]
CLAUDE.md(andAGENTS.mdif you use Codex) at the root, under about 150 lines, with real build and test commands. - [ ]
.cursor/rules/with one scoped rule per concern, or a legacy.cursorrules. - [ ]
DESIGN.mdat the root, and aTheme.swiftortheme.tsthat mirrors it. - [ ] No literal colors or font sizes outside the theme file (search for
Color(red:and#[0-9a-fA-F]{6}to check). - [ ] The preflight hook installed for the agent you use.
- [ ] A release-build run on a real device before every submission.
Mistakes that make rules files useless
- Too long. A 600-line rules file is skimmed by the model the way it would be by a person. Cut anything the agent already does correctly without being told.
- Aspirational. "Write clean, maintainable code" changes nothing. "Extract a subview when
bodypasses 40 lines" does. - Contradictory. Rules that say "iOS 17 APIs only" in a project full of
ObservableObjectproduce half-migrated files. Describe the code as it is, and say which direction new code should take. - Design in prose. "Warm, minimal, premium" is not a specification. Hex values and point sizes are.
- No verification step. If the file does not say how to build and test, the agent will not.