← 返回
AI智能 Key 中文

Hugging Face CLI

Manage Hugging Face Hub via hf CLI. Use when working with HF AI models, datasets, spaces, or repos.
使用 hf CLI 管理 Hugging Face Hub,适用于 HF AI 模型、数据集、Spaces 或仓库。
yevhendiachenko0
AI智能 clawhub v1.1.0 1 版本 100000 Key: 需要
★ 1
Stars
📥 606
下载
💾 15
安装
1
版本
#latest

概述

Hugging Face CLI

Hugging Face (https://huggingface.co) is the leading platform for sharing and collaborating on AI models, datasets, and spaces. This skill enables interaction with the Hub through the official hf CLI.

Installation

Check if hf is available by running hf version. If not installed:

pip install -U "huggingface_hub[cli]"
# or
brew install hf

If the options above do not work, follow the official installation guide.

After installation, run hf version to verify. If the command is not found, run source ~/.bashrc (or source ~/.zshrc for zsh) to reload the PATH, then try again.

Authentication

A Hugging Face User Access Token is required. The token is provided via the HF_TOKEN environment variable.

If authentication fails or the token is missing, instruct the user to:

  1. Go to https://huggingface.co/settings/tokens
  2. Create a new token — there are two permission levels:
    • Read (safer): sufficient for searching, downloading models/datasets, listing repos, browsing papers, and most read-only operations. Choose this if you only need to explore and download.
    • Write (less safe, broader access): required for creating/deleting repos, uploading files, managing discussions, deploying endpoints, and running jobs. Example 3 (create a repo and upload weights) requires a write token.
  3. Set it as an environment variable: export HF_TOKEN="hf_..." (add to shell profile for persistence)

Important: Do NOT run hf auth login interactively — it requires terminal input. Instead, use the environment variable directly. The hf CLI automatically picks up HF_TOKEN from the environment for all commands. To verify authentication, run:

hf auth whoami

Key Commands

TaskCommand
------
Check current userhf auth whoami
Download fileshf download [files...] [--local-dir ]
Download specific revision`hf download --revision tag\commit>`
Download with filtershf download --include ".safetensors" --exclude ".bin"
Upload fileshf upload [path_in_repo]
Upload as PRhf upload [path_in_repo] --create-pr
Upload (private repo)hf upload [path_in_repo] --private
Upload large folderhf upload-large-folder
Create a repo`hf repos create [--repo-type model\dataset\space] [--private]`
Delete a repohf repos delete
Delete files from repohf repos delete-files ...
Duplicate a repo`hf repos duplicate [--type model\dataset\space]`
Repo settings`hf repos settings [--private\--public]`
Manage branches`hf repos branch create\delete `
Manage tags`hf repos tag create\delete `
List modelshf models ls [--search ] [--sort downloads] [--limit N]
Model infohf models info
List datasetshf datasets ls [--search ]
Dataset infohf datasets info
Run SQL on datahf datasets sql ""
List spaceshf spaces ls [--search ]
Space infohf spaces info
Space dev modehf spaces dev-mode
List papershf papers ls [--limit N]
List collectionshf collections ls [--owner ] [--sort trending]
Create collectionhf collections create ""</code></td></tr><tr><td>Collection info</td><td><code>hf collections info <collection_slug></code></td></tr><tr><td>Add to collection</td><td><code>hf collections add-item <collection_slug> <repo_id> <type></code></td></tr><tr><td>Delete collection</td><td><code>hf collections delete <collection_slug></code></td></tr><tr><td>Run a cloud job</td><td><code>hf jobs run <docker_image> <command></code></td></tr><tr><td>List jobs</td><td><code>hf jobs ps</code></td></tr><tr><td>Job logs</td><td><code>hf jobs logs <job_id></code></td></tr><tr><td>Cancel a job</td><td><code>hf jobs cancel <job_id></code></td></tr><tr><td>Job hardware</td><td><code>hf jobs hardware</code></td></tr><tr><td>Deploy endpoint</td><td><code>hf endpoints deploy <name> --repo <repo_id> --framework <fw> --accelerator <hw> ...</code></td></tr><tr><td>List endpoints</td><td><code>hf endpoints ls</code></td></tr><tr><td>Endpoint info</td><td><code>hf endpoints describe <name></code></td></tr><tr><td>Pause/resume endpoint</td><td>`hf endpoints pause\</td><td>resume <name>`</td></tr><tr><td>Delete endpoint</td><td><code>hf endpoints delete <name></code></td></tr><tr><td>List discussions</td><td><code>hf discussions ls <repo_id></code></td></tr><tr><td>Create discussion</td><td><code>hf discussions create <repo_id> --title "<title>"</code></td></tr><tr><td>Comment on discussion</td><td><code>hf discussions comment <repo_id> <num> --body "<text>"</code></td></tr><tr><td>Close discussion</td><td><code>hf discussions close <repo_id> <num></code></td></tr><tr><td>Merge PR</td><td><code>hf discussions merge <repo_id> <num></code></td></tr><tr><td>Manage cache</td><td><code>hf cache ls</code>, <code>hf cache rm <id></code>, <code>hf cache prune</code></td></tr><tr><td>Delete bucket / files</td><td><code>hf buckets delete <user>/<bucket></code>, <code>hf buckets rm <user>/<bucket>/<path></code></td></tr><tr><td>Sync to bucket</td><td><code>hf sync <local_path> hf://buckets/<user>/<bucket></code></td></tr><tr><td>Print environment</td><td><code>hf env</code></td></tr></tbody></table><h1>End-to-End Examples</h1><p><strong>Example 1: Explore trending models, pick one, and preview a download</strong></p><pre><code>hf models ls --sort trending_score --limit 5 hf models info openai-community/gpt2 hf download --dry-run openai-community/gpt2 config.json tokenizer.json hf download openai-community/gpt2 config.json tokenizer.json --local-dir ./gpt2 </code></pre><p><strong>Example 2: Browse today's papers and find related datasets</strong></p><pre><code>hf papers ls --limit 5 hf datasets ls --search "code" --sort downloads --limit 5 hf datasets info bigcode/the-stack </code></pre><p><strong>Example 3: Create a private model repo and upload weights</strong></p><pre><code>hf repos create my-fine-tuned-model --private # create returns <your-username>/my-fine-tuned-model — use that full ID below hf upload <username>/my-fine-tuned-model ./output --commit-message "Add fine-tuned weights" hf repos tag create <username>/my-fine-tuned-model v1.0 -m "Initial release" </code></pre><h1>Further Reference</h1><p>Reference version: <code>hf</code> CLI v1.x</p><p>For the full list of commands and options, use built-in help:</p><pre><code>hf --help hf <command> --help </code></pre><ul><li><strong>Full documentation:</strong> https://huggingface.co/docs/huggingface_hub/guides/cli</li><li><strong>CLI reference:</strong> https://huggingface.co/docs/huggingface_hub/package_reference/cli</li></ul><h1>Safety Rules</h1><ul><li><strong>Destructive commands require explicit user confirmation.</strong> Before running any of the following, describe what will happen and ask the user to confirm:</li><li><code>hf repos delete</code> — permanently deletes a repository</li><li><code>hf repos delete-files</code> — deletes files from a repository</li><li><code>hf buckets delete</code> / <code>hf buckets rm</code> — deletes buckets or bucket files</li><li><code>hf discussions close</code> / <code>hf discussions merge</code> — closes or merges PRs/discussions</li><li><code>hf collections delete</code> — permanently deletes a collection</li><li><code>hf endpoints delete</code> — permanently deletes an Inference Endpoint</li><li><code>hf jobs cancel</code> — cancels a running compute job</li><li>Any command with <code>--delete</code> flag (e.g., sync with deletion)</li><li><code>hf cache rm</code> / <code>hf cache prune</code> — removes cached data from disk (re-downloadable, but may waste bandwidth)</li><li>Never expose or log the <code>HF_TOKEN</code> value. Do not include it in command output or commit it to files.</li><li>When uploading, warn the user if the target repo is public and the upload may contain sensitive data.</li></ul></div> </div> </div> <div id="tab-versions" class="detail-content"> <div class="detail-section"> <h2>版本历史</h2> <p style="margin-bottom:12px;font-size:14px;color:#94a3b8;">共 1 个版本</p> <ul class="version-list"> <li> <div> <span class="version-tag">v1.1.0</span> <span style="font-size:11px;color:#5b6abf;margin-left:8px;background:#eef0ff;padding:1px 8px;border-radius:10px;">当前</span> </div> <div style="font-size:12px;color:#94a3b8;"> 2026-03-29 19:33 安全 安全 </div> </li> </ul> </div> </div> <div id="tab-security" class="detail-content"> <div class="detail-section"> <h2>安全检测</h2> <div class="sec-grid"> <div class="sec-card"> <h4>腾讯云安全 (Keen)</h4> <div class="sec-status sec-safe"> 安全,无风险 </div> <a href="https://tix.qq.com/search/skill?keyword=093df17e9bc613cabb6e451f89db85d1" target="_blank">查看报告</a> </div> <div class="sec-card"> <h4>腾讯云安全 (Sanbu)</h4> <div class="sec-status sec-safe"> 安全,无风险 </div> <a href="https://static.cloudsec.tencent.com/html-report-v2/2026/05/25/412081_afe0c325c04b10a5f116a5b5313765c8.html?q-sign-algorithm=sha1&q-ak=AKID8JMG1bzBC1dz96qNhssfFftujT1NCoFi&q-sign-time=1781301254%3B1812837254&q-key-time=1781301254%3B1812837254&q-header-list=host&q-url-param-list=&q-signature=62e0b55cedc6b6de7ea2f218c60fa68abd227b9d" target="_blank">查看报告</a> </div> </div> </div> </div> <!-- Recommended Skills --> <div style="margin-top:24px;"> <h2 style="font-size:18px;font-weight:600;margin-bottom:16px;">🔗 相关推荐</h2> <div class="rec-grid"> <div class="rec-card"> <span class="badge-cat" style="margin-bottom:8px;display:inline-block;">ai-intelligence</span> <h3><a href="/s/self-improving">Self-Improving + Proactive Agent</a></h3> <div class="rec-owner">ivangdavila</div> <div class="rec-desc">自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。</div> <div class="rec-stats"> <span style="color:#f39c12;">★ 1,354</span> <span style="color:#5b6abf;">📥 317,968</span> </div> </div> <div class="rec-card"> <span class="badge-cat" style="margin-bottom:8px;display:inline-block;">ai-intelligence</span> <h3><a href="/s/ontology">ontology</a></h3> <div class="rec-owner">oswalpalash</div> <div class="rec-desc">类型化知识图谱,用于结构化智能体记忆与可组合技能。支持创建/查询实体(人员、项目、任务、事件、文档)及关联...</div> <div class="rec-stats"> <span style="color:#f39c12;">★ 710</span> <span style="color:#5b6abf;">📥 243,683</span> </div> </div> <div class="rec-card"> <span class="badge-cat" style="margin-bottom:8px;display:inline-block;">productivity</span> <h3><a href="/s/learn-me">Learn me</a></h3> <div class="rec-owner">yevhendiachenko0</div> <div class="rec-desc">了解我:OpenClaw通过自然对话主动了解你</div> <div class="rec-stats"> <span style="color:#f39c12;">★ 1</span> <span style="color:#5b6abf;">📥 818</span> </div> </div> </div> </div> </div> <script> document.addEventListener('DOMContentLoaded',function(){ document.querySelectorAll('.detail-tab').forEach(function(btn){ btn.addEventListener('click',function(e){ var tab = this.getAttribute('data-tab'); document.querySelectorAll('.detail-tab').forEach(function(b){b.classList.remove('active')}); document.querySelectorAll('.detail-content').forEach(function(c){c.classList.remove('active')}); this.classList.add('active'); var el = document.getElementById('tab-'+tab); if(el) el.classList.add('active'); }); }); }); </script> <div class="footer"> <p>Skill工具集 © 2026</p> </div></body> </html>