How to safely delete Xcode DerivedData, and what else Xcode leaves behind

Where Xcode stores DerivedData, archives, device support files and simulators on a Mac, which of them are safe to delete, and the commands to do it.

Xcode is usually the largest consumer of disk space on an iOS or macOS developer’s Mac, and most of what it stores can be rebuilt. The trick is knowing which parts are pure cache and which parts you will miss.

Check what you have

du -sh ~/Library/Developer/Xcode/DerivedData \
       ~/Library/Developer/Xcode/Archives \
       ~/Library/Developer/Xcode/iOS\ DeviceSupport \
       ~/Library/Developer/CoreSimulator \
       ~/Library/Caches/com.apple.dt.Xcode 2>/dev/null

What is safe, and what it costs

LocationSafe to delete?Cost
DerivedDataYesThe next build of each project is a full build, and indexing runs again.
iOS DeviceSupportYesXcode copies symbols again the next time you connect a device on that OS version. It takes a few minutes.
ArchivesWith careArchives hold the dSYMs for builds you shipped. Without them you cannot symbolicate crash reports for those versions. Keep the ones that are in users’ hands.
Simulator devicesUnavailable ones, yesNone for devices whose runtime is gone. Deleting a live simulator deletes the apps and data in it.
Simulator runtimesOld onesSeveral gigabytes to download again if you need that OS version.

Do it by hand

Quit Xcode first so it is not writing while you delete.

# Build output and indexes
rm -rf ~/Library/Developer/Xcode/DerivedData/*

# Simulators whose runtime no longer exists
xcrun simctl delete unavailable

# See installed runtimes, then delete one you no longer need
xcrun simctl runtime list
xcrun simctl runtime delete <identifier>

rm -rf does not go through the Trash. Check the path twice; a stray space after ~/Library is how people lose their Library folder.

How Siftaway handles this

Siftaway lists each of these separately with its size and cost, pre-selects DerivedData, leaves Archives and runtimes unselected because they are expensive to get back, and moves whatever you confirm to the Trash so you can put it back.