Xcode
DerivedData
MacOS
Developer tips
Disk cleanup

How can I safely delete in my /Library/Developer/Xcode/DerivedData directory?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

DerivedData is Xcode's scratch space for build products, indexes, logs, and other generated artifacts. If the directory grows to many gigabytes, it is usually safe to delete, and doing so often fixes stale-build and indexing problems at the same time.

What Lives in DerivedData

Xcode stores generated files under ~/Library/Developer/Xcode/DerivedData. These files are not your source code. They are rebuildable caches such as:

  • compiled intermediates
  • indexing data for code completion
  • simulator-related build output
  • logs and temporary metadata

Because the contents are generated, deleting them does not remove your project files or your Git history. The tradeoff is that the next build may take longer because Xcode has to regenerate everything.

The Safe Way to Clean It

The simplest rule is: close Xcode first, then remove only DerivedData, not neighboring folders you do not understand.

From Terminal:

bash
rm -rf ~/Library/Developer/Xcode/DerivedData/*

If you want to inspect usage before deleting:

bash
du -sh ~/Library/Developer/Xcode/DerivedData
du -sh ~/Library/Developer/Xcode/DerivedData/*

You can also remove only one project's cache if you recognize the folder name:

bash
ls ~/Library/Developer/Xcode/DerivedData
rm -rf ~/Library/Developer/Xcode/DerivedData/MyApp-abcdxyz1234

That is useful when one project is misbehaving but you do not want to force full rebuilds for everything else.

Cleaning Through Xcode

You do not have to use the shell. Xcode can also remove build artifacts through its UI. For some issues, "Clean Build Folder" is enough because it clears the active target's build output without wiping every cached project.

That distinction matters:

  • "Clean Build Folder" is narrower and less disruptive.
  • deleting DerivedData is broader and resets indexes and caches too.

If code completion is broken, indexing is stale, or an old build setting seems to stick around, deleting DerivedData is often the better reset.

What Not to Delete Carelessly

The path ~/Library/Developer/Xcode contains more than DerivedData. For example, other subdirectories may hold archives, device support files, or simulator data. Those can be deleted in some cases too, but they have different consequences.

So the safe advice is specific:

  • deleting ~/Library/Developer/Xcode/DerivedData is normally fine
  • deleting the whole ~/Library/Developer/Xcode tree blindly is not a good habit

Precision matters here because a broad cleanup can remove items that are expensive to restore.

When Deleting Helps

Removing DerivedData is a good troubleshooting step when:

  • Xcode reports impossible compile errors after a branch switch
  • SwiftUI previews refuse to refresh
  • autocomplete and symbol navigation are obviously stale
  • a build keeps using output from an older configuration

In those cases, the issue is often cache corruption rather than a real code problem.

Common Pitfalls

The most common mistake is deleting DerivedData while Xcode is still actively building or indexing. Usually that just causes noise, but it is cleaner to quit Xcode first.

Another mistake is assuming this folder contains precious project data and avoiding cleanup forever. That leads to wasted disk space and slower diagnostics when caches go bad.

A third issue is overusing deletion as a reflex. If you have repeatable build failures caused by a bad script phase, broken signing configuration, or incompatible package state, clearing DerivedData will only mask the symptom temporarily.

Summary

  • 'DerivedData contains generated Xcode artifacts, not source code.'
  • It is generally safe to delete, especially with Xcode closed.
  • Removing one project folder is a good middle ground when only one app is affected.
  • Do not blindly delete the entire ~/Library/Developer/Xcode directory.
  • Use cleanup as a troubleshooting tool, not as a substitute for fixing real build issues.

Course illustration
Course illustration