開發者如何清理 Mac 而不誤刪重要資料
How to clean a developer Mac without breaking anything
這份指南以刪除後能否自行重建、是否可重新下載,或是否屬於無法重建的個人資料,分類開發者 Mac 上的清理項目。內容涵蓋 Xcode、Docker、專案依賴、套件管理器快取及 AI 編碼工具,並提醒 Docker volumes 和 AI 對話記錄須小心處理;工作樹只有在 git status 乾淨且所有提交已推送或合併時才可移除。
A developer Mac fills up in places macOS lumps together as "System Data". Most of it is safe
to remove. Some of it looks like junk and is not. The question for every folder is the same:
what happens if it is gone? There are three answers.
- It rebuilds itself. The tool makes it again when needed. You lose time, not data.
- It downloads again. Safe, but the next install or build needs the network and waits.
- It is yours. Nothing makes it again. Look before you remove it.
Xcode
| What | Where | If it is gone |
|---|---|---|
| Build data | ~/Library/Developer/Xcode/DerivedData |
Rebuilds itself on the next build |
| Device support | ~/Library/Developer/Xcode/iOS DeviceSupport |
Downloads again when you connect that device |
| Simulator caches | ~/Library/Developer/CoreSimulator/Caches |
Rebuilds itself |
| Archives | ~/Library/Developer/Xcode/Archives |
Yours. The builds you shipped, with their debug symbols |
Simulators for iOS versions you removed are dead weight. Remove only those:
xcrun simctl delete unavailable
Docker
Docker keeps images, stopped containers, build cache and volumes. The first three come back;
volumes are databases and do not.
docker container prune # stopped containers
docker image prune # images no container or tag uses
docker builder prune # build cache
Never run docker system prune --volumes unless you are sure no volume holds data you need.
node_modules and other project dependencies
node_modules, .venv and similar folders are downloaded again by npm install,
pnpm install or pip install. Removing them from projects you have not touched in months is
the biggest safe win on most JavaScript machines. Leave the ones in projects you are working on
this week, or your next run waits for a full install.
Build output beside a project file (target next to Cargo.toml, dist or build next to
package.json) rebuilds itself. A folder named build with no project file beside it may be
someone's documents.
Package manager caches
All of these download again:
brew cleanup # old Homebrew downloads and versions
npm cache clean --force # npm's download cache
pnpm store prune # packages no project uses any more
Cargo's ~/.cargo/registry/cache, Gradle's ~/.gradle/caches and uv's ~/.cache/uv work the
same way.
AI coding tools
AI tools leave three kinds of things behind, and they are not equally safe.
- Scratch and cache folders rebuild themselves. Remove a finished session's, never a running one's.
- Local models (Ollama, LM Studio, Hugging Face) download again, but each one is gigabytes. Remove the ones you stopped using, not the one you use daily.
-
Worktrees are full copies of a repository. One can go only when
git statusinside it is clean and every commit is pushed or merged. Remove it withgit worktree removeso git forgets it too. -
Session transcripts are yours: they are what lets you resume a conversation. Claude Code
deletes old ones by itself after 30 days by default (the
cleanupPeriodDayssetting). Keep anymemoryfolder next to them; that is what the tool remembers about your projects.
Doing it with an app
Kempt and DiskAtlas sort Xcode data, dependencies, package caches and AI tool folders by the
same three answers (Docker they leave to Docker). They list every item by name and path before
anything moves and send what you choose to the Trash, so any of it can go back. Dependencies
are never ticked for you, a worktree is offered only when git says it is clean and pushed, and
a running AI session is never offered.
First published on deskworthy.app. I make Kempt and DiskAtlas.
來源:DEV Community · dev.to