swift-refactor

swift-refactor is a command for coding agents from OkminLee/everything-claude-code-ios. It costs 31 tokens per session (1,827 once invoked), scanned A, original, MIT.

A command for finding and safely removing unused Swift code in iOS projects. It groups findings by risk and checks tests before and after proposed deletions.

In plain words
What is it for?
Use it to scan Swift projects, review unused methods or APIs, remove low-risk code, and verify the app still passes its tests.
Why use it?
It reduces dead code while lowering the risk of deleting something that the app still needs.

Command

Part of the everything-claude-code-ios plugin — 5 skills, 10 commands, 12 agents, 5 hooks, 4 MCP servers shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/okminlee/everything-claude-code-ios/swift-refactor
Clone the repo
git clone --depth 1 https://github.com/OkminLee/everything-claude-code-ios

Or install everything-claude-code-ios, the plugin that ships this one along with the rest of its 5 skills, 10 commands, 12 agents, 5 hooks, 4 MCP servers.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for swift-refactor

README.md
[![agentmods](https://agentmods.dev/badge/commands/okminlee/everything-claude-code-ios/swift-refactor.svg)](https://agentmods.dev/commands/okminlee/everything-claude-code-ios/swift-refactor)
Your own site
<a href="https://agentmods.dev/commands/okminlee/everything-claude-code-ios/swift-refactor"><img src="https://agentmods.dev/badge/commands/okminlee/everything-claude-code-ios/swift-refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 31 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,827 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00031 $0.01827
Opus 5 $0.00015 $0.00914
Sonnet 5 $0.00006 $0.00365
Haiku 4.5 $0.00003 $0.00183

Measured 3d ago against content hash bb26fffb2357, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

swift-refactor scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/swift-refactor.md · 307 lines

How it starts

The opening of the file, as written. The whole thing — 307 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Swift Refactor Clean

Safely identify and remove dead code with test verification for iOS projects.

This command invokes the swift-refactor-cleaner agent.

What This Command Does

  1. Analyze Dead Code - Run Periphery to find unused Swift code
  2. Generate Report - Categorize findings by severity
  3. Propose Safe Deletions - Start with low-risk items
  4. Verify with Tests - Run tests before and after each change
  5. Rollback on Failure - Revert if tests fail

Process

  1. Run dead code analysis tools:

    • Periphery: Find unused code, protocols, functions
    • SPM: swift package diagnose-dependencies
    • Xcode: Build with -Wunused warnings
  2. Generate report in .reports/dead-code-analysis.md

  3. Categorize findings by severity:

    • SAFE: Unused private methods, test utilities
    • CAUTION: Unused public APIs, ViewModels
    • DANGER: Protocol extensions, @objc code, App entry points
  4. Propose safe deletions only

  5. Before each deletion:

    • Run full test suite
    • Verify tests pass
    • Apply change
    • Re-run tests
    • Rollback if tests fail
  6. Show summary of cleaned items

Running Periphery

Installation

# Homebrew
brew install peripheryapp/periphery/periphery

# Or build from source
git clone https://github.com/peripheryapp/periphery
cd periphery && make install

Configuration

Create .periphery.yml in project root:

# .periphery.yml
project: MyApp.xcodeproj
schemes:
  - MyApp
targets:
  - MyApp
  - MyAppTests

# Exclude patterns
exclude:
  - "*.generated.swift"
  - "**/Preview Content/**"
  - "**/*+Preview.swift"

# Retain patterns (false positives)
retain_public: false
retain_objc_accessible: true
retain_unused_protocol_func_params: true

# Output
format: json
quiet: false

Running Analysis

# Full analysis
periphery scan --project MyApp.xcodeproj --schemes MyApp --targets MyApp

# With JSON output for parsing
periphery scan --format json > dead-code-report.json

# SPM project
periphery scan --setup

# Quick scan (faster, less accurate)
periphery scan --skip-build

Read the full file on GitHub · 307 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 307 lines · 31 tokens per session scan A bb26fffb2357

Subscribe to this mod's changes

swift-refactor is a command published in the GitHub repository OkminLee/everything-claude-code-ios (58 stars, last pushed 5mo ago), licensed MIT. It adds 31 tokens to every session and 1,827 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.