If you have downloaded models, datasets, or other files from Hugging Face, they may be taking up space on your computer. The good news is that you can clear the Hugging Face cache without uninstalling Transformers or the Hugging Face Hub. You can remove selected downloads with the Hugging Face command-line tool, use Python to delete specific cached revisions, or remove cache folders manually. This guide explains each method, where the files are stored, and how to avoid deleting something you still need.
What Is the Hugging Face Cache?
The Hugging Face cache stores files downloaded from the Hub so they can be reused. For example, when you load a model with Transformers, the model files are typically downloaded once and then read from the cache on later runs. Dataset files and other Hub downloads can also be cached.
Caching saves time and bandwidth, but it can use considerable disk space—especially if you have tried several large models. Clearing the cache removes downloaded cache data. It does not usually uninstall Python packages, delete your project files, or remove model files that you separately saved to another location.
The Hub cache uses a structure that may include snapshots, references, and shared data files. Because some files are shared between revisions, deleting individual files by hand can be confusing. For most users, the Hugging Face cache command is the safest place to start.
Find Your Hugging Face Cache Location
The default Hub cache directory depends on your operating system:
-
Linux and macOS:
~/.cache/huggingface/hub -
Windows:
C:\Users\YOUR_USERNAME\.cache\huggingface\hub
The tilde symbol in the Linux and macOS path refers to your home folder. On Windows, replace YOUR_USERNAME with your Windows account name. Your setup may use a different location if you or your organization configured a custom cache path.
The HF_HOME environment variable changes the main Hugging Face data directory. The HF_HUB_CACHE variable can set the Hub cache directory directly. Check these variables if you cannot find the files in the default location. In Python, you can inspect them with:
import os
print("HF_HOME:", os.environ.get("HF_HOME"))
print("HF_HUB_CACHE:", os.environ.get("HF_HUB_CACHE"))
Other Hugging Face libraries may use related cache directories. For instance, dataset processing files may be stored separately from Hub model downloads. Changing or clearing the Hub cache does not necessarily clear every cache used by every library.
Check How Much Space the Cache Uses
Before clearing anything, you may want to see which cached repositories are taking up space. The current Hugging Face CLI includes a cache scanning command. Open a terminal or command prompt and run:
hf cache scan
The report lists cached repositories and revisions, along with information such as their size and local path. If the hf command is not recognized, install or update the Hugging Face Hub package in the Python environment you use:
python -m pip install -U huggingface_hub
Then close and reopen your terminal and try the scan command again. If you use a virtual environment, activate it first so the command is available in the right environment.
Clear the Cache with the Hugging Face CLI
To remove cached files using the recommended interactive approach, run:
hf cache delete
Follow the prompts to choose which repositories or revisions to delete, review the proposed changes, and confirm. This lets you clear only selected downloads instead of removing every cached model and dataset. Read the selection carefully before confirming, particularly if you work with several projects or share a machine with other users.
To clear the entire Hub cache, select all the entries presented by the tool and confirm the deletion. The exact prompts may vary depending on your installed version of huggingface_hub. If you are unsure what will be removed, run hf cache scan first and use the interactive deletion process rather than deleting folders immediately.
Some older installations use the previous command-line interface. If hf cache is unavailable, try updating huggingface_hub. Older versions may provide commands such as huggingface-cli scan-cache and huggingface-cli delete-cache. The available commands depend on your package version, so you can check the help output with:
hf cache --help
Delete Specific Revisions with Python
If you want to automate cache cleanup, the huggingface_hub Python library can scan the cache and prepare a deletion strategy for particular revisions. This is useful for scripts or workflows where you want more control than a full cache wipe.
from huggingface_hub import scan_cache_dir
cache_info = scan_cache_dir()
for repo in cache_info.repos:
print(repo.repo_id, repo.size_on_disk)
# Replace this value with a revision hash shown in your cache information.
revision_to_delete = "YOUR_REVISION_HASH"
strategy = cache_info.delete_revisions(revision_to_delete)
print(strategy.expected_freed_size)
# Run only after checking that the selected revision is safe to remove.
strategy.execute()
Review the revision information and expected freed space before calling execute(). A revision may be needed by a local workflow, and cache entries can share files. If your goal is simply to free space, the interactive CLI is often easier and less error-prone than writing a deletion script.
Remove the Hub Cache Manually
You can also delete the Hub cache folder using your operating system’s file manager or a terminal. First, make sure no Python script, notebook, training job, or application is currently downloading from or loading files in the cache. Then remove the Hub directory at the relevant path.
On Linux or macOS, the default Hub cache can be removed from a terminal with:
rm -rf ~/.cache/huggingface/hub
This command permanently removes the specified folder, so check the path carefully before running it. To use a graphical file manager instead, navigate to your home directory, open .cache/huggingface, and move the hub folder to the trash.
On Windows, open File Explorer, enter %USERPROFILE%\.cache\huggingface in the address bar, and delete the hub folder. If your cache is in a custom location, use that path instead. Avoid deleting the whole .cache or huggingface directory unless you intend to remove other cached data stored there as well.
Manual deletion is straightforward, but it does not give you the same repository-by-repository review as the CLI. Do not remove files while an application is using them. If you see a permission error, close the relevant processes and check that you have permission to modify the directory rather than changing permissions broadly.
Clear Dataset and Other Hugging Face Caches
Deleting ~/.cache/huggingface/hub removes Hub downloads stored there, but it may not remove every dataset-related cache. The Datasets library can keep processed data in its own cache directory, commonly under ~/.cache/huggingface/datasets on Linux and macOS. Its location can be affected by settings such as HF_HOME and HF_DATASETS_CACHE.
If you use the Hugging Face Datasets library, you can inspect its cache with the library’s cache utilities. For example, the following code reports cache files known to the current Datasets installation:
from datasets import Dataset
print(Dataset.cache_files)
The result depends on the dataset object and how it was loaded. You can also check the cache directory in the application or environment configuration that created the data. Before removing dataset cache files, confirm that they can be regenerated or downloaded again. Deleting them may make the next run slower or require another download.
Some tools also use their own cache settings. If files remain after clearing the Hub directory, check the documentation for the specific library or application rather than assuming all Hugging Face data lives in one folder.
What Happens After You Clear the Cache?
When you next request a deleted model or dataset, Hugging Face will generally download the required files again. You may need an internet connection, and the first load can take longer. If you load a model in offline mode, clearing its cached files may prevent it from loading until you download the files again.
Clearing a cache is different from deleting a model you saved yourself. For example, a model saved using save_pretrained("/path/to/my-model") is stored in that specified folder. Removing the Hub cache does not automatically remove that separate folder. Likewise, uninstalling transformers or huggingface_hub does not reliably clear downloaded cache files.
If you want to reclaim space but keep frequently used models, delete only the entries you no longer need. If you need to work offline, keep the relevant model and tokenizer files available, either in the cache or in a separate saved directory.
Troubleshooting Hugging Face Cache Deletion
-
The cache appears empty: Check
HF_HOMEandHF_HUB_CACHEfor custom locations, and make sure you are checking the same operating-system account and Python environment that downloaded the files. -
The command is not found: Install or update
huggingface_hub, activate the correct virtual environment, and reopen your terminal. - Files return after deletion: A script or application may have downloaded them again. Check for running jobs and review recent model-loading activity.
- Deletion fails: Close programs that may be using the files. On Windows, a process can keep files locked; on Linux or macOS, check ownership and permissions.
- Disk space does not change immediately: Check the trash or recycle bin if you used a file manager, and confirm that you deleted the intended cache directory.
Conclusion
To clear the Hugging Face cache, first check its size with hf cache scan, then use hf cache delete to remove selected entries or clear the Hub cache interactively. Python’s scan_cache_dir() API is another option for targeted, automated cleanup, while manual folder deletion can work when you know the exact cache path. Check custom environment variables, close active processes, and remember that dataset caches and separately saved models may live elsewhere. Taking these steps lets you free disk space while keeping the files your projects still need.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.