<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ali Codes</title>
    <description>The latest articles on DEV Community by Ali Codes (@alicodesdev).</description>
    <link>https://dev.to/alicodesdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4272205%2F36eda738-5e4b-4b11-8f92-6c6e2905eda1.png</url>
      <title>DEV Community: Ali Codes</title>
      <link>https://dev.to/alicodesdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alicodesdev"/>
    <language>en</language>
    <item>
      <title>What deleting a file really frees on a Mac: APFS clones, hard links and iCloud placeholders</title>
      <dc:creator>Ali Codes</dc:creator>
      <pubDate>Sun, 29 Nov 2026 15:36:17 +0000</pubDate>
      <link>https://dev.to/alicodesdev/what-deleting-a-file-really-frees-on-a-mac-apfs-clones-hard-links-and-icloud-placeholders-41gb</link>
      <guid>https://dev.to/alicodesdev/what-deleting-a-file-really-frees-on-a-mac-apfs-clones-hard-links-and-icloud-placeholders-41gb</guid>
      <description>&lt;p&gt;On a Mac, the size a tool shows for a folder and the space you get back when you delete it are often two different numbers. &lt;code&gt;du&lt;/code&gt; and Finder add up the blocks each file uses, but APFS lets files share blocks, hard links let one file live at several paths, and iCloud can leave a file on disk that holds nothing at all.&lt;/p&gt;

&lt;p&gt;Here are the three cases, how to see each one for yourself, and how to measure them from code.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. APFS clones: two files, one copy of the data
&lt;/h2&gt;

&lt;p&gt;On APFS, a copy can be a clone: a second file that points at the same blocks as the first until one of them changes. Finder's Duplicate makes clones, &lt;code&gt;cp -c&lt;/code&gt; makes them, and so do package managers: pnpm, Bun and uv clone packages from their store into each project's folder on APFS.&lt;/p&gt;

&lt;p&gt;Each clone still reports its full size, so &lt;code&gt;du&lt;/code&gt; counts the same data twice. Try it in a folder of your own:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dd &lt;span class="nv"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/urandom &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;a.bin &lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1m &lt;span class="nv"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1024   &lt;span class="c"&gt;# 1 GB of real data&lt;/span&gt;
df -h .                                        &lt;span class="c"&gt;# note the free space&lt;/span&gt;
cp -c a.bin b.bin                              &lt;span class="c"&gt;# clone it&lt;/span&gt;
du -sh a.bin b.bin                             &lt;span class="c"&gt;# 1.0G each&lt;/span&gt;
df -h .                                        &lt;span class="c"&gt;# free space barely moved&lt;/span&gt;
rm a.bin b.bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete &lt;code&gt;b.bin&lt;/code&gt; alone and you get almost nothing back, because &lt;code&gt;a.bin&lt;/code&gt; still needs those blocks. A folder full of clones can look like gigabytes in &lt;code&gt;du&lt;/code&gt; and free a few megabytes.&lt;/p&gt;

&lt;p&gt;Since macOS 10.15, APFS tells you how much of a file no clone shares, through &lt;code&gt;getattrlist&lt;/code&gt; and the extended attribute &lt;code&gt;ATTR_CMNEXT_PRIVATESIZE&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Darwin&lt;/span&gt;

&lt;span class="c1"&gt;/// Bytes of this file that no clone shares: what deleting this one file gives back.&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;privateSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Int64&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;attrs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;attrlist&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;attrs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bitmapcount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;u_short&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;ATTR_BIT_MAP_COUNT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;attrs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;forkattr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;attrgroup_t&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;ATTR_CMNEXT_PRIVATESIZE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;// The reply is a UInt32 length, then the size as an off_t.&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;UInt8&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;repeating&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;UInt32&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;FSOPT_NOFOLLOW&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="no"&gt;FSOPT_ATTR_CMN_EXTENDED&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;guard&lt;/span&gt; &lt;span class="nf"&gt;getattrlist&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;attrs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;withUnsafeBytes&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loadUnaligned&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fromByteOffset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Int64&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kc"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;FSOPT_ATTR_CMN_EXTENDED&lt;/code&gt;, the &lt;code&gt;forkattr&lt;/code&gt; field asks for extended common attributes. Use &lt;code&gt;min(st_blocks * 512, privateSize)&lt;/code&gt; as the file's real cost.&lt;/p&gt;

&lt;p&gt;One catch: private size answers "what if I delete only this file". Two files cloned from each other each report almost no private size, yet deleting both frees the whole thing. So it's the right number for a file you'd remove while its twin stays, like a project's copy of a package whose original lives in the package store, and the wrong one for adding up a group of files that only share blocks with each other.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Hard links: one file, several paths
&lt;/h2&gt;

