mcpbeat Sign in

Code Size Skill for Claude

Enforce complexity and size limits on Swift code with SwiftLint threshold rules — cyclomatic complexity, function/type/file length, parameter count — adopted via a violations baseline so existing code never blocks. Use when agent-written code needs deterministic size constraints.

1k tokens
context cost
the whole folder, loaded on every use
2
files
instructions only
0
copies elsewhere
how many repositories repackaged it
585
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/rshankras/claude-code-apple-skills --skill code-size

The instruction itself

7 sections, as written by the author

Code Size & Complexity Limits

Complexity is the strongest single predictor of defect density, and code written *by agents* balloons fastest — an agent under pressure adds one more branch to an existing function far more readily than it extracts a new one. These five SwiftLint threshold rules are the deterministic cap: they keep functions small enough that tests can actually cover their branches, and they keep agents from wrangling with their own tangles.

When This Skill Activates

Use this skill when:

  • Setting up quality gates for a project where agents write most of the code
  • A review keeps flagging "this function is too long/branchy" by hand
  • Functions have grown past what their tests plausibly cover
  • Adopting the deterministic gauntlet (see testing/fitness-functions/)

The Rules

The fragment at rules/swiftlint.yml configures five built-in SwiftLint rules (all enabled by default in SwiftLint — this fragment sets the thresholds):

| Rule | Warning | Error | What it caps |

|---|---|---|---|

| cyclomatic_complexity | 10 | 20 | Independent paths through one function |

| function_body_length | 50 | 100 | Lines per function body |

| type_body_length | 300 | 500 | Lines per type body |

| file_length | 500 | 1000 | Lines per file |

| function_parameter_count | 5 | 8 | Parameters per function |

Merge the fragment into the project's .swiftlint.yml (alongside any opt_in_rules/custom_rules fragments already adopted).

Brownfield Adoption: Baseline, Never Mass-Refactor

Turning these rules on in an existing codebase must not trigger a refactoring spree — bulk rewrites to satisfy a linter are how working code gets broken. Freeze today's violations and gate only *new* ones:

# One-time: record existing violations (SwiftLint 0.55+)
swiftlint lint --write-baseline .swiftlint-baseline.json

# The gate from then on — fails only on NEW violations
swiftlint lint --strict --baseline .swiftlint-baseline.json

Commit .swiftlint-baseline.json. Shrink it opportunistically: when touching a baselined function for other reasons, fix its violation and regenerate the baseline in the same commit.

Fallback for older SwiftLint (before 0.55, no baseline support): record the violation count instead —

swiftlint lint --quiet | wc -l > .swiftlint-count
# Gate: current count must not exceed the committed count

When a Rule Fires

The fix is structural, not suppressive:

  • cyclomatic_complexity / function_body_length → extract the branches into named functions, or replace the branch ladder with a table/enum dispatch
  • type_body_length / file_length → split by responsibility (extensions in separate files count separately)
  • function_parameter_count → introduce a parameter struct

// swiftlint:disable is not a fix. The rare legitimate exemption (a generated file, a big-but-flat data table) belongs in .swiftlint.yml's excluded: list with a comment — visible in one place, not scattered through source.

Common Pitfalls

| Pitfall | Problem | Solution |

|---------|---------|----------|

| Enabling without a baseline | Day-one wall of violations, gate ignored | --write-baseline first, gate on new only |

| Mass-refactoring to satisfy thresholds | Working code broken for a number | Freeze old violations; fix opportunistically |

| Inline swiftlint:disable comments | Exemptions scattered and invisible | excluded: list in config, with reasons |

| Thresholds loosened per-project | Cap quietly stops capping | Change thresholds only with a written reason |

References

  • testing/fitness-functions/ — set/count invariants a per-line rule can't express
  • testing/coverage-ratchet/ — the coverage half of the metrics gauntlet
  • ios/coding-best-practices/ — iOS-specific lint fragment (style/API rules)
  • generators/ci-cd-setup/ — base .swiftlint.yml template these fragments merge into

Other skills for the same job

different authors, same section of the catalogue
MCP Builder
by anthropics
vendor ×13

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

30k tokens scripts
Changelog Generator
by frostant
×9

Automatically creates user-facing changelogs from git commits by analyzing commit history, categorizing changes, and transforming technical commits into clear, customer-friendly release notes. Turns hours of manual changelog writing into minutes of automated generation.

774 tokens
Finishing A Development Branch
by ZhanlinCui
×7

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup

1k tokens
MCP Builder
by JayZeeDesign
×7

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

37k tokens scripts
Vercel React Native Skills
by vercel-labs
vendor ×6

React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.

39k tokens
Vercel React Best Practices
by ratacat
×5

React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.

34k tokens
Next Best Practices
by vercel-labs
vendor ×4

Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling

20k tokens
Using Git Worktrees
by ZhanlinCui
×4

Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification

1k tokens

How to use it

Copy the folder

Take rshankras/code-size from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.