# How to download a model from Hugging Face: web, CLI and Python

> Use hf download or snapshot_download for whole models, filter to one GGUF or safetensors file, and log in with a token for gated models.

URL: https://claudegpt.si/news/how-to-download-model-from-hugging-face  
Published: 2026-11-28T18:57:14.588Z  
Updated: 2026-11-28T18:57:50.370Z  
Author: ClaudeGPT Si Newsroom  
Section: Guides  
Topics: Hugging Face, How to, Open-weight models, Developer tools  
Publisher: ClaudeGPT Si

## Key takeaways

- The command line tool is now called hf: run hf download <repo_id> for a whole model or add a file name for one file.
- In Python, hf_hub_download() fetches one file and snapshot_download() fetches a repository, both into ~/.cache/huggingface/hub by default.
- Gated models need you to accept the terms on the model page and log in with a read token, via hf auth login or HF_TOKEN.

To download a model from Hugging Face, install the `huggingface_hub` package and run `hf download <repo_id>` in a terminal, or call `snapshot_download()` from Python. For a single file, click it under the model's Files tab in the browser, or pass the file name: `hf download <repo_id> <filename>`. Gated models also need you to accept the author's terms on the model page and log in with an access token.

This guide covers every route in [Hugging Face's own documentation](https://huggingface.co/docs/hub/models-downloading): the browser, the `hf` command line tool, Python, Git, one GGUF file at a time, and apps like Ollama and LM Studio that pull from the Hub for you. It ends with where the files land on disk and how to avoid downloading something harmful. The commands were checked on November 28, 2026 with `huggingface_hub` 2.5.0.

## What you need first

- Python 3 and pip, or one of the standalone installers below.
- Disk space. Models are big: the `openai-community/gpt2` repository alone holds 5.6 GB across 26 files, most of them the same weights in different formats.
- A free Hugging Face account and an access token, but only for gated or private models. Public models download without logging in.

## How to download a model in the browser

Every model page has a **Files** tab (called "Files and versions" in older docs). Each file there has a download link that points to a URL of the form `https://huggingface.co/<repo_id>/resolve/main/<filename>`. Click it and your browser saves the file.

This works for one or two files. For a whole model with many shards, the command line is faster and can resume.

## How to download a model with the hf CLI

The command line tool is now called `hf`. It ships with the `huggingface_hub` Python package. Install it with pip, Homebrew or the standalone installer for macOS and Linux, according to the [CLI guide](https://huggingface.co/docs/huggingface_hub/guides/cli). Any one of these lines is enough:

```bash
pip install -U "huggingface_hub"
brew install hf
curl -LsSf https://hf.co/cli/install.sh | bash
```

On Windows, the standalone installer runs in PowerShell: `powershell -ExecutionPolicy ByPass -c "irm https://hf.co/cli/install.ps1 | iex"`. Check it works with `hf --help`.

Then pick what to download:

1. **The whole repository.** `hf download HuggingFaceH4/zephyr-7b-beta`
2. **One file.** `hf download openai-community/gpt2 config.json`
3. **Several files.** `hf download openai-community/gpt2 config.json model.safetensors`
4. **Files matching a pattern.** `hf download stabilityai/stable-diffusion-xl-base-1.0 --include "*.safetensors" --exclude "*.fp16.*"`
5. **A specific version.** Add `--revision` with a branch, tag or full commit hash.

Two options are worth knowing before a big download. `--dry-run` lists the files and their sizes without downloading anything, and `--local-dir` puts the files in a normal folder instead of the cache:

```bash
hf download openai-community/gpt2 --dry-run
hf download openai-community/gpt2 --include "*.json" --local-dir gpt2
```

The dry run is the easy way to see that a repository contains the same model as safetensors, PyTorch `.bin`, TensorFlow, ONNX and more. You usually need only one format, so filter with `--include`.

With `--local-dir`, the files keep their folder structure, and a small `.cache/huggingface/` folder inside tracks what is already there, so a rerun only fetches what changed. When the download ends, `hf download` prints the local path.

Datasets and Spaces use the same command with `--repo-type dataset` or `--repo-type space`. Older tutorials use `huggingface-cli download`. That command is not installed with `huggingface_hub` 2.5.0; use `hf download` instead.

## How to download a model in Python

The same package has two functions, described in the [download guide](https://huggingface.co/docs/huggingface_hub/guides/download). `hf_hub_download()` fetches one file and returns its local path:

```python
from huggingface_hub import hf_hub_download

path = hf_hub_download(repo_id="openai-community/gpt2", filename="config.json")
print(path)
```

`snapshot_download()` fetches a whole repository, several files at a time, and returns the folder:

```python
from huggingface_hub import snapshot_download

folder = snapshot_download(
    repo_id="openai-community/gpt2",
    allow_patterns=["*.json", "*.safetensors"],
)
print(folder)
```

`allow_patterns` and `ignore_patterns` take the same wildcards as the CLI's `--include` and `--exclude`. Both functions accept `revision`, `local_dir`, `cache_dir` and `token`.

If you use Transformers, you may not need either function. `from_pretrained()` downloads the model into the same cache the first time you load it.

## How to clone a model with Git

Every model on the Hub is a Git repository whose large files sit in Xet storage, Hugging Face's replacement for Git LFS. To clone one with its weights, install Git, Git LFS and the [Git Xet extension](https://huggingface.co/docs/hub/xet/using-xet-storage), then:

```bash
brew install git-xet        # or the install script on Linux, winget on Windows
git xet install
git lfs install
git clone git@hf.co:openai-community/gpt2
```

The SSH form needs your public key in your [Hugging Face settings](https://huggingface.co/settings/keys). Git is the right choice when you want to edit and push changes. For downloading only, `hf download` is simpler: it skips formats you don't need, and Git pulls every file in the repository.

## How to download a single GGUF file

GGUF is the single-file format that llama.cpp, Ollama and LM Studio run locally (our [explainer on GGUF](https://claudegpt.si/news/what-is-gguf) covers what it is). A GGUF repository usually holds one file per quantization level, and each can be several gigabytes. Download only the one you want:

```bash
hf download bartowski/Llama-3.2-1B-Instruct-GGUF --include "*Q4_K_M.gguf" --dry-run
```

On November 28 that dry run reported one file, `Llama-3.2-1B-Instruct-Q4_K_M.gguf`, at 807.7 MB. Drop `--dry-run` to fetch it, and add `--local-dir models` if your app wants it in a plain folder. You can browse every GGUF model on the Hub at [hf.co/models?library=gguf](https://huggingface.co/models?library=gguf).

## How Ollama, LM Studio and llama.cpp pull models from the Hub

These apps download GGUF files straight from Hugging Face, so you don't need `hf` at all.

| App | Command | Pick a quantization |
| --- | --- | --- |
| Ollama | `ollama run hf.co/{username}/{repository}` | Add `:Q8_0` or another tag. Without one, Ollama uses `Q4_K_M` when the repository has it. |
| LM Studio | `lms get https://huggingface.co/{username}/{repository}` | Add `@Q6_K` or another tag. |
| llama.cpp | `llama cli -hf {username}/{repository}:Q8_0` | The tag after the colon. |

The [Ollama](https://huggingface.co/docs/hub/ollama) and [LM Studio](https://huggingface.co/docs/hub/lmstudio) pages in the Hub docs also describe a browser route: turn the app on under [Local Apps settings](https://huggingface.co/settings/local-apps), then choose it from the **Use this model** menu on a model page. LM Studio's in-app search also accepts a pasted Hugging Face URL.

For private GGUF repositories, Ollama uses an SSH key: copy `~/.ollama/id_ed25519.pub` and add it under SSH keys in your Hugging Face settings. llama.cpp stores its downloads in the folder set by `LLAMA_CACHE`, not in the Hugging Face cache.

## How to download a gated model with an access token

Some authors, Meta among them, gate their models. Without access, a download fails. Our test on `meta-llama/Llama-3.2-1B` returned "Access denied. Model 'meta-llama/Llama-3.2-1B' requires approval."

The [gated models docs](https://huggingface.co/docs/hub/models-gated) give the steps:

1. Log in to huggingface.co in your browser and open the model page.
2. Fill in the form if there is one and click **Agree**. This shares your username and email with the authors unless they turned that off.
3. Wait for approval. Some models grant it at once; others are approved by hand, which can take longer.
4. Create a token under [Access Tokens](https://huggingface.co/settings/tokens). A `read` token is enough to download.
5. Log in on your machine with `hf auth login`, or set the `HF_TOKEN` environment variable, or pass `--token` to `hf download` or `token=` in Python.

Our guide to [Hugging Face API keys](https://claudegpt.si/news/hugging-face-api-key) covers token types in more detail. Hugging Face recommends one token per machine or app, so you can revoke one without breaking the others.

## Where Hugging Face saves downloaded models

By default, downloads go to `~/.cache/huggingface/hub`, according to the [cache guide](https://huggingface.co/docs/huggingface_hub/guides/manage-cache). Each repository gets a folder such as `models--openai-community--gpt2`, with the real files in `blobs/` and links to them, by version, in `snapshots/`.

- `HF_HOME` moves everything, including your saved token. The cache then lives at `$HF_HOME/hub`.
- `HF_HUB_CACHE` moves only the model cache.
- `--cache-dir` or `cache_dir=` changes it for one download.

`hf cache ls` lists what is cached and how much space it takes. `hf cache rm model/openai-community/gpt2` deletes a repository, and `hf cache prune` clears old revisions and half-finished downloads. On Windows without Developer Mode, the cache can't create symlinks, so it copies files instead and may store the same file twice.

## Common problems

- **Slow or stalled downloads.** Install the latest `huggingface_hub`, which since version 0.32.0 includes `hf_xet` for faster Xet downloads. On slow connections, raise `HF_HUB_DOWNLOAD_TIMEOUT` from its 10-second default, for example to 30.
- **"Requires approval" or 401 errors.** You haven't accepted the terms, approval is pending, or your machine isn't logged in. See the gated model steps above.
- **Downloads fail behind a company firewall.** Allowing `huggingface.co` isn't enough, because files come from separate storage and CDN hosts. Hugging Face suggests allowlisting both the `hf.co` and `huggingface.co` domains with their subdomains.
- **A warning about unauthenticated requests.** Public downloads still work. Logging in gives you higher rate limits.

## How to download models safely

A model file can carry code. Older PyTorch weights (`.bin`, `.pt`) use Python's pickle format, and loading a pickle can run whatever code was placed in it. Hugging Face's [pickle scanning page](https://huggingface.co/docs/hub/security-pickle) suggests loading models only from users and organizations you trust.

- **Prefer safetensors.** When a repository offers both, download `*.safetensors` and skip `*.bin`. The Transformers docs call safetensors "more secure and faster to load", and `from_pretrained()` picks it when it exists.
- **Be careful with `trust_remote_code=True`.** It runs Python code from the repository on your machine. If you must use it, pin a `revision` to a commit you have read.
- **Check the scan results.** The Hub runs every file under 2 GB through a malware scanner on each commit and flags suspicious pickle imports next to the file. Hugging Face calls its pickle scan "not 100% foolproof".
- **Don't run commands a model tells you to run.** GGUF files hold weights, not code, but they are not automatically safe. This week Hugging Face disabled five GGUF models that hid Windows malware or used their chat templates to tell users to run PowerShell commands. Our report on the [malicious GGUF models](https://claudegpt.si/news/hugging-face-malicious-gguf-models) explains how they worked, and [is Hugging Face safe](https://claudegpt.si/news/is-hugging-face-safe) covers what the Hub scans and what it misses.

## Where to go next

Before your next big download, run `hf download <repo_id> --dry-run` to see the files and their sizes, then fetch only the format you need. For a local chat model, the Ollama or LM Studio route is the shortest path. For code, `snapshot_download()` with `allow_patterns` keeps your disk and your cache tidy.

## Frequently asked questions

### How do I download all files from a Hugging Face repo?

Run hf download <repo_id> with no file names, or call snapshot_download(repo_id=...) in Python. Add --dry-run first to see every file and its size.

### How do I download a GGUF file from Hugging Face?

Filter to the quantization you want, for example hf download bartowski/Llama-3.2-1B-Instruct-GGUF --include "*Q4_K_M.gguf". Ollama, LM Studio and llama.cpp can also pull a GGUF straight from the Hub by repository name.

### Do I need a token to download models from Hugging Face?

Not for public models. Gated and private models need a user access token, set with hf auth login, the HF_TOKEN environment variable or a token argument.

### Where does Hugging Face store downloaded models?

In ~/.cache/huggingface/hub by default. Set HF_HOME or HF_HUB_CACHE to move it, or use --local-dir to save files to a normal folder.

## Sources

- [Downloading models](https://huggingface.co/docs/hub/models-downloading), Hugging Face
- [Command Line Interface (CLI)](https://huggingface.co/docs/huggingface_hub/guides/cli), Hugging Face
- [Download files from the Hub](https://huggingface.co/docs/huggingface_hub/guides/download), Hugging Face
- [Gated models](https://huggingface.co/docs/hub/models-gated), Hugging Face
- [User access tokens](https://huggingface.co/docs/hub/security-tokens), Hugging Face
- [Understand caching](https://huggingface.co/docs/huggingface_hub/guides/manage-cache), Hugging Face
- [Environment variables](https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables), Hugging Face
- [Using Xet Storage](https://huggingface.co/docs/hub/xet/using-xet-storage), Hugging Face
- [GGUF](https://huggingface.co/docs/hub/gguf), Hugging Face
- [Use Ollama with any GGUF model on Hugging Face Hub](https://huggingface.co/docs/hub/ollama), Hugging Face
- [GGUF usage with LM Studio](https://huggingface.co/docs/hub/lmstudio), Hugging Face
- [GGUF usage with llama.cpp](https://huggingface.co/docs/hub/gguf-llamacpp), Hugging Face
- [Pickle scanning](https://huggingface.co/docs/hub/security-pickle), Hugging Face
- [Malware scanning](https://huggingface.co/docs/hub/security-malware), Hugging Face
- [Loading models](https://huggingface.co/docs/transformers/main/en/models), Hugging Face
