agentleFS
rkhozinovrkhozinov/claude-skills/skills/gh/SKILL.md

gh

Skill0 starsChanged 4 months agoMITView on GitHub

GitHub CLI (gh) full reference. Covers multi-account setup, auth switching, issues, PRs, reviews, inline comments via API, code search, merge queues, and common pitfalls.

  • Reads credentials
  • Commits and pushes

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 0 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use gh for all GitHub operations.

    line 9
  2. Very specific:

    Always use single quotes around jq expressions to prevent shell interpretation of $, backticks, etc.

    line 237
  3. Very specific:

    Auth mismatch: If gh says "could not determine repo owner", run ghswitch or gh auth switch --user <work-account>.

    line 241
  4. Very specific:

    Add --json field1,field2 to most commands for structured JSON output

    line 247
  5. Very specific:

    Add --jq '.expression' to filter JSON output

    line 248
  6. Very specific:

    Use gh api for any REST API endpoint not covered by built-in commands

    line 249
  7. Very specific:

    Default repo is inferred from the current git remote.

    line 250

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

GitHub CLI (gh) Reference

Use gh for all GitHub operations. Do NOT use the GitHub MCP plugin tools.

Multi-Account Setup

Accounts

AccountUseSSH Key
<work-account>Work (default)~/.ssh/id_rsa_work → github.com-work
rkhozinovPersonal~/.ssh/id_rsa → github.com

The shell auto-switches to <work-account> on every cd and on shell startup via ghswitch in ~/.zshrc.

Auth Switching

# Manual switch (rarely needed — ghswitch handles it)
gh auth switch --user <work-account>
gh auth switch --user rkhozinov

# Check active account
gh auth status --active

SSH Config

The ~/.ssh/config maps hosts to keys:

  • github.com → personal key (id_rsa)
  • github.com-work → work key (id_rsa_work)

<org> repo remotes use git@github.com-work:<org>/repo.git.

Issues

# List issues
gh issue list
gh issue list --state closed --limit 20
gh issue list --label "bug" --assignee "@me"

# View issue details
gh issue view 123
gh issue view 123 --json title,body,comments

# Create issue
gh issue create --title "Title" --body "Description"
gh issue create --title "Title" --body "Description" --label "bug" --assignee "user"

# Comment / close / reopen
gh issue comment 123 --body "Comment text"
gh issue close 123 --reason "completed"
gh issue reopen 123

# Search issues (cross-repo)
gh search issues "query" --repo owner/repo
gh search issues "query" --owner <org> --state open

Pull Requests

# List PRs
gh pr list
gh pr list --state merged --limit 10
gh pr list --author "@me"

# View PR details
gh pr view 123
gh pr view 123 --json title,body,commits,files,reviews,comments

# Create PR
gh pr create --title "Title" --body "$(cat <<'EOF'
## Summary
- Change 1

## Test plan
- [ ] Test A
EOF
)"

# Review PR
gh pr review 123 --approve
gh pr review 123 --request-changes --body "Feedback"
gh pr review 123 --comment --body "Comment"

# Comment on PR
gh pr comment 123 --body "Comment text"

# View PR comments (including review comments)
gh api repos/{owner}/{repo}/pulls/123/comments

# Merge PR
# Preferred — waits for checks + reviews, then merges via queue:
gh pr merge 123 --auto --squash
# Bypass merge queue (admin only):
gh pr merge 123 --squash --admin
# NOTE: --merge-queue flag does NOT exist in gh CLI

# Update PR
gh pr edit 123 --title "New title" --add-label "ready"

# PR diff and checks
gh pr diff 123
gh pr checks 123

Check Filtering

# Filter checks by status (pipe to jq — do NOT use --jq with !=)
gh pr checks 123 --json name,state,link | jq '.[] | select(.state != "SUCCESS" and .state != "SKIPPED")'
gh pr checks 123 --json name,state | jq '[.[] | select(.state == "FAILURE")] | length'

PR Reviews with Inline Comments (via API)

gh pr review does NOT support inline file-level comments. Use the REST API with a temp file.

Never pass nested JSON inline in shell commands. Shell quoting will mangle nested arrays/objects. Always write the payload to a temp file and use --input.

