MacSonar.Our apps
← MacSonar Blog

Is It Safe to Delete Xcode DerivedData? Yes, and Here Is the Cost

DerivedData is often the largest folder a developer has never opened. It is safe to delete, and Xcode recreates it, but the next build of every project will be a full one. Here is what it holds and how to clear it properly.

Yes, it is safe. DerivedData contains only things Xcode generated from your projects: build products, indexes and caches. Your source code, project settings and signing certificates are stored elsewhere. The cost is time: the next build of each project starts from nothing, and Xcode re-indexes the code.

What DerivedData contains

The folder lives at ~/Library/Developer/Xcode/DerivedData. Inside is one subfolder per project or workspace, plus shared caches. Each holds:

Because Xcode never cleans this folder on its own, it keeps data for projects you stopped working on years ago. Tens of gigabytes is common.

How to delete it

  1. Quit Xcode, so it is not writing to the folder.
  2. In Finder choose Go → Go to Folder… and enter ~/Library/Developer/Xcode/DerivedData. You can also open it from Xcode → Settings → Locations, using the arrow beside the Derived Data path.
  3. Move the contents to the Trash. To clear a single project, move only its subfolder.
  4. Open Xcode and build. The folder is recreated.

For one project, Product → Clean Build Folder (Shift-Command-K) inside Xcode removes that project’s build products without touching the others.

What it costs you

The first build of each project afterwards is a clean build, which on a large app can take many minutes. Swift packages are resolved and built again, which may need a network connection. Code completion is limited until indexing finishes. Old build and test logs are gone. Nothing else changes.

So clear it when you need the space or when Xcode is behaving strangely, not as a daily habit.

Other Xcode folders that take space

The same idea for other developer caches

Most build tools keep a similar cache that is safe to remove at the cost of a slower next run: Gradle, CocoaPods, Cargo, pip and npm among them. Before clearing any of them, check which ones are actually big: see how to find large files and folders on a Mac.

See how big each Xcode folder is

Before clearing anything, find out where the space actually is. This read-only command lists the size of each folder Xcode uses:

du -sh ~/Library/Developer/Xcode/* ~/Library/Developer/CoreSimulator ~/Library/Caches/org.swift.swiftpm 2>/dev/null

DerivedData is often the largest, but on Macs used for iOS work, simulators and device support files can be bigger still.

Clear it from Terminal

With Xcode quit, these commands do the same as the Finder steps above. They delete immediately rather than moving items to the Trash, so check each path before pressing Return:

Leave ~/Library/Developer/Xcode/Archives out of any clean-up script; it cannot be recreated.

Quick answers

Will deleting DerivedData delete my project or source code?

No. Your code lives wherever you saved the project. DerivedData holds only files Xcode generated from it.

Does deleting DerivedData fix Xcode problems?

Often. Stale build products and a damaged index cause errors that make no sense, and clearing the folder forces Xcode to rebuild both.

How often should I clear it?

When you need the space or Xcode misbehaves. Clearing it regularly only makes your builds slower.

Working in JavaScript as well? See how to clear the npm cache and old node_modules folders.

Sources

SonarSpaceSee where your Mac’s storage went, and what is safe to remove.

Download free

← More from the MacSonar Blog