Skip to main content

HuggingFace CLI Cheatsheet

The HuggingFace CLI is the command-line tool for interacting with the HuggingFace Hub. Use it to download/upload models and datasets, manage cache, create/delete repositories, and handle authentication. Supports resume downloads and file filtering for large model downloads.

Updated: 2026-07-20·24 commands

Quick Start

``bash # Login huggingface-cli login --token hf_xxxxxxxx

# Download a model huggingface-cli download meta-llama/Llama-3.1-8B --local-dir ./models

# Download only GGUF files huggingface-cli download bartowski/Llama-3.2-3B-Instruct-GGUF --include '*.gguf'

# Check current user huggingface-cli whoami

# View cache usage huggingface-cli scan-cache `

Authentication

Login with huggingface-cli login --token . Tokens are managed at huggingface.co/settings/tokens. For CI/CD, use export HF_TOKEN=hf_xxx. Models requiring access approval (like Llama) need a token with accepted terms.

Download

The download command is the most used feature. Key flags: --local-dir (output path), --include (file filter), --exclude (skip files), --repo-type (model/dataset/space), --revision (branch/tag), --resume-download (resume interrupted), --cache-dir (custom cache).

Upload

Use upload to push files. First create a repo with repo create, then upload files. Supports --repo-type for dataset repos. For large files (>5MB), LFS is handled automatically.

Cache Management

scan-cache shows cached repos and versions. delete-cache interactively removes unused versions. Set HF_HOME to change the cache location. The default cache at ~/.cache/huggingface/hub can grow very large (100GB+ for multiple models).

Environment Variables

HF_TOKEN for authentication, HF_ENDPOINT for mirror endpoints (China: https://hf-mirror.com), HF_HOME for cache directory, HF_HUB_ENABLE_HF_TRANSFER=1 for faster downloads with hf_transfer`.

Startup & Modes(14)

CommandLevel
huggingface-cli --help
Show huggingface-cli help
Basic
huggingface-cli login
Log in to HuggingFace account
Basic
huggingface-cli logout
Log out
Basic
huggingface-cli whoami
Check current logged-in user
Basic
huggingface-cli scan-cache
Scan HuggingFace cache
Intermediate
huggingface-cli delete-cache
Delete specific version from cache
Intermediate
huggingface-cli env
Show HuggingFace environment info
Basic
huggingface-cli repo create
Create a new repository
Intermediate
huggingface-cli repo delete
Delete a repository
Expert
huggingface-cli lfs-enable-largefiles
Enable large file support (LFS)
Intermediate
huggingface-cli tag
Tag a repository version
Intermediate
huggingface-cli list
List user's models/datasets
Basic
export HF_TOKEN
Set HuggingFace token environment variable
Basic
export HF_ENDPOINT
Set HF mirror endpoint (for China users)
Basic

ai-model(10)

CommandLevel
huggingface-cli download
Download model or dataset (core feature)
Basic
huggingface-cli download --local-dir
Specify local download directory
Basic
huggingface-cli download --repo-type
Specify repo type (model/dataset/space)
Intermediate
huggingface-cli download --revision
Download specific version/branch
Intermediate
huggingface-cli download --include
Only download files matching pattern
Intermediate
huggingface-cli download --exclude
Exclude files matching pattern
Intermediate
huggingface-cli download --cache-dir
Specify cache directory
Intermediate
huggingface-cli upload
Upload file to HuggingFace
Intermediate
huggingface-cli upload --repo-type
Upload to specific repo type
Intermediate
huggingface-cli download --resume-download
Resume interrupted download
Intermediate

FAQ

This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-20.