What is Xcode DerivedData, and is it safe to delete?

Xcode DerivedData is the folder where Xcode keeps build products, project indexes and logs, and it is safe to delete because Xcode rebuilds it on the next build.

Shiva ChandraMaker of Clean House · · 2 min read
Short answer

Xcode DerivedData is the folder where Xcode stores build products, project indexes and logs for every project you open. It is safe to delete. Quit Xcode first, move the folder to the Trash, and Xcode rebuilds what it needs the next time you build. Nothing you wrote lives there.

Path
~/Library/Developer/Xcode/DerivedData
What it is
Build products, indexes and logs for each Xcode project
Typical size
Often several gigabytes, and tens of gigabytes if you open many projects
Made by
Xcode
Safe to delete?
Safe to clear
Comes back?
Yes. The next build recreates it, so the first build afterward is slower

What is in this folder?

Each project you open in Xcode gets its own subfolder named after the project plus a long hash. Inside are the compiled app, intermediate object files, the code index that powers search and autocomplete, and build logs. Apple's Xcode help describes derived data as project indexes, logs and build products, including intermediate build files.

Because every project and every scheme adds its own copy, the folder keeps growing. Projects you deleted years ago can still have a subfolder here.

Is it safe to delete?

Yes. DerivedData is a cache of work Xcode can redo from your source code. Your code, assets and signing settings live in the project, not here. The cost of deleting it is time: the next build recompiles everything, and Xcode re-indexes the project before autocomplete is fully back.

Delete it when Xcode is quitting, not while a build runs. Clearing it mid-build breaks that build. It also fixes odd problems such as stale module caches, which is why it is the classic first step when a build fails for no clear reason.

How do I clear it by hand?

  1. Quit Xcode, and stop any xcodebuild run or CI job on this Mac.
  2. Open Terminal and run the command below, or press Shift-Command-G in Finder, paste the path and drag the folder to the Trash.
  3. Open your project and build. The first build is slow; later ones are normal.
rm -rf ~/Library/Developer/Xcode/DerivedData
Only run this with Xcode closed. To remove a single project, delete just its subfolder instead of the whole folder.

How do I stop it growing?

Xcode has no size cap for DerivedData. Clearing it every few months, or deleting the subfolders of projects you no longer have, keeps it small. You can also point it at another drive in Xcode Settings under Locations.

How Clean House handles it

Clean House recognizes DerivedData as Xcode build files and labels each subfolder with the project it belongs to, noting when that project no longer exists on the Mac. It holds off while Xcode or a build is running, and the folder goes to the Trash, so Recently Cleared can put it back.

Questions

Is it safe to delete Xcode DerivedData?

Yes. It only holds build products, indexes and logs that Xcode regenerates. Quit Xcode first and expect a slower first build afterward.

Where is DerivedData on a Mac?

By default in ~/Library/Developer/Xcode/DerivedData. You can change the location in Xcode Settings under Locations.

Will deleting DerivedData delete my code?

No. Your source code and project files are stored in the project folder, not in DerivedData.

Sources

  1. Apple Xcode Help: Locations settings and derived data