3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Claude Code】uvでスキルを1ファイル完結にする

3
Last updated at Posted at 2026-04-15

Claude Codeのスキルで外部ライブラリ(例:httpx)を使ったPythonスクリプトを実行したい。しかし仮想環境は管理したくない。

uvはPythonのパッケージ・プロジェクト管理ツールで、パッケージインストール・仮想環境作成・依存関係解決をまとめて行う。uv shebangを使えば、venv作成やpip installの手順なしに、1ファイルで外部ライブラリを使ったスクリプトが完結する。

uv本体はegetで取得できる(egetの使い方はこちら)。

eget astral-sh/uv --to ~/bin/uv

uv shebangとは

shebang行に uv run --with を指定すると、uvが依存関係を自動解決してスクリプトを実行する。

#!/usr/bin/env -S uv run --with httpx

初回実行時にuvがhttpxを一時的にインストールしてから実行する(以降はキャッシュされ即座に起動する)。venvの作成やactivate、pip installを手動で行う必要はない。

スキルでの使い方

.claude/skills/{skill-name}/
├── SKILL.md
└── scripts/
    └── example.py  # 実行権限を付与
chmod +x scripts/example.py

実例:GitHub Star Counter

github_stars.py
#!/usr/bin/env -S uv run --with httpx
import sys
import httpx

repo = sys.argv[1]
stars = httpx.get(f"https://api.github.com/repos/{repo}").json()["stargazers_count"]
print(f"{repo}: {stars:,} stars")

実例:Qiita Tag Info

記事のタグ候補提案に使用。Qiita記事執筆支援スキルの一部。

qiita_tag_info.py
#!/usr/bin/env -S uv run --with httpx
import sys
import httpx

tag = sys.argv[1]
data = httpx.get(f"https://qiita.com/api/v2/tags/{tag}").json()
print(f"{data['id']}\t{data['items_count']}\t{data['followers_count']}")

まとめ

  • shebang1行で外部ライブラリが使える
  • 仮想環境不要
  • uvさえあればどこでも動く

参考

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?