DEV Community

Cover image for Xcode is eating your disk: clearing DerivedData, archives and old simulators safely
MagioApps
MagioApps

Posted on AI-assisted

Xcode is eating your disk: clearing DerivedData, archives and old simulators safely

If you build for Apple platforms, Xcode is probably the single biggest tenant on your disk. Not the app itself: everything it leaves behind. Build products for every project you've ever opened, symbol files for every iPhone you've ever plugged in, simulators for OS versions you stopped testing two years ago.

The good news: most of it is rebuildable. The bad news: one folder in the mix is not, and it looks just as deletable as the rest.

Here's a tour, with commands that work on macOS 11 Big Sur and later on Apple silicon. Quit Xcode and the Simulator app before you start.

First, measure

Don't delete blind. This is read-only:

du -sh ~/Library/Developer/Xcode/* \
       ~/Library/Developer/CoreSimulator \
       ~/Library/Caches/com.apple.dt.Xcode 2>/dev/null | sort -h
Enter fullscreen mode Exit fullscreen mode

You'll typically see some of these:

Folder What it is Verdict
Xcode/DerivedData Build products, indexes, intermediate files Safe: rebuilt on next build
Xcode/iOS DeviceSupport (and watchOS, tvOS) Symbols copied from devices you've connected Mostly safe: re-copied when needed
CoreSimulator/Devices Your simulators and their data Safe-ish: delete what you don't use
Xcode/UserData/Previews Simulators used for SwiftUI previews Safe: recreated
Caches/com.apple.dt.Xcode Xcode's own cache Safe
Xcode/Archives Builds you shipped, with their debug symbols Your call: keep the live ones

Let's go through them.

1. DerivedData: the big, safe one

~/Library/Developer/Xcode/DerivedData holds a folder per project with compiled objects, module caches, index data and build logs. It grows with every project and every branch you build, and nothing ever cleans it up by default.

Deleting it is safe. The cost is time: your next build of each project is a full, clean build, and Xcode re-indexes, so autocomplete is sluggish for a few minutes.

One project only. In Xcode, Product > Clean Build Folder (Shift-Command-K) clears that project's build folder.

Everything, from Finder. Xcode > Settings > Locations shows the DerivedData path with a small arrow to open it in Finder. Drag the project folders you don't need to the Trash.

Everything, from Terminal:

rm -rf ~/Library/Developer/Xcode/DerivedData/*
Enter fullscreen mode Exit fullscreen mode

Note the /*: it empties the folder rather than deleting it. And triple-check the path before you press Return. rm -rf has no undo, which is fine for DerivedData and terrible for a typo.

A side benefit: clearing DerivedData is also the classic fix for strange "it builds on my colleague's Mac" errors and stale indexing.

2. Device support files

Each time you connect an iPhone or iPad running an iOS version Xcode hasn't seen, it copies that version's symbols into ~/Library/Developer/Xcode/iOS DeviceSupport. Each folder can be gigabytes, and they pile up release after release.

You can delete folders for OS versions you no longer debug on. If you connect a device with that version again, Xcode copies the symbols again (it takes a while, but nothing is lost). The same applies to the watchOS DeviceSupport and tvOS DeviceSupport folders if you have them.

3. Simulators and runtimes

Simulators are sneaky because each one has its own installed apps, caches and data, and old ones linger after you've removed the runtime they belong to.

See what you have:

xcrun simctl list devices
Enter fullscreen mode Exit fullscreen mode

Remove simulators whose runtime is no longer installed (they can't boot anyway):

xcrun simctl delete unavailable
Enter fullscreen mode Exit fullscreen mode

Reset a simulator's contents without deleting it:

xcrun simctl erase <device-udid>
Enter fullscreen mode Exit fullscreen mode

Clear the simulators Xcode uses for SwiftUI previews:

xcrun simctl --set previews delete all
Enter fullscreen mode Exit fullscreen mode

The simulator runtimes themselves (whole iOS versions) are separate, and often the largest items. In recent Xcode versions you manage them in Xcode > Settings > Platforms (renamed Components in newer releases): select an old runtime and remove it. With Xcode 15 or later you can also do it from Terminal:

xcrun simctl runtime list
xcrun simctl runtime delete <runtime-identifier>
Enter fullscreen mode Exit fullscreen mode

Before deleting a runtime, check your deployment target. If your app still supports an older iOS, you may want one simulator on that version.

4. Caches

~/Library/Caches/com.apple.dt.Xcode is Xcode's own cache. Safe to delete with Xcode closed.

If you use Swift Package Manager, ~/Library/Caches/org.swift.swiftpm holds downloaded package repositories. Also safe: packages are fetched again on the next resolve. Expect the first build afterwards to take longer, especially offline.

5. Archives: the one to think about

~/Library/Developer/Xcode/Archives looks like more build output. It isn't.

Each archive is a build you distributed, together with its dSYM files: the debug symbols that turn a crash report's memory addresses back into function names and line numbers. Delete the archive for a version that's still in your users' hands, and you may lose the ability to read that version's crash reports, unless you've stored the dSYMs somewhere else.

Sensible rule: keep archives for every version that's still live. Delete archives for builds that never shipped, test builds, and versions long retired. Use Window > Organizer > Archives in Xcode, which shows the version and date for each, and right-click > Delete.

6. Old copies of Xcode

If you keep a second Xcode for an older toolchain (Xcode-15.app next to Xcode.app), that's many gigabytes. Your call, but make sure no project or CI script still points at it via xcode-select or DEVELOPER_DIR.

A sane routine

  • Monthly: clear DerivedData, run xcrun simctl delete unavailable.
  • After each major iOS release: remove old DeviceSupport folders and runtimes you no longer target.
  • After each App Store release: prune archives for retired versions, keep the live ones.

Doing it without Terminal

If you'd rather not keep this routine in your head, that's the job we built Ample for: a native Mac disk cleaner that knows these folders by name.

Ample sorts what it finds into three colours. DerivedData sits in Safe (green), next to ~/Library/Caches, logs, node_modules, npm and Cargo caches and old installers: things that regenerate by themselves. Xcode Archives sit in Important (amber): shown to you, never removed for you, exactly because of the dSYM problem above. And folders like .git, .ssh and your Keychains are Critical: never touched.

Only green can ever be cleaned. Cleaning moves items to a quarantine first, with Undo at any time, and you purge when you're sure. Each item is re-checked right before it's touched. Ample also has Tools for old simulators, Homebrew cleanup, Docker space and Time Machine snapshots, plus a Space Map and a Large Files finder.

Scanning is free, unlimited and read-only. Cleaning, the Space Map, Large Files and Tools are in Pro, $10 once. No account, no analytics in the app, and your files never leave your Mac. It needs macOS 11 or later on Apple silicon (M1 or later).

Curious how much your Xcode is hoarding? Download Ample free and see how much space you can get back in about a minute.

Top comments (8)

Collapse
 
diskbee profile image
DiskBee(NTFS for Mac) •

For Archives, I would make the retention key the dSYM UUID rather than only the marketing version or build number. Before pruning, xcrun dwarfdump --uuid /path/to/App.app.dSYM prints the UUID for each architecture; it must match the binary-image UUID in the crash report. That also makes the backup test concrete: move an archive aside, verify that every still-supported build has its matching dSYM elsewhere, then delete. A rebuilt 1.2 (34) is not necessarily symbol-compatible with the original 1.2 (34), even when the source looks identical.

Collapse
 
xenoci_com profile image
xenoci.com •

Keying on the dSYM UUID is cleaner, agreed. Build numbers get reused more often than people expect, especially when a CI job and a local archive both bump from the same base. Do you keep the dSYMs next to the archive, or upload them somewhere and only prune locally once the upload is confirmed?

Collapse
 
diskbee profile image
DiskBee(NTFS for Mac) •

I would keep the dSYM inside the .xcarchive as the working copy, and treat an uploaded symbol store as the retention copy. Before pruning locally, verify the uploaded object rather than relying on a successful upload response: compare the dSYM UUID with xcrun dwarfdump --uuid /path/to/App.app.dSYM, and, if the service allows retrieval, download it and compare the complete file hash as well.

The important boundary is recoverability. Keep the archive-local copy until every still-supported binary image has a matching, retrievable dSYM. A version/build match or an upload log entry alone does not prove that a later crash report can be symbolicated. I cannot speak to your storage backend, but I would also test one restore before deleting the only local copy.

Thread Thread
 
xenoci_com profile image
xenoci.com • • Edited

The restore test is the part most setups skip, and it's cheap to make real: take a crash report from an older build, pull its dSYM back from the store into an empty folder, and run atos -arch arm64 -o App.app.dSYM/Contents/Resources/DWARF/App -l <load address> <frame address> on one frame. If that prints a function and line, the copy is good; a UUID match alone can still hide a truncated or Bitcode-era placeholder dSYM.

The Bitcode point matters for anyone with old builds: dSYMs from Bitcode-enabled archives were regenerated by Apple, so the local one never matched. Those are worth pulling from App Store Connect once and storing with the rest before Xcode stops listing them.

Thread Thread
 
diskbee profile image
DiskBee(NTFS for Mac) •

That is a better acceptance test than comparing UUIDs alone. I would keep the crash report beside the retrieved dSYM and record both the binary-image UUID and the exact atos invocation used. A successful lookup proves that the selected image, load address, and frame can be symbolicated; it does not prove that every dSYM in the archive was restored. For an archive containing frameworks or extensions, I would repeat the check for each binary image that still has support value before deleting the only local copy.

Thread Thread
 
xenoci_com profile image
xenoci.com •

Good point on extensions. Widgets and notification service extensions each ship their own dSYM with their own UUID, and those are the ones that go missing because nobody looks at their crashes until a widget starts dying. Looping over every .dSYM in the archive and running the atos check per image would cover it in a few lines of shell.

Thread Thread
 
diskbee profile image
DiskBee(NTFS for Mac) •

I would drive that loop from the binary images in the archive and their UUIDs, not treat find ... -name "*.dSYM" as proof of coverage. The crash report selects which architecture UUID matters. A useful retention check would emit image path -> dwarfdump UUIDs -> one atos result and fail when a still-supported binary image has no matching dSYM. That also catches an entirely missing extension dSYM, which a loop limited to files that happen to exist would silently skip.

Collapse
 
xenoci_com profile image
xenoci.com •

Good call flagging Archives as the one that isn't rebuildable. Losing the dSYMs for a version that's still live is how a crash report turns into hex addresses. Two that bit me on top of your list: xcrun simctl delete unavailable clears simulators whose runtime is already gone, and old runtimes themselves sit outside CoreSimulator/Devices, so xcrun simctl runtime list is worth a look too. Do you keep archives only for versions still on the store, or a fixed count?