A native macOS (SwiftUI) disk-usage analyzer and cleaner, inspired by CleanMyMac, with a few hard principles:
- Runs 100% locally — no network, no uploads, no telemetry
- Scanning is read-only
- Default cleanup = move to Trash (
FileManager.trashItem); mistakes can be recovered - Permanent deletion is possible, but it is a separate red button with a forced confirmation — never an accidental tap (see below)
- Every item is tagged with a risk level and "what happens if I delete it"
- Every deletion path (to Trash or permanent) shares one safety check: paths outside home, standard system directories, items inside the Trash, symbolic links and missing paths are all refused
A local-only, read-only-by-default disk cleaner for macOS, written in SwiftUI. Cleaning moves items to the Trash by default; permanent deletion is a separate, explicitly-confirmed action. No network, no telemetry. MIT licensed.
Grab the .dmg from Releases, open it, and drag
iCleaner onto the Applications shortcut.
First launch: right-click the app → Open → Open again. Release builds are signed ad-hoc but not notarized, so a plain double-click is blocked by Gatekeeper. If macOS still refuses, open System Settings → Privacy & Security and click Open Anyway.
Then grant Full Disk Access and restart the app — without it most of
~/Library is unreadable and every number comes out too low.
Every release needs Full Disk Access granted again: macOS keys that permission to the code signature, and an ad-hoc signature changes with each build. If you update often, build from source and run
./setup-signing.shonce — a stable local certificate makes the permission stick.
Verify what you downloaded:
shasum -a 256 -c iCleaner-*.dmg.sha256Requires macOS 13+ and Xcode 16 or matching Command Line Tools
(xcode-select --install) — Package.swift is swift-tools-version 6.0.
git clone <repo> && cd iCleaner
./build.sh
open iCleaner.appTo put it in Launchpad:
cp -R iCleaner.app /Applications/build.sh tries SwiftPM first. If your machine only has Command Line Tools,
swift build may fail with:
error: Invalid manifest ...
Undefined symbols: PackageDescription.Package.__allocating_init(...)
That is a mismatch between the libPackageDescription shipped with CLT and the
tools-version declared in the manifest — unrelated to the project code. The
script automatically falls back to compiling directly with swiftc; the
artifact is identical. You can also force it:
./build.sh --swiftc # skip SwiftPM
./build.sh --spm # SwiftPM only
./build.sh --run # build then openIf Gatekeeper blocks the first launch, right-click → Open, or
xattr -dr com.apple.quarantine iCleaner.app.
Run the diagnostic script first; its output can be pasted straight into an issue:
./debug.sh # environment + bundle + signing + crash reports + recent logs
./debug.sh --run # additionally runs in the foreground so crashes print to the terminalKnown pitfalls:
- Clicked the icon; no menu bar and no window. A hand-assembled SwiftUI
bundle missing
NSPrincipalClassstarts as a background process.build.shalready writes it into Info.plist, andAppDelegateexplicitly enforces the.regularactivation policy. Re-run./build.sh. The log showsapplicationDidFinishLaunching — policy=… mainMenuItems=…; a non-zero policy still means this issue. - Process running but no window. Search the log for
No visible window after launch. - Permission keeps dropping after every rebuild. Ad-hoc signing changes every time — see the next section.
Without it, many directories under ~/Library are unreadable and the scan
numbers come out noticeably too small. When the app detects missing
permission it shows a banner at the top that jumps straight to the settings
page.
System Settings → Privacy & Security → Full Disk Access → + → select
iCleaner.app → enable → restart the app.
Default ad-hoc signing (codesign -s -) changes the signature on every
rebuild, invalidating the granted permission.
The reason: TCC does not key on the app path but on the code signature's designated requirement. Ad-hoc has no certificate, so the DR degrades to a cdhash (binary content hash) — recompile after changing a line and it changes.
Run this script once to generate a locally self-signed certificate:
./setup-signing.shAfter that the DR becomes identifier "local.icleaner.app" and certificate leaf H"…",
without a cdhash, identical across rebuilds — the permission persists.
./setup-signing.sh --status # show signing identity and which kind of DR the current .app hasNotes:
- The private key is not and must not be in the repo. Anyone holding the private key could sign a binary with your identity, and that identity holds Full Disk Access on your machine. Anyone who clones just runs the script once to generate their own certificate.
- After switching to certificate signing, grant access once more (the signing identity changed); after that it sticks.
- Keychain may prompt "codesign wants to use your private key" on the first build — click Always Allow.
- This does not affect Gatekeeper — a self-signed certificate is not notarized, so the first launch may still need right-click → Open.
Import fails with MAC verification failed during PKCS12 import
Homebrew's OpenSSL 3.x writes .p12 with AES-256 + PBKDF2 + SHA-256 MAC by
default, which macOS's security import (an old parser) cannot read; an empty
password also guarantees the two sides compute different MACs. The script
already forces SHA-1 + 3DES + a non-empty temporary password, with two
fallbacks (-legacy, and importing PEM key/cert separately). If it still
fails:
# 1) Use the system LibreSSL instead of Homebrew's OpenSSL
PATH=/usr/bin:$PATH ./setup-signing.sh --force
# 2) Last resort: create one by hand in Keychain Access, no openssl at all:
# Keychain Access → Certificate Assistant → Create a Certificate…
# Name "iCleaner Self Signed", Identity Type "Self-Signed Root",
# Certificate Type "Code Signing"
# Then double-click it → Trust → Code Signing → "Always Trust"
./setup-signing.sh --status # confirm codesign recognizes the certificate| Category | Contents |
|---|---|
| App caches | ~/Library/Caches/*, HTTPStorages, crash reports, saved window state, local iPhone backups, WeChat data |
| Developer caches | Gradle / Maven / npm / yarn / pnpm / bun / cargo / pip / uv / Homebrew / Go module / CocoaPods / SwiftPM / NuGet / Ollama models … |
| Xcode & simulators | DerivedData, per-platform DeviceSupport, Archives, CoreSimulator devices and runtimes |
| Containers & VMs | OrbStack, Docker Desktop data disk, Lima / Colima / minikube / UTM / Parallels |
| Logs & temporary files | ~/Library/Logs/*, VS Code / Cursor caches |
| Project build artifacts | node_modules / target / .venv / vendor/bundle … under your project directories |
| Large files | single files or bundles above a threshold (default 500MB) in your home |
| Duplicate files | files with identical content (off by default — hashes full contents) |
| Uninstall leftovers | what stays under ~/Library after an app is deleted: config and sandbox containers |
| Trash | space still held by ~/.Trash |
Three additional tool pages:
- App Uninstaller — pick an app and send the bundle plus its preferences,
caches, sandbox container and Group Containers under
~/Libraryto the Trash. Dragging the app to the Trash only removes the bundle. - Space Explorer — measures directory usage one level at a time on demand; double-click to drill down. Answers "which folder is actually eating the space".
- Local Snapshots — lists APFS local snapshots. "System Data"
inflating is, eight times out of ten, these — but deleting a snapshot
needs
sudoand is irreversible, so this page only hands out the command, it does not do the deed.
Sizes use allocated size, consistent with du; hard links count once.
- 🟢 Safe to clean — regenerated automatically, effectively unnoticed
- 🟠 Needs rebuilding — no data loss, but the next build re-downloads / recompiles
- 🔴 Careful — may contain things you actually want (Archives dSYMs, WeChat history, iPhone backups, container volumes)
The bottom bar's "Select all safe items" only selects the green ones.
Two buttons sit side by side; you choose at the moment you press. There is no global mode to toggle beforehand:
| Move to Trash (default) | Permanent delete | |
|---|---|---|
| Behavior | FileManager.trashItem |
FileManager.removeItem |
| When space is freed | after emptying the Trash | immediately |
| Recoverable | ✅ yes | ❌ no |
| Confirmation | plain confirmation | red dialog + must check "I understand these files will be permanently deleted" |
| 🔴 careful items | can be cleaned (not selected by default) | excluded by default; to delete, release them one by one via right-click in the detail list |
Both paths share the same front-end safety validation (Trash.validate's
five checks); they only differ at the final disk step. The permanent-delete
implementation lives in forceDelete in
Sources/iCleanerCore/Trash.swift; the risk-to-action binding is in
CleanAction.allows(_:).
"Empty Trash" is essentially a permanent delete (the content is already in the Trash), so it always requires a second confirmation.
- The Containers category deletes the whole data disk — Docker images,
containers and volumes all go with it. A safer route is
docker system prune -a/ OrbStack's own cleanup. - After moving to the Trash, space is only truly freed by emptying the Trash. The bottom bar has a one-click Empty.
- Large-file and duplicate scans never enter iCloud Drive
(
~/Library/Mobile Documents,~/Library/CloudStorage) — traversing it would pull every not-yet-downloaded file to disk. - If "System Data" is inflated but nothing shows up here, check the "Local Snapshots" page.
Package.swift
Sources/
iCleanerCore/ scanning & cleaning logic, pure Foundation, unit-testable
Models.swift risk levels, categories, item model
Paths.swift home conventions, protected paths, scan exclusions
Rules.swift rule table + deduplicated expansion (add directories here)
SizeCalculator.swift size accounting (allocated size / hard-link dedup / concurrency)
Scanner.swift build-artifact finder, large-file top-N
DuplicateFinder.swift size → head/tail fragments → SHA-256
AppInventory.swift installed apps, uninstall-leftover lookup
SpaceTree.swift on-demand directory space tree
Snapshots.swift APFS local snapshots
Trash.swift pre-delete safety check, Trash wrapper, permanent delete
CleanAction.swift cleanup actions (Trash / permanent) bound to risk levels
ActivityReporter.swift throttled "what is being processed" reporting
Localization.swift localization lookup and language switching
AppLog.swift unified logging (English, see below)
iCleaner/ SwiftUI UI
iCleanerApp.swift entry point and menu
ScanStore.swift state, scan scheduling, preference persistence
Theme.swift colors, progress bar, permission banner, language picker
ContentView.swift sidebar, nav bar, confirmation dialogs, scan options
SmartScanView.swift smart-scan landing page (big scan button → category cards → one-click clean)
CategoryView.swift result list, duplicate groups, bottom bar
UninstallerView.swift app uninstaller
SpaceTreeView.swift space explorer
SnapshotsView.swift local snapshots
Resources/
en.lproj/Localizable.strings development language
zh-Hans.lproj/Localizable.strings Simplified Chinese
Tests/iCleanerCoreTests/ unit tests
build.sh compile + package into .app
To add a scan target, add one line to Rules.all, then add the English
sentence to both Localizable.strings files. To add a protected path (never
deletable), edit Paths.protectedRelativePaths.
ScanCategory back to Category — the ObjC runtime has a
typedef struct objc_category *Category, which collides in any module that
imports AppKit as 'Category' is ambiguous for type lookup, and the error
cascades across dozens of places, hard to locate.
UI strings go through localization; logs are always English.
The development language is English and the strings in the source are the keys themselves:
Text(L("Scan options"))
Text(L("%d items", count))Resources/zh-Hans.lproj/Localizable.strings maps them to Chinese. So even
when the bundle is not found (swift run, swift test), the UI is readable
English rather than internal identifiers like scan.options.title.
Language switching has two entry points: the "Language" menu bar item, and
the scan options on the overview page. The switch takes effect immediately
(ContentView carries .id(store.languageTag) and rebuilds the whole tree);
already-scanned results change too — ScanItem stores key + args and looks
up at render time, no rescan needed.
Resources/<tag>.lproj/Localizable.strings, translating theen.lprojone- Add a line to
Localization.supported swift test—LocalizationTestschecks for missing keys and whether the count/order of%@/%dplaceholders matches English (a mismatch crashes inString(format:))
build.sh copies Resources/*.lproj into the app bundle automatically,
writes CFBundleLocalizations, and validates syntax with plutil -lint.
Everything goes through AppLog (os.Logger, subsystem
local.icleaner.app), split into six categories:
scan / cleanup / uninstall / duplicates / system / ui.
# Live view
log stream --predicate 'subsystem == "local.icleaner.app"' --level info
# Last 30 minutes
log show --predicate 'subsystem == "local.icleaner.app"' --last 30mTwo rules:
- Log messages are always English and never go through
L(_:). The UI can be any language, but logs pasted into a GitHub issue must be readable by everyone. - Paths are logged as
.private; counts, durations and category names (non-sensitive) use.public. Users' directory names should not end up in sysdiagnose.
swift build # compile
swift test # run tests (covers iCleanerCore only)
./build.sh --run # package and openSome tests act as safety nets; keep them green when changing rules or strings:
RulesTests.testExpandProducesNoDuplicatePaths— the same path must not be produced twiceRulesTests.testExpandProducesNoNestedCandidates— candidates must not nest (double-counted sizes)RulesTests.testSelectableCandidatesPassTrashValidation— every selectable candidate must pass the deletion safety checkTrashSafetyTests— paths outside home, standard system directories and inside the Trash must be refusedLocalizationTests— key sets identical across languages, placeholders match one-to-one, all rule descriptions translated
PRs welcome. Before adding a rule, please confirm:
- Does this directory regenerate automatically after deletion? What does rebuilding cost? Is the risk level right?
- Does it overlap an existing rule? Run
swift test. - Write
detailin English, human language, explaining "what happens if I delete it", then add it toResources/*/Localizable.strings(missing it turnsswift testred). - New log lines in English, not through
L(_:).
DOCS/DESIGN.md |
What the app is meant to be and why — information architecture, visual language, and a decision log (§12) of the calls that were made and the ones that were reversed |
DOCS/TECH_SPEC.md |
How it is built — module layout, the scanning pipeline, the deletion safety gate, threading |
CONTRIBUTING.md |
The one hard rule about deletions, plus the conventions that have already cost someone an afternoon |
CHANGELOG.md |
What changed, per release |
Both design docs exist in Chinese (DESIGN.md) and English (DESIGN.en.md).
MIT, see LICENSE.