# 1. Write review payload to temp file
cat > /tmp/review-payload.json <<'EOF'
{
  "event": "COMMENT",
  "body": "Overall review summary here.",
  "comments": [
    {
      "path": "terraform/modules/vpc/main.tf",
      "line": 42,
      "side": "RIGHT",
      "body": "This CIDR block overlaps with the staging VPC."
    }
  ]
}
EOF

# 2. Submit the review via API
gh api repos/{owner}/{repo}/pulls/123/reviews \
  --method POST --input /tmp/review-payload.json

# 3. Clean up
rm -f /tmp/review-payload.json

Payload field reference

FieldRequiredDescription
eventYesAPPROVE, REQUEST_CHANGES, or COMMENT
bodyNoTop-level review summary
comments[]NoArray of inline comment objects
comments[].pathYesFile path relative to repo root
comments[].lineYesLine number in the diff
comments[].sideYesRIGHT (new code) or LEFT (deleted code)
comments[].bodyYesComment text (supports Markdown)
comments[].start_lineNoFirst line of a multi-line comment
comments[].start_sideNoSide for start_line

Replying to / editing an inline comment

# Reply to an existing inline comment (thread reply, not a new top-level comment)
jq -n --rawfile body /tmp/reply.md '{body: $body}' > /tmp/reply-payload.json
gh api repos/{owner}/{repo}/pulls/comments/{comment_id}/replies --input /tmp/reply-payload.json

# Edit an existing comment
gh api -X PATCH repos/{owner}/{repo}/pulls/comments/{comment_id} --input /tmp/reply-payload.json

# Always verify what actually landed — don't trust the POST/PATCH response body alone
gh api repos/{owner}/{repo}/pulls/comments/{comment_id} --jq '.body'

Code Search

gh search code "pattern" --repo owner/repo
gh search code "function_name" --owner <org> --language python
gh search repos "query" --owner <org>

File Contents (via API)

gh api repos/{owner}/{repo}/contents/{path} --jq '.content' | base64 -d
gh api repos/{owner}/{repo}/contents/{path}?ref=branch-name

Commits and Branches

gh api repos/{owner}/{repo}/commits --jq '.[].sha'
gh api repos/{owner}/{repo}/commits?sha=branch-name&per_page=10
gh api repos/{owner}/{repo}/branches --jq '.[].name'
gh api repos/{owner}/{repo}/git/refs -f ref="refs/heads/new-branch" -f sha="base-sha"

Releases

gh release list
gh release view v1.0.0
gh release view --latest
gh api repos/{owner}/{repo}/releases/tags/v1.0.0

--jq Expression Rules

NEVER use --jq with expressions containing !=. zsh history expansion rewrites != to \!= before gh receives it, causing jq parse errors. This happens even inside single quotes.

Workaround: Pipe to jq instead of using --jq:

# CORRECT — pipe to jq, zsh doesn't mangle the expression
gh pr checks 123 --json name,state | jq '.[] | select(.state != "SUCCESS")'

# WRONG — zsh rewrites != to \!= causing jq parse error
gh pr checks 123 --json name,state --jq '.[] | select(.state != "SUCCESS")'

For simple --jq expressions without !=, --jq is fine:

# OK — no != operator
gh pr view 123 --json title --jq '.title'

Always use single quotes around jq expressions to prevent shell interpretation of $, backticks, etc.

Common Pitfalls

  • Auth mismatch: If gh says "could not determine repo owner", run ghswitch or gh auth switch --user <work-account>.
  • Token scopes: Work token has gist, read:org, repo. If an operation fails with 403, check scopes with gh auth status.
  • -f key=@file doesn't expand: gh api -f body=@/path/to/file can post the literal string @/path/to/file instead of the file's contents (seen on pulls/comments POST/PATCH). Don't rely on @file expansion for comment bodies — build JSON with jq -n --rawfile body <file> '{body: $body}' and pass it via --input payload.json instead, then GET the comment back to confirm the body actually landed.

Tips

  • Add --json field1,field2 to most commands for structured JSON output
  • Add --jq '.expression' to filter JSON output
  • Use gh api for any REST API endpoint not covered by built-in commands
  • Default repo is inferred from the current git remote; use --repo owner/repo to override
  • Pagination: gh api --paginate for full results

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.