&lt;p&gt;A hard link is a second name for the same file. Deleting one name frees nothing while another remains. &lt;code&gt;stat&lt;/code&gt; gives you the count in &lt;code&gt;st_nlink&lt;/code&gt;, and &lt;code&gt;(st_dev, st_ino)&lt;/code&gt; identifies the file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;du&lt;/code&gt; counts a hard-linked file once per run, which is right inside the folder you asked about, but it can't know about the other link outside that folder. To know what deleting a set of paths frees, count a file with &lt;code&gt;st_nlink &amp;gt; 1&lt;/code&gt; only once you've seen every one of its links inside that set:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;Inode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Hashable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;dev&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Int32&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;ino&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;UInt64&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Inode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Int64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;links&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;found&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;// For each regular file in the paths you plan to delete:&lt;/span&gt;
&lt;span class="c1"&gt;//   if st.st_nlink &amp;gt; 1, bump seen[Inode(dev: st.st_dev, ino: UInt64(st.st_ino))].found&lt;/span&gt;
&lt;span class="c1"&gt;// Afterwards, a file frees its bytes only when found == links.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;pnpm falls back to hard links where it can't clone, so this matters for node_modules too.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. iCloud placeholders: a file that holds nothing
&lt;/h2&gt;

&lt;p&gt;With Optimize Mac Storage on, iCloud Drive keeps some files only in the cloud. They still show up in folders, but the file on disk is a placeholder marked with the flag &lt;code&gt;SF_DATALESS&lt;/code&gt; (&lt;code&gt;0x40000000&lt;/code&gt; in &lt;code&gt;sys/stat.h&lt;/code&gt;), and it takes no space.&lt;/p&gt;

&lt;p&gt;The trap is that looking can cost more than deleting. Reading inside a cloud-only folder or package makes macOS download it first, so a scanner that walks every folder can pull gigabytes back from iCloud, onto the disk it's trying to free, and stall while it waits.&lt;/p&gt;

&lt;p&gt;You can turn that off for your own process, so such a read fails instead of downloading:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Once, at launch: never download cloud-only files for this process.&lt;/span&gt;
&lt;span class="nf"&gt;setiopolicy_np&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;IOPOL_TYPE_VFS_MATERIALIZE_DATALESS_FILES&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="no"&gt;IOPOL_SCOPE_PROCESS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="no"&gt;IOPOL_MATERIALIZE_DATALESS_FILES_OFF&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then skip any folder whose &lt;code&gt;st_flags&lt;/code&gt; has &lt;code&gt;SF_DATALESS&lt;/code&gt; while you walk, for example with &lt;code&gt;fts_set(fts, ent, FTS_SKIP)&lt;/code&gt; when you use &lt;code&gt;fts&lt;/code&gt;. In Terminal, the same idea is &lt;code&gt;find ~ -flags +dataless -prune -o …&lt;/code&gt; so &lt;code&gt;find&lt;/code&gt; never steps inside.&lt;/p&gt;

&lt;p&gt;A related surprise: removing the download of an iCloud file you have on disk often doesn't change the free space Finder shows, because macOS already counts downloaded iCloud files as purgeable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Putting it together
&lt;/h2&gt;

&lt;p&gt;For each file in what you plan to delete: skip cloud-only folders without opening them, take the smaller of its blocks and its private size, and count a hard-linked file only when every link is in the set. That's the number you'll actually see come back in &lt;code&gt;df&lt;/code&gt;.&lt;/p&gt;




&lt;p&gt;Disclosure: I make &lt;a href="https://diskwise.app/" rel="noopener noreferrer"&gt;Diskwise&lt;/a&gt;, a Mac menu bar app for disk space that sizes things this way, so the sizes it shows are what you get back and its scan never downloads anything from iCloud. The scan is free. Claude Code wrote its code; I decide what it does.&lt;/p&gt;

</description>
      <category>macos</category>
      <category>swift</category>
      <category>apple</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to shrink Docker's disk image on a Mac and get the space back</title>
      <dc:creator>Ali Codes</dc:creator>
      <pubDate>Sun, 29 Nov 2026 14:49:02 +0000</pubDate>
      <link>https://dev.to/alicodesdev/how-to-shrink-dockers-disk-image-on-a-mac-and-get-the-space-back-53fm</link>
      <guid>https://dev.to/alicodesdev/how-to-shrink-dockers-disk-image-on-a-mac-and-get-the-space-back-53fm</guid>
      <description>&lt;p&gt;On a Mac, Docker Desktop keeps every image, container, volume and build cache in one disk image, so macOS sees a single big file. To make it smaller, you clear things out from inside Docker, and Docker hands the space back.&lt;/p&gt;

