mcpField
G
gh-cli

gh-cli

github.com/logicrw開発02.7k 回インストール33 週間前に更新
リポジトリ

gh-cli について

GitHub のコマンドラインツール `gh` を使った各種操作を扱うエージェントスキルです。JSON の項目選択や出力制限により、エージェントが扱う情報を絞ります。

主な機能

  1. 01GitHub の PR と Issue の操作
  2. 02リポジトリとファイルへのアクセス
  3. 03コードとリポジトリの検索
  4. 04コミット、リリース、API の照会
  5. 05JSON 出力の絞り込み方法

活用シーン

  1. 01PR の詳細や差分の確認
  2. 02GitHub Issue の作成や確認
  3. 03コードやリポジトリの検索
  4. 04コミットやリリース情報の取得

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/logicrw/gh-cli-skill --skill gh-cli

インストール後、Claude Code で/gh-cliを入力して読み込まれたか確認します。

詳細

GitHub CLI (gh) — エージェントスキル

GitHub のすべての操作には gh CLI を使用してください。構造化された出力には必ず --json を使用し、トークン使用量を最小限に抑えるため、フィールドの選択には --jq を使用してください。

認証

gh auth を使用して設定済みです。次のコマンドで確認してください。

gh auth status

基本原則

出力トークンを最小限に抑えるため、必要なフィールドのみを常に要求してください。

# ❌ Bad — returns everything
gh pr view 123

# ✅ Good — returns only what's needed
gh pr view 123 --json title,state,body,url --jq '{title,state,body,url}'

クイックリファレンス

プルリクエスト
# List open PRs
gh pr list --json number,title,author,updatedAt --jq '.[] | {number,title,author:.author.login}'

# View PR details
gh pr view <number> --json title,state,body,headRefName,baseRefName,additions,deletions,changedFiles

# View PR diff
gh pr diff <number>

# View PR files changed
gh pr diff <number> --name-only

# Create PR
gh pr create --title "title" --body "description" --base main --head feature-branch

# Create draft PR
gh pr create --title "title" --body "description" --draft

# Merge PR
gh pr merge <number> --squash --delete-branch

# Review PR
gh pr review <number> --approve
gh pr review <number> --request-changes --body "feedback"
gh pr review <number> --comment --body "looks good"

# PR review comments
gh api repos/{owner}/{repo}/pulls/{number}/comments --jq '.[].body'

# Add review comment on specific line
gh api repos/{owner}/{repo}/pulls/{number}/comments \
  -f body="comment" -f path="file.py" -F line=42 -f side="RIGHT" \
  -f commit_id="$(gh pr view <number> --json headRefOid --jq .headRefOid)"

# Check PR CI status
gh pr checks <number>

# Update PR branch
gh pr update-branch <number>
Issue
# List issues
gh issue list --json number,title,labels,assignees --jq '.[] | {number,title,labels:[.labels[].name]}'

# View issue
gh issue view <number> --json title,body,state,labels,assignees,comments

# Create issue
gh issue create --title "title" --body "description" --label "bug"

# Comment on issue
gh issue comment <number> --body "comment text"

# Close issue
gh issue close <number> --reason completed

# Edit issue
gh issue edit <number> --title "new title" --add-label "priority"

# Search issues
gh issue list --search "keyword in:title,body" --json number,title
リポジトリとファイル
# View repo info
gh repo view --json name,description,defaultBranchRef --jq '{name,description,branch:.defaultBranchRef.name}'

# Get file contents (use gh api to avoid raw output issues)
gh api repos/{owner}/{repo}/contents/{path} --jq '.content' | base64 -d
# Or with ref:
gh api repos/{owner}/{repo}/contents/{path}?ref={branch} --jq '.content' | base64 -d

# List directory
gh api repos/{owner}/{repo}/contents/{path} --jq '.[].name'

# Create/update file
gh api repos/{owner}/{repo}/contents/{path} \
  -X PUT \
  -f message="commit message" \
  -f content="$(echo -n 'file content' | base64)" \
  -f branch="branch-name"
# For update, include sha:
  -f sha="<blob_sha>"

# Delete file
gh api repos/{owner}/{repo}/contents/{path} \
  -X DELETE \
  -f message="delete file" \
  -f sha="<blob_sha>" \
  -f branch="branch-name"

# Push multiple files — use git directly
git add file1 file2 && git commit -m "message" && git push

# Create branch
gh api repos/{owner}/{repo}/git/refs \
  -f ref="refs/heads/new-branch" \
  -f sha="$(gh api repos/{owner}/{repo}/git/ref/heads/main --jq '.object.sha')"

# List branches
gh api repos/{owner}/{repo}/branches --jq '.[].name'

# Fork repo
gh repo fork {owner}/{repo}

# Create repo
gh repo create {name} --public --description "desc"
検索
# Search code
gh search code "query" --repo {owner}/{repo} --json path,repository,textMatches
gh search code "query language:python" --json path,repository

# Search repos
gh search repos "query" --json fullName,description,stargazersCount --jq '.[] | {name:.fullName,stars:.stargazersCount}'

# Search issues across GitHub
gh search issues "query" --json number,title,repository

# Search PRs
gh search prs "query" --json number,title,repository
コミットと履歴
# List commits
gh api repos/{owner}/{repo}/commits --jq '.[].commit.message' | head -20
gh api repos/{owner}/{repo}/commits?sha={branch}\&per_page=10 --jq '.[] | {sha: .sha[:7], message: .commit.message}'

# View specific commit
gh api repos/{owner}/{repo}/commits/{sha} --jq '{message:.commit.message,files:[.files[].filename],stats:.stats}'

# Get commit diff
gh api repos/{owner}/{repo}/commits/{sha} -H "Accept: application/vnd.github.diff"
リリースとタグ
# List releases
gh release list --json tagName,name,publishedAt

# View latest release
gh release view --json tagName,name,body

# View specific release
gh release view {tag} --json tagName,name,body

# List tags
gh api repos/{owner}/{repo}/tags --jq '.[].name'

# Create release
gh release create {tag} --title "title" --notes "release notes"
高度な API アクセス

上記で扱われていない操作には、gh api を直接使用してください。

# GET request
gh api repos/{owner}/{repo}/actions/runs --jq '.workflow_runs[:3] | .[].conclusion'

# POST request
gh api repos/{owner}/{repo}/issues/{number}/comments -f body="comment"

# With pagination
gh api repos/{owner}/{repo}/issues --paginate --jq '.[].number'

# Get authenticated user
gh api user --jq '{login,name,email}'

# Team members
gh api orgs/{org}/teams/{team}/members --jq '.[].login'

出力の最適化

エージェントが処理しやすいよう、出力は常に最小限に抑えてください。

  1. 構造化された最小限の出力には --json と --jq を使用する
  2. --limit または API の per_page パラメーターで結果を制限する
  3. フィールドを選択する — オブジェクト全体を出力しないでください
  4. 長い出力は head にパイプする:| head -50

エラー処理

# Check if command succeeded
gh pr view 999 --json state 2>/dev/null && echo "exists" || echo "not found"

# Safe API call with error handling
gh api repos/{owner}/{repo}/contents/{path} 2>/dev/null || echo "file not found"

コメント