GitHub Codespaces Storage: Find & Cut Waste
In this article
This guide explains how to see what is consuming storage in a GitHub Codespace and how to delete the files, images, and caches that are wasting space. You will learn the built-in commands to check disk usage, the common culprits behind a full disk, and safe ways to reclaim space without breaking your development environment.
Why Codespaces Run Out of Space
A GitHub Codespace is a Linux virtual machine that runs in the cloud. By default, you get a certain amount of disk space (often 32 GB or more, depending on your plan). This space is shared by the operating system, the tools you installed, your project files, and temporary data. Over time, several things can quietly consume that space:
- Package manager caches – apt, npm, pip, and others store downloaded packages so they can be reinstalled quickly.
- Docker images and containers – if you use Docker, each image and container can take hundreds of MB or more.
- Build artifacts – compiled binaries, node_modules, and .next or .venv folders can be huge.
- Log files – system and application logs accumulate over time.
- Old versions of tools – when you update a tool, the old version may remain on disk.
How to Check Disk Usage in a Codespace
Open a terminal in your Codespace and run the following commands to see what is using space.
- Overall disk usage:
df -h– shows how much space is used and available on the filesystem. - Largest directories in your home folder:
du -h --max-depth=1 ~ 2>/dev/null | sort -hr | head -20– lists the biggest folders in your home directory. - Largest files in the current directory:
find . -type f -size +100M -exec ls -lh {} \;– finds files over 100 MB.
These commands give you a quick overview. The du command is the most useful for identifying which folder is the culprit.
Common Storage Hogs and How to Remove Them
Once you know which directories are large, you can target the usual suspects.
Package Manager Caches
- npm:
npm cache clean --force– clears the npm cache. - pip:
pip cache purge– removes pip's cached wheels. - apt:
sudo apt clean– removes downloaded .deb files. - yarn:
yarn cache clean– clears yarn's cache.
Docker Data
If you use Docker, run docker system prune -a to remove all unused images, containers, and networks. Add --volumes to also delete unused volumes (be careful – this removes data you might need).
Build Artifacts
Delete folders like node_modules (you can reinstall with npm install), .next, dist, build, or .venv if you don't need them right now. If you are not using Docker, you can also remove the Docker images manually with docker rmi.
Log Files
Logs are often in /var/log or ~/.npm/_logs. You can delete old log files with rm or use sudo journalctl --vacuum-size=100M to limit system journal size.
How to Prevent Storage Waste
Prevention is better than cleanup. Here are a few habits that keep your Codespace lean:
- Use a .gitignore file – make sure large build artifacts and dependencies are not committed to the repository.
- Rebuild your Codespace occasionally – if you don't need the current state, you can delete and recreate it from the repository. This gives you a fresh environment.
- Use devcontainer features wisely – only install what you need. Each additional tool takes space.
- Regularly run cleanup commands – add a script that clears caches and old logs.
- Store large files outside the Codespace – use GitHub LFS or a cloud storage service for big assets.
What Happens When You Delete Files?
Deleting files in a Codespace is permanent – there is no recycle bin. Once you remove a file, it is gone from the virtual disk. However, if the file is tracked in Git, you can recover it from the repository history. For untracked files, there is no recovery.
Also note that your Codespace is a temporary environment. If you stop it, the disk is preserved (for a limited time, depending on your plan). But if you delete the Codespace entirely, all local changes are lost. So before deleting anything, make sure your work is committed and pushed.
Comparing Storage Options
GitHub offers different storage limits depending on your plan. For example, free accounts may get 15 GB of storage per month, while Pro accounts get 20 GB, and Team/Enterprise get 50 GB. These limits apply to the total storage used by all your Codespaces. If you hit the limit, you cannot create new Codespaces until you free up space or upgrade.
If you need more space, you have a few options:
- Upgrade your GitHub plan – higher tiers include more storage.
- Use a larger VM type – some VM types come with more disk, but this may be limited to certain plans.
- Reduce your usage – delete old Codespaces and clean up caches regularly.
Frequently Asked Questions
Why is my Codespace disk full even though my project is small?
The disk is shared with the operating system, preinstalled tools, and caches. A small project can still have a large node_modules folder or a Docker image that takes several GB. Use du to find the biggest folders – you'll likely see caches or build artifacts.
Can I increase the disk size of my Codespace?
Not directly. The disk size is determined by your GitHub plan and the VM type you choose. You can switch to a VM with more storage (if available), but you cannot manually expand the disk.
Will deleting node_modules break my project?
No. node_modules is just the installed dependencies. You can reinstall them with npm install (or yarn/pnpm). The only downside is the time it takes to reinstall.
How do I see the storage used by each Codespace?
On the GitHub website, go to Settings → Codespaces to see a list of your Codespaces and their usage. You can also use the gh codespace list command in the terminal.
Is there a way to automatically clean up caches?
You can add a postCreateCommand in your devcontainer.json to run cleanup commands every time the Codespace is created. For example, you can clear the npm cache or remove Docker images.
What is the safest way to free up space?
Start by clearing package manager caches and Docker images – these are safe to remove. Then delete build artifacts that you can regenerate. Always commit your work before deleting anything, so you can recover it from Git if needed.