&lt;h2&gt;
  
  
  See how big it really is
&lt;/h2&gt;

&lt;p&gt;The disk image is &lt;code&gt;Docker.raw&lt;/code&gt;, in &lt;code&gt;~/Library/Containers/com.docker.docker/Data/vms/0/data&lt;/code&gt;. Many tools show the most it may grow to, not the space it really takes. This shows both:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ls -klsh ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first number is what it takes on your disk, and the size further along the line is its limit. Docker Desktop shows the same under Settings &amp;gt; Resources &amp;gt; Advanced. To see what fills it, by images, containers, volumes and build cache:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker system df
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Clear out what you don't use
&lt;/h2&gt;

&lt;p&gt;This removes stopped containers, networks no container uses, dangling images and build cache. Docker says what it will remove and asks before it does:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker system prune
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add &lt;code&gt;-a&lt;/code&gt; to remove every image no container uses as well. Images download again the next time you need them, so it only costs time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker system prune -a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Neither touches volumes, where your containers keep databases and other data. &lt;code&gt;docker volume ls&lt;/code&gt; lists them, and &lt;code&gt;docker volume rm&lt;/code&gt; followed by a name deletes one you're sure about.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get the space back
&lt;/h2&gt;

&lt;p&gt;After a prune, it can take a few minutes for the space to show up as free on your Mac. To have Docker hand it back right away:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run --privileged --pid=host docker/desktop-reclaim-space
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deleting files inside a running container doesn't free space on your Mac; pruning does.&lt;/p&gt;

&lt;p&gt;To keep the image from growing as large again, lower its limit under Settings &amp;gt; Resources &amp;gt; Advanced. Lowering it deletes the disk image and everything in it, so Docker can start a smaller one: prune first, and lower it only if you can rebuild what's inside.&lt;/p&gt;

&lt;h2&gt;
  
  
  If you use Diskwise
&lt;/h2&gt;

&lt;p&gt;Disclosure: I make &lt;a href="https://diskwise.app/" rel="noopener noreferrer"&gt;Diskwise&lt;/a&gt;, a Mac menu bar app for disk space. Its free scan shows Docker's disk image when Docker Desktop is installed. It's Your call, and stays unticked: ticking it moves the whole image to the Trash, with every container, image and volume inside it. That's only worth it once you're done with Docker, and with Docker Desktop quit. While you still use Docker, prune from inside it as above.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;First published at &lt;a href="https://diskwise.app/guides/docker-disk-space" rel="noopener noreferrer"&gt;diskwise.app/guides/docker-disk-space&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>macos</category>
      <category>devops</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How to free up Xcode disk space on a Mac</title>
      <dc:creator>Ali Codes</dc:creator>
      <pubDate>Sun, 29 Nov 2026 11:49:53 +0000</pubDate>
      <link>https://dev.to/alicodesdev/how-to-free-up-xcode-disk-space-on-a-mac-35h7</link>
      <guid>https://dev.to/alicodesdev/how-to-free-up-xcode-disk-space-on-a-mac-35h7</guid>
      <description>&lt;p&gt;Xcode keeps build data for every project you open, simulators for every device you try, and support files for every iPhone and iOS version you build to, and it seldom deletes any of them. Here's what each part is, which parts are safe to delete, and how.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the space goes
&lt;/h2&gt;

&lt;p&gt;Nearly all of it is in &lt;code&gt;~/Library/Developer&lt;/code&gt;, a folder Finder hides. Here's what's inside, from the safest to delete to the ones to think about first.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What&lt;/th&gt;
&lt;th&gt;Where&lt;/th&gt;
&lt;th&gt;Safe to delete?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Build data (DerivedData)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;~/Library/Developer/Xcode/DerivedData&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes. Indexes, build products and logs for every project you've opened. Xcode makes it again on the next build.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Simulator caches&lt;/td&gt;
&lt;td&gt;&lt;code&gt;~/Library/Developer/CoreSimulator/Caches&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes. Rebuilt when a simulator next starts.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;iOS device support files&lt;/td&gt;
&lt;td&gt;&lt;code&gt;~/Library/Developer/Xcode/iOS DeviceSupport&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Rebuildable. A folder for each iPhone model and iOS version you've built to. Xcode copies the one it needs again when that iPhone connects.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Simulators&lt;/td&gt;
&lt;td&gt;&lt;code&gt;~/Library/Developer/CoreSimulator/Devices&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Your call. Every simulator, with the apps you ran on it and their data. Those for an iOS version you've removed can't start, and are safe to delete.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Archives&lt;/td&gt;
&lt;td&gt;&lt;code&gt;~/Library/Developer/Xcode/Archives&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Your call. Every build you archived for TestFlight or the App Store, with the symbols that make its crash reports readable.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Simulator runtimes, the copies of iOS and Apple's other systems that simulators run, live outside your home folder and are often the biggest of all. They have a section of their own below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clear DerivedData
&lt;/h2&gt;

