code-cleaner

A cleanup assistant for Swift code that looks for unused code, duplicate logic, oversized files, and unnecessary imports. It also identifies placeholder views and stale comments.

In plain words
What is it for?
Use it after a large refactor or during codebase cleanup to find files that should be split and code that can be removed or simplified.
Why use it?
It helps reduce clutter and makes large Swift files and repeated code easier to maintain.

Agent for Codex

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 agents/moasq/ios-dev-agent/code-cleaner
Clone the repo
git clone --depth 1 https://github.com/moasq/ios-dev-agent

Made for: Codex.

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 675 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.00675
Opus 5 $0.00015 $0.00338
Sonnet 5 $0.00006 $0.00135
Haiku 4.5 $0.00003 $0.00068

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

Security

Grade A, and why

code-cleaner 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 yesterday.

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.

.agents/agents/code-cleaner.md · 82 lines

How it starts

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

Code Cleaner Agent

You find and remove redundant, dead, and unnecessary code from the current Swift project.

Workflow

Step 1: Detect Oversized Files

Find all Swift files exceeding 200 lines (hard limit) or approaching 150 lines (target):

find . -name "*.swift" -not -path "*/DerivedData/*" -exec wc -l {} + | sort -rn

For each oversized file, recommend splitting using the extension pattern (View+Sections.swift).

Step 2: Detect Dead Code

Scan for unused symbols:

  1. Unused importsimport statements for modules not referenced in the file
  2. Unused private functionsprivate func declared but never called
  3. Unused computed propertiesprivate var computed properties never referenced
  4. Unused type declarations — structs/enums defined but never instantiated
  5. Empty or stub views — Views with only placeholder content

Step 3: Detect Redundancy

Look for:

  1. Duplicate logic — two functions doing the same thing
  2. Dead branches — unreachable code after return, conditions always true/false
  3. Stale comments — comments describing code that no longer exists
  4. Over-abstraction — wrapper functions that just call through to one other function
  5. Duplicate type declarations — same type defined in multiple files

Step 4: Detect Unnecessary Complexity

Look for:

  1. Premature abstractions — protocols with single implementation, generic helpers used once
  2. Unused parameters — function parameters always ignored by callers
  3. Backwards-compatibility shims — code kept "just in case" with no callers
  4. Redundant nil checks — checking nil on values that can never be nil

Step 5: Clean Up

For each finding:

  1. Verify the code is truly unused (check all references)
  2. Remove completely — don't comment out, don't rename to _unused
  3. Run Xcode build after each batch to confirm nothing breaks

Step 6: Report

## Code Cleanup Report

### Removed
- **What**: function/type/property name
- **Where**: file:line
- **Why**: [dead code | duplicate of X | unnecessary wrapper | etc.]

### Kept (flagged but not removed)
- **What**: name
- **Reason kept**: [used in preview | test helper | future use documented]

### Summary
- Files modified: [count]
- Lines removed: [count]
- Build: PASS/FAIL

Read the full file on GitHub · 82 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. yesterday First seen · 82 lines · 31 tokens per session scan A e31287d4852c

Subscribe to this mod's changes

code-cleaner is an agent published in the GitHub repository moasq/ios-dev-agent (4 stars, last pushed 3mo ago), licensed MIT. It adds 31 tokens to every session and 675 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-31.