Agent skill

Fitness Functions

by rshankras in rshankras/claude-code-apple-skills

Write architecture fitness functions — deterministic tests that enforce a project's hard rules (module boundaries, offline guarantees, content contracts) from inside its own test target.

MITAuto-check: notesDevelopment

Install Fitness Functions

skills CLI
$ npx skills add rshankras/claude-code-apple-skills --skill fitness-functions -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install rshankras/claude-code-apple-skills fitness-functions --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/rshankras/claude-code-apple-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/testing/fitness-functions .claude/skills/fitness-functions && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
fitness-functions
GitHub stars
787
Token cost
~2k tokens
SKILL.md length
971 words
Files
4
Skills in repo
41
Repo updated
First seen
Licence
MIT

At a glance

Write architecture fitness functions — deterministic tests that enforce a project's hard rules (module boundaries, offline guarantees, content contracts) from inside its own test target.

  • Works in 5 steps: Identify the Invariant → Pick the Pattern → Write the Suite → …
  • A constraint lives only in prose (CLAUDE.md
  • SKILL.md covers When This Skill Activates, Why a Test, Not a Lint Rule, The Three Patterns and Process, plus 3 more sections
  • Runs Swift scripts from its folder

What it does

Fitness Functions is an agent skill from rshankras/claude-code-apple-skills. Write architecture fitness functions — deterministic tests that enforce a project's hard rules (module boundaries, offline guarantees, content contracts) from inside its own test target. Use when a constraint lives only in prose (CLAUDE.md, code review) and should become un-arguable.

Its SKILL.md is about 2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 4 other files.

It sits in Development, covering Agent instruction files and Code review. The repository describes itself as: Claude Code skills for Apple platform development (iOS, macOS, iPadOS) — product validation, code generation, App Store optimization, and more. The licence is MIT.

When your agent uses it

  • A constraint lives only in prose (CLAUDE.md
  • Code review) and should become un-arguable

Example prompts

  • “/fitness-functions”

Requirements

  • Pre-approved tools (allowed-tools): Read, Write, Edit, Glob, Grep, Bash

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Identify the Invariant
  2. Pick the Pattern
  3. Write the Suite
  4. Prove It Red (Deliberate-Break Drill)
  5. Commit

What it can do on your machine

Read from SKILL.md and the folder at commit 9ffb831. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Read
    • Write
    • Edit
    • Glob
    • Grep
    • Bash

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships script files (Swift), which the agent can run.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Fitness Functions loads about 2k tokens when it runs. Until then it costs about 76 tokens; SKILL.md has 971 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~76
When it runs · the whole SKILL.md, loaded when a task matches
~2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check: notes

The automated check noted patterns worth knowing about, such as sudo or a known installer.

  • NotePre-approves every shell command (allowed-tools: Bash)SKILL.md
    allowed-tools: Read, Write, Edit, Glob, Grep, Bash

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from rshankras/claude-code-apple-skills at commit 9ffb831, republished under its MIT licence (© rshankras). 971 words, ~2,024 tokens.

Download SKILL.mdSave it as .claude/skills/fitness-functions/SKILL.md (or your agent's skills folder). This skill also uses 3 other files; get the full folder from GitHub.
name
fitness-functions
description
Write architecture fitness functions — deterministic tests that enforce a project's hard rules (module boundaries, offline guarantees, content contracts) from inside its own test target. Use when a constraint lives only in prose (CLAUDE.md, code review) and should become un-arguable.
allowed-tools
Read, Write, Edit, Glob, Grep, Bash
last_verified
2026-07-24
review_by
2027-07-01

Architecture Fitness Functions

A fitness function is an ordinary test that enforces an architectural rule instead of a behavior. It lives in the app's own test target, runs under every existing test gate forever, and turns "the agent said it's fine" into an exit code. This is the gauntlet's answer for invariants no unit test of behavior can see: a file quietly importing a framework it must not touch, a registry drifting from its documented size, user-facing copy breaking its format contract.

When This Skill Activates

Use this skill when:

  • A project hard rule exists only in prose — CLAUDE.md constraints, file-header comments, review checklists ("deck games must run fully offline", "only the sync layer may import CloudKit")
  • A code review keeps re-checking the same structural rule by hand
  • An /apple:review structural finding is being graduated into permanent enforcement
  • A count, boundary, or content format was broken silently once already

Why a Test, Not a Lint Rule

A per-line regex (SwiftLint custom_rules) can flag a line. A fitness function can assert a set: "the files importing MusicKit are exactly these four", "the mode registry has exactly 21 entries", "every case's copy fits the format". Sets, counts, and cross-file facts need code, and putting that code in the test target means no new tooling, no CI wiring — it rides the test gate that already exists.

The Three Patterns

Pattern 1: Import-Boundary Allowlist Scan

Enforces "only these files may import X." The test walks the shipped source tree and compares the actual importer set against an allowlist — so a fifth importer fails a test, not a code review.

Key rules (learned in production):

  • Resolve the source root from #filePath, never a hardcoded path — the test stays correct wherever the repo is checked out.
  • Match exact trimmed lines (line == "import X"), not contains — comments documenting the contract itself must not count as hits.
  • Compare full sets, not counts — the failure message then names the drifted file.
  • Exclude non-shipping directories deliberately (DEBUG-only spikes, generated code) and say why in a comment: the guarantee is about what ships.
  • The allowlist is a fence, not a headcount. Widening it is a legitimate, documented decision: when a new file genuinely belongs inside the boundary, the test failing is the system working — record why in the allowlist comment, then add it.
  • Add a companion API-surface scan for bypass routes the import check can't see. An import-only check misses a file calling the underlying API directly (every file already imports Foundation, which is enough to reach URLSession without importing the fenced framework). Scan for the raw API strings (URLSession(, URLSession.shared) outside the boundary too.

Template: templates/ImportBoundaryTests.swift

Pattern 2: Runtime Sentinel

Enforces "this code path never attempts X" — stronger than "happens to succeed without X." The canonical case is an offline guarantee: register a URLProtocol subclass that intercepts, counts, and fails every network request, drive the real production path, and assert the counter stayed at zero.

Key rules:

  • Register the sentinel per-test and unregister in defer.
  • The sentinel fails requests loudly (never lets them reach the network) — a regression fails in CI instead of silently succeeding against a live server.
  • Assert interceptedRequestCount == 0: the contract is zero attempts, not zero successes.
  • Drive the real path (real service, real composition), with only storage in-memory.

Template: templates/NetworkSentinelTests.swift

Show full SKILL.md (427 more words)Show less
Pattern 3: Contract Pins

Pins facts that must change deliberately, never by drift.

Count pins — registry and configuration sizes:

swift
// Phase 3.5 added 3 modes — 9 modes, 5 streaming.
// Phase 3.8 added the four reunion music games — 15 modes, 9 streaming.
// Phase 3.10 added the DJ-host quartet — 18 modes, 10 streaming.
#expect(PartyOccasion.bigParty.modes.count == 18)
#expect(PartyOccasion.bigParty.modes.filter(\.usesDJEngine).count == 10)

The comment trail is mandatory: each pinned number carries its history, so updating the pin is a reviewed decision with a written reason, not a chore silenced with an edit.

Copy-contract pins — structural rules on user-facing content, iterated over CaseIterable so new cases are covered automatically:

swift
@Test func everyModeHasExactlyThreeBeats() {
    for mode in GameMode.allCases {
        #expect(mode.howItPlaysBeats.count == 3, "\(mode.rawValue) has \(mode.howItPlaysBeats.count) beats, expected 3")
    }
}

Plus a few verbatim exemplars pinned with exact equality — a future content pass must change those deliberately, not by accident.

Template: templates/ContractPinTests.swift

Process

Phase 1: Identify the Invariant

Read CLAUDE.md / APP.md / file-header comments for hard rules currently enforced by nothing. Good candidates state a set or bound: "only", "never", "exactly", "at most", "every".

Phase 2: Pick the Pattern
The rule is about…Pattern
Which files may use a framework/API1 — import-boundary scan (+ API-surface companion)
What a code path may do at runtime2 — runtime sentinel
A size, format, or exact content3 — contract pins
Phase 3: Write the Suite

Copy the matching template into the existing unit-test target and adapt. One suite per invariant; name it after the guarantee (OfflineGuaranteeTests), not the mechanism. Every failure message must tell the fixer which side to change — the code or the contract — and where the contract is documented.

Phase 4: Prove It Red (Deliberate-Break Drill)

A fitness function that has never failed is unverified. Before committing:

  1. Introduce the violation for real (add the forbidden import to one file; change a pinned count).
  2. Run the suite — it MUST fail, with a message that names the offender.
  3. Revert. Run again — green.

Record the red/green pair in the commit message or PR. Repeat the drill whenever the suite's scanning logic (not its data) changes.

Phase 5: Commit

The suite ships in the normal test target. No special CI wiring — every existing test gate now enforces the rule.

Output Format

markdown
## Fitness Function: [invariant]

- **Rule source**: CLAUDE.md hard rule N / [file header]
- **Pattern**: import-boundary | runtime sentinel | contract pin
- **Suite**: Tests/[Name]Tests.swift
- **Deliberate-break drill**: [what was broken] → failed with "[message]" → reverted → green

Common Pitfalls

PitfallProblemSolution
contains("import X") matchingComments about the rule count as violationsCompare exact trimmed lines
Hardcoded source pathsBreaks on other checkouts/CIDerive root from #filePath
Pinning counts without historyUpdating the pin becomes a mindless choreComment trail explaining every number
Import check onlyDirect API calls bypass the fenceAdd the API-surface companion scan
Never proven redScan bug silently passes everythingDeliberate-break drill before commit
Allowlist grows without commentFence decays into a headcountEach entry documents why it's inside the boundary

References

  • testing/tdd-bug-fix/ — prove-red discipline for behavioral bugs
  • testing/test-contract/ — runtime behavioral invariants across implementations
  • swift/code-size/ — the complexity/size half of the deterministic gauntlet
  • testing/coverage-ratchet/ — coverage floor that only rises

© rshankras, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 3 other files in skills/testing/fitness-functions of rshankras/claude-code-apple-skills.

  • SKILL.md
  • templates/ContractPinTests.swift
  • templates/ImportBoundaryTests.swift
  • templates/NetworkSentinelTests.swift

Open the folder on GitHubat commit 9ffb831

Compare with similar skills

Fitness Functions next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Fitness Functions compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Fitness Functions this skillrshankras/claude-code-apple-skills787—~2kAutomated safety check: NotesMIT
Code Reviewimbenrabi/Financial-Modeling-Prep-MCP-Server150—~2.6kAutomated safety check: PassApache-2.0
Shipmillionco/react-doctor15k—~716Automated safety check: PassCustom licence
Promptkitmicrosoft/PromptKit111—~420Automated safety check: PassMIT
Megingiard Code Reviewstormpanda/megingiard155—~2.9kAutomated safety check: PassCustom licence
Ad ReviewCorridorTech/PoseCap224—~2.4kAutomated safety check: NotesApache-2.0

Similar skills

  • Code Review

    imbenrabi/Financial-Modeling-Prep-MCP-Server

    Review a PR or working diff against this repo's intent layer (the AGENTS.md hierarchy), toolception pitfalls, and core invariants.

    150 GitHub stars~2.6k tokensUpdated today
    DevelopmentAuto-check passed
  • Ship

    millionco/react-doctor

    Take the current branch from done-coding to merge-ready in one pass — review the diff against AGENTS.md, deslop, commit and push, open a PR using rule-validate's PR copy, then babysit until mergeable.

    15k GitHub stars~716 tokensUpdated today
    DevelopmentAuto-check passed
  • Promptkit

    microsoft/PromptKit

    Official

    PromptKit composition engine. An agent skill from microsoft/PromptKit.

    111 GitHub stars~420 tokensUpdated 22 days ago
    DevelopmentAuto-check passed
  • Megingiard Code Review

    stormpanda/megingiard

    Conduct a thorough code review of the current Git branch or specific files in Megingiard.

    155 GitHub stars~2.9k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Ad Review

    CorridorTech/PoseCap

    Two-axis fresh-context code review per WORKFLOW §10. An agent skill from CorridorTech/PoseCap.

    224 GitHub stars~2.4k tokensUpdated 4 days ago
    DevelopmentAuto-check: notes
  • Review Steering

    dralgorhythm/claude-agentic-framework

    Compiles REVIEW.md and keeps CLAUDE.md accurate as the two sanctioned surfaces for steering Anthropic's managed Code Review service, translating this repo's rules into terse reviewer imperatives.

    125 GitHub stars~1.1k tokensUpdated 2 mo ago
    DevelopmentAuto-check passed

More from rshankras/claude-code-apple-skills

All 41 skills in this repo
  • Accessibility Generator

    rshankras/claude-code-apple-skills

    Generate accessibility infrastructure for VoiceOver, Dynamic Type, and accessibility features.

    787 GitHub stars~1.4k tokensUpdated 2 mo ago
    Auto-check: notes
  • Animation Patterns

    rshankras/claude-code-apple-skills

    SwiftUI animation patterns including springs, transitions, PhaseAnimator, KeyframeAnimator, SF Symbol effects, scroll-driven effects, mesh gradients, text renderers, and shader effects.

    787 GitHub stars~2.1k tokensUpdated 2 mo ago
    Auto-check passed
  • App Description Writer

    rshankras/claude-code-apple-skills

    Generate compelling App Store descriptions that convert browsers into users.

    787 GitHub stars~1.3k tokensUpdated 2 mo ago
    Auto-check passed
  • App Icon Generator

    rshankras/claude-code-apple-skills

    Generates an app icon for macOS or iOS — a fast CoreGraphics placeholder and/or flat layered source art to finish in Icon Composer (the Liquid Glass / iOS 26+ standard).

    787 GitHub stars~5.1k tokensUpdated 2 mo ago
    Auto-check: notes
  • App Namer

    rshankras/claude-code-apple-skills

    Turn an app idea into validated, App-Store-ready name candidates.

    787 GitHub stars~3.4k tokensUpdated 2 mo ago
    Auto-check passed
  • Bundles And Licensing

    rshankras/claude-code-apple-skills

    Revenue beyond the single-app price tag — own-app bundles, Family Sharing as a conversion lever, cross-developer bundles & suites, and institutional licensing via Group Purchases / Apple School &…

    787 GitHub stars~1.8k tokensUpdated 2 mo ago
    Auto-check passed

Questions about Fitness Functions

What does Fitness Functions do?

Write architecture fitness functions — deterministic tests that enforce a project's hard rules (module boundaries, offline guarantees, content contracts) from inside its own test target. Fitness Functions is an agent skill from rshankras/claude-code-apple-skills. Write architecture fitness functions — deterministic tests that enforce a project's hard rules (module boundaries, offline guarantees, content contracts) from inside its own test target.

When should I use Fitness Functions?

Fitness Functions fits situations like: A constraint lives only in prose (CLAUDE.md; code review) and should become un-arguable.

How do I install Fitness Functions in Claude Code?

Run `npx skills add rshankras/claude-code-apple-skills --skill fitness-functions -a claude-code`. Or copy the skill folder (skills/testing/fitness-functions in rshankras/claude-code-apple-skills) into .claude/skills/fitness-functions in your project. Claude Code loads it when a task matches its description.

How do I install Fitness Functions in Codex?

Run `npx skills add rshankras/claude-code-apple-skills --skill fitness-functions -a codex`. Or copy the skill folder (skills/testing/fitness-functions in rshankras/claude-code-apple-skills) into .agents/skills/fitness-functions in your project. Codex loads it when a task matches its description.

Can I use Fitness Functions in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add rshankras/claude-code-apple-skills --skill fitness-functions -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/fitness-functions, .gemini/skills/fitness-functions, .github/skills/fitness-functions and .opencode/skills/fitness-functions in your project.

What does Fitness Functions need to run?

Going by SKILL.md and its folder, Fitness Functions needs Swift for the scripts in its folder. Its frontmatter pre-approves these tools: Read, Write, Edit, Glob, Grep, Bash.

Does Fitness Functions access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Fitness Functions safe to install?

Our automated static check of SKILL.md found notes only (pre-approves every shell command (allowed-tools: bash)), nothing it rates as a warning. It is not a guarantee. Review the folder before installing.

What licence does Fitness Functions use?

Fitness Functions is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Fitness Functions use?

About 2k tokens (SKILL.md is roughly 8.1k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Fitness Functions?

Skills that share tags, products or a category with Fitness Functions: Code Review (imbenrabi/Financial-Modeling-Prep-MCP-Server, 150 stars), Ship (millionco/react-doctor, 15k stars), Promptkit (microsoft/PromptKit, 111 stars) and Megingiard Code Review (stormpanda/megingiard, 155 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Fitness Functions?

rshankras (a GitHub user) maintains it in rshankras/claude-code-apple-skills, which has 787 GitHub stars. The repository holds 41 skills in this directory. The repository was last updated on July 24, 2026.

Source: rshankras/claude-code-apple-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.