&lt;p&gt;DerivedData is safe to delete whenever Xcode isn't building. Quit Xcode, then run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rm -rf ~/Library/Developer/Xcode/DerivedData
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Xcode makes the folder again, and the next build of each project takes longer, as it indexes and compiles everything from scratch. To clear one project's build instead, choose Product &amp;gt; Clean Build Folder in Xcode, or press Shift-Command-K.&lt;/p&gt;

&lt;p&gt;If you've moved DerivedData, Xcode &amp;gt; Settings &amp;gt; Locations shows where it is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Delete simulators you don't use
&lt;/h2&gt;

&lt;p&gt;Each simulator keeps its own copy of the apps you've run on it, and their data. Those made for an iOS version you've since removed can't start any more, and this deletes all of them at once:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;xcrun simctl delete unavailable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see every simulator with its iOS version and ID, run &lt;code&gt;xcrun simctl list devices&lt;/code&gt;. Delete one you no longer use with &lt;code&gt;xcrun simctl delete&lt;/code&gt; followed by its ID, or in Xcode under Window &amp;gt; Devices and Simulators.&lt;/p&gt;

&lt;h3&gt;
  
  
  SwiftUI previews
&lt;/h3&gt;

&lt;p&gt;Previews keep simulators of their own in &lt;code&gt;~/Library/Developer/Xcode/UserData/Previews&lt;/code&gt;, which the commands above leave alone. This deletes them, and Xcode makes new ones the next time a preview runs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;xcrun simctl --set previews delete all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Remove runtimes you don't build for
&lt;/h2&gt;

&lt;p&gt;A runtime is the copy of iOS, watchOS, tvOS or visionOS that simulators run, and each takes several gigabytes. To remove one, open Xcode &amp;gt; Settings &amp;gt; Components, find it under Other Installed Platforms, click the info button beside it and click Delete.&lt;/p&gt;

&lt;p&gt;From Terminal, this lists the runtimes with their identifiers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;xcrun simctl runtime list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then &lt;code&gt;xcrun simctl runtime delete&lt;/code&gt; followed by an identifier removes that one. Keep the newest runtime of each platform you build for: Xcode needs the current one to build, though your apps still run on older ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  Delete old iPhone support files
&lt;/h2&gt;

&lt;p&gt;The first time you build to an iPhone on a new iOS version, Xcode copies support files for that version to your Mac, and it keeps every version it has copied. Each folder is named for the iPhone model and the iOS version, with its build number.&lt;/p&gt;

&lt;p&gt;Xcode only uses the folder for the version each iPhone runs now. This opens them in Finder, so you can move the older ones to the Trash:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;open ~/Library/Developer/Xcode/iOS\ DeviceSupport
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you delete the current one too, Xcode copies it back the next time that iPhone connects, which takes a while.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep only the archives you need
&lt;/h2&gt;

&lt;p&gt;Each time you archive a build for TestFlight or the App Store, Xcode keeps it, along with its debug symbols, the dSYM files that turn a crash report from that version into something you can read. Archives of versions nobody runs any more can go.&lt;/p&gt;

&lt;p&gt;You can look through them in Xcode under Window &amp;gt; Organizer. To move the ones you don't need to the Trash, this opens their folder in Finder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;open ~/Library/Developer/Xcode/Archives
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  If you'd rather not do this by hand
&lt;/h2&gt;

&lt;p&gt;Disclosure: I make &lt;a href="https://diskwise.app/" rel="noopener noreferrer"&gt;Diskwise&lt;/a&gt;, a Mac menu bar app for exactly this. Its free scan finds everything in the list above and sorts it the same way. Build data and simulator caches are Safe to clear. Support files for iOS versions your iPhone has updated past, and simulators that can't start, get Safe to clear rows of their own.&lt;/p&gt;

&lt;p&gt;Archives and the simulators that still work are Your call: they stay unticked until you tick them, and they go to the Trash, not straight to deletion. Auto clean never touches build data while Xcode or a command-line build is running.&lt;/p&gt;

</description>
      <category>xcode</category>
      <category>ios</category>
      <category>macos</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
