Wauplin's picture
|
download
raw
10.7 kB
---
name: hf-cli
description: "Hugging Face Hub CLI (`hf`). Use it to search, download and upload models, datasets and Spaces; manage repos, buckets (S3-like storage), the local cache, discussions and pull requests, collections and webhooks; run Jobs and sandboxes on Hugging Face infrastructure; create and configure Spaces; deploy Inference Endpoints; read papers; query datasets with SQL; and share agent session traces. Use this skill whenever a task involves the Hugging Face Hub or the user mentions 'hf', 'huggingface', 'Hugging Face' or 'huggingface-cli' (deprecated, replaced by `hf`), and for cloud compute or storage needs like training runs, batch jobs, checkpoints or datasets, even if the user doesn't explicitly ask for a CLI command. Requires a terminal."
---
`hf` is the command line interface of the Hugging Face Hub. It replaces the deprecated `huggingface-cli`.
Not installed? Run `curl -LsSf https://hf.co/cli/install.sh | bash -s` (alternatives: `pip install -U huggingface_hub`, `brew install hf`, or `uvx hf ...` without installing).
Generated with `huggingface_hub v2.6.0.dev0`. Run `hf skills update hf-cli -g` to regenerate.
## Commands
Only command names are listed here. Run `hf <command> --help` before using a command for the first time: it prints its arguments, flags and examples. Do not guess flags.
- `hf auth` — Manage authentication (login, logout, etc.): `list (ls)`, `login`, `logout`, `revoke`, `switch`, `token`, `whoami`
- `hf buckets` — Commands to interact with buckets: `cp`, `create`, `delete`, `info`, `list (ls)`, `move`, `remove (rm)`, `settings`, `sync`
- `hf cache` — Manage local cache directory: `list (ls)`, `prune`, `rm`, `verify`
- `hf collections` — Interact with collections on the Hub: `add-item`, `create`, `delete`, `delete-item`, `info`, `list (ls)`, `update`, `update-item`
- `hf cp SRC [DST]` — Copy files between local paths, repositories, and buckets.
- `hf datasets` — Interact with datasets on the Hub: `card`, `info`, `leaderboard`, `list (ls)`, `parquet`, `sql`
- `hf discussions` — Manage discussions and pull requests on the Hub: `close`, `comment`, `create`, `diff`, `edit`, `info`, `list (ls)`, `merge`, `rename`, `reopen`
- `hf download REPO_ID [FILENAMES]...` — Download files from the Hub.
- `hf endpoints` — Manage Hugging Face Inference Endpoints: `catalog {deploy, list (ls)}`, `delete`, `deploy`, `describe`, `hardware`, `list (ls)`, `pause`, `resume`, `scale-to-zero`, `update`
- `hf env` — Print information about the environment.
- `hf extensions (ext)` — Manage hf CLI extensions: `exec`, `install`, `list (ls)`, `remove (rm)`, `search`, `update`
- `hf jobs` — Run and manage Jobs on the Hub: `cancel`, `expose`, `hardware`, `inspect`, `labels`, `list (ls, ps)`, `logs`, `rerun`, `run`, `scheduled {delete, inspect, labels, list (ls, ps), reschedule, resume, run, suspend, trigger, uv run}`, `ssh`, `stats`, `uv run`, `wait`
- `hf models` — Interact with models on the Hub: `card`, `info`, `list (ls)`
- `hf papers` — Interact with papers on the Hub: `info`, `list (ls)`, `read`, `search`
- `hf repos` — Manage repos on the Hub: `branch {create, delete}`, `cp`, `create`, `delete`, `delete-files`, `duplicate`, `list (ls)`, `move`, `settings`, `tag {create, delete, list (ls)}`
- `hf resource-groups` — Manage resource groups of an organization on the Hub: `assign`, `unassign`
- `hf sandbox` — Run and manage experimental sandboxes on Hugging Face Jobs: `cp`, `create`, `exec`, `kill`, `pool {create, delete (rm), ls (list)}`, `process {kill, ls (list)}`, `spawn`
- `hf skills` — Manage skills for AI assistants: `add`, `list (ls)`, `preview`, `update`
- `hf spaces` — Interact with spaces on the Hub: `card`, `dev-mode`, `hardware`, `hot-reload`, `info`, `list (ls)`, `logs`, `pause`, `restart`, `search`, `secrets {add, delete, list (ls)}`, `settings`, `ssh`, `templates`, `variables {add, delete, list (ls)}`, `volumes {delete, list (ls), set}`, `wait`, `zero-gpu quota`
- `hf sync [SOURCE] [DEST]` — Sync files between local directory and a bucket.
- `hf update` — Update the `hf` CLI to the latest version.
- `hf upload REPO_ID [LOCAL_PATH] [PATH_IN_REPO]` — Upload a file or a folder to the Hub.
- `hf version` — Print information about the hf version.
- `hf webhooks` — Manage webhooks on the Hub: `create`, `delete`, `disable`, `enable`, `info`, `list (ls)`, `update`
## Output and scripting
- Output is compact when an AI agent is detected and human-friendly otherwise; force a format with `--format [agent|auto|human|json|quiet]`.
- Use `--json` to parse results (e.g. with `jq`) and `-q` / `--quiet` to print one ID per line (e.g. `hf jobs ls -q | xargs hf jobs wait`).
- These flags work on every command except `hf extensions exec`, `hf sandbox exec` and `hf sandbox spawn`; most commands also accept `--no-truncate` for full values in human tables.
- Lines starting with `Hint:` go to stderr, so stdout stays parseable; read them, they often give the next command to run.
## Authentication
- Check the current login with `hf auth whoami`; if logged out, ask the user to run `hf auth login` or to set the `HF_TOKEN` environment variable.
- Prefer `HF_TOKEN` or `hf auth login` over `--token`: the flag ends up in the shell history and not every command accepts it (e.g. `hf auth whoami`).
- Never print a token; forward it to a Job, a sandbox or a Space with `--secrets HF_TOKEN`, which reads the value from the local environment.
## Repos, files and paths
- Repo IDs are `namespace/name` and are models by default: prefix them (`datasets/namespace/name`, `spaces/namespace/name`) or pass `--type` for other repo types.
- Remote files are addressed as `hf://[datasets/|spaces/|buckets/]namespace/name[@revision]/path` (no prefix means a model repo; buckets have no revision).
- `hf models ls REPO_ID`, `hf datasets ls REPO_ID`, `hf spaces ls REPO_ID` and `hf buckets ls BUCKET_ID` list remote files, and `hf models card REPO_ID` (same for datasets and Spaces) prints the README, without downloading anything.
- `hf download` stores files in the local cache and prints their path: pass filenames or `--include` / `--exclude` globs to fetch only what is needed, `--dry-run` to check sizes first, and `--local-dir` to get plain files in a folder.
- `hf upload REPO_ID [LOCAL_PATH] [PATH_IN_REPO]` creates the repo if needed and handles large folders: they are split into several commits and re-running the same command resumes an interrupted upload.
- `hf cp` copies single files between local paths, repos and buckets, with `-` for stdin/stdout (e.g. `hf cp hf://datasets/namespace/name/README.md -`); for local folders use `hf upload` / `hf download` (repos) or `hf sync` (buckets).
- To read a repo or bucket as a local folder without downloading it, mount it with `hf-mount` (https://github.com/huggingface/hf-mount).
## Choosing the right resource
- Dataset repo vs bucket: use a dataset (or model) repo for data to publish, share or version, as repos are git-based and keep history; use a bucket (`hf buckets`, `hf sync`) for mutable S3-like storage without history, e.g. checkpoints, logs and intermediate artifacts.
- Job vs sandbox: use `hf jobs` to run one command to completion (training, batch inference, evals, scheduled tasks); use `hf sandbox` (experimental) for a machine to iterate on with repeated `exec` and `cp` calls, and `hf sandbox kill` it when done.
- Space SDK: use `--sdk static` for a website made of plain HTML/CSS/JS files, `--sdk gradio` for a Python demo, and `--sdk docker` only when the app needs its own server or system dependencies.
- Create a Space explicitly with `hf repos create NAME --type space --sdk ...` before uploading to it: `hf upload` on a missing Space creates a Gradio one.
- After pushing to a Space, run `hf spaces wait SPACE_ID` (non-zero exit code if the Space is not running) and read `hf spaces logs SPACE_ID` (`--build` for build logs) if it failed.
## Jobs
- `hf jobs uv run script.py` runs a Python script and installs its dependencies (inline script metadata or `--with`) without building an image; `hf jobs run IMAGE COMMAND...` runs any Docker image.
- Hardware defaults to `cpu-basic`: list flavors and prices with `hf jobs hardware` and pick one with `--flavor`.
- Jobs stop after 30 minutes by default: set `--timeout` (e.g. `--timeout 2h`) for longer runs.
- A Job streams its logs until it ends; pass `-d` / `--detach` to get the Job ID right away, then use `hf jobs logs -f JOB_ID`, `hf jobs inspect JOB_ID` or `hf jobs wait JOB_ID` (non-zero exit code if the Job failed).
- When launching related Jobs, give each one a descriptive `--name` and a shared `--label` (e.g. `--label project=my-experiment`), and reuse that label in later calls so they can be found with `hf jobs ls -a --label project=my-experiment`.
- `hf jobs ls` only shows running Jobs; add `-a` to include finished and failed ones.
- Mount inputs and outputs with `-v`: repos are read-only (`-v hf://datasets/namespace/name:/data`) and buckets are read-write (`-v hf://buckets/namespace/name:/output`), which makes buckets the place to persist results.
## Sharing agent traces
- The Hub renders raw JSONL session traces in a trace viewer, no conversion needed: Claude Code stores them in `~/.claude/projects/<project>/<session-id>.jsonl`, Codex in `~/.codex/sessions/YYYY/MM/DD/*.jsonl`, Pi in `~/.pi/agent/sessions` and Factory Droid in `~/.factory/sessions`.
- To share the current session, pick the most recently modified `.jsonl` of your harness and upload that single file: `hf upload namespace/name path/to/session.jsonl --type dataset --private` (or `hf cp` it into a bucket).
- Traces contain prompts, command output, local paths and possibly secrets: keep the dataset or bucket private unless the user explicitly asks to publish it, and offer to review or redact it first.
- To keep sharing new sessions, sync the whole folder to a bucket, e.g. `hf sync ~/.codex/sessions hf://buckets/namespace/name/codex`.
- Other harnesses can write the Session Traces Format to render in the same viewer: https://huggingface.co/docs/hub/session-traces-format.
## Search
- Search with `hf models ls` and `hf datasets ls` (`--search`, `--filter`, `--author`, `--sort`, `--limit`), `hf spaces search QUERY` (semantic search) and `hf papers search QUERY`.
- `hf datasets sql "SELECT ..."` queries the parquet files of a dataset with DuckDB, without downloading it.
## Staying up to date
- `hf update` updates the CLI and `hf skills update hf-cli -g` regenerates this skill for the installed version (drop `-g` for a project-level install); `hf --skills` prints it.
- If Hugging Face MCP tools are also available in the session, they can be used as well.

Xet Storage Details

Size:
10.7 kB
·
Xet hash:
6cc2d938089066352dd3e8039532a01dad08fbfd3639d8d6a52fc063a8a4768a

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.