home / skills / gwenwindflower / .charmschool / gh-cli-use

gh-cli-use skill

/agents/claude/skills/gh-cli-use

This skill helps you manage GitHub repos safely with gh by guiding reads, scope, and non-destructive actions before making changes.

npx playbooks add skill gwenwindflower/.charmschool --skill gh-cli-use

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
3.8 KB
---
name: gh-cli-use
description: |
  Safely use the GitHub CLI (gh) working with GitHub repos beyond standard git operations: creating, forking, or cloning new remote repos, triggering and monitoring GitHub Actions, or working with Issues and Pull Requests.
---

# gh CLI Usage

## Safety Rules

- **Read before write.** Use `list`, `view`, `status`, `diff`, `checks` before any write operation.
- **Scope every command.** Use `-R OWNER/REPO` unless clearly inside the target project directory.
- **No destructive commands without explicit user instruction.** Destructive/high-risk subcommands: `delete`, `close`, `merge`, `revert`, `archive`, `unarchive`, `transfer`, `lock/unlock`, `release delete`, `cache delete`, `run delete`.
- **Protect secrets.** Never log tokens or print `gh auth token` output.

For commands not covered below, consult the [gh CLI reference map](gh-cli-guide.md).

## Common Start-up Errors

**When:** switching repos, or on permission errors, check for common issues:

- Confirm repo:
  - Explicit (preferred): `gh repo view -R OWNER/REPO`
  - Implicit (CWD matches known repo and project path): `gh repo view`
- Verify auth: `gh auth status`

Note the active account and canonical `OWNER/REPO` before proceeding.

## GitHub Issues

**When:** asked to find, summarize, update, or work on an Issue.

1. List: `gh issue list -R OWNER/REPO`
2. Read: `gh issue view <number>`
3. Work on: `gh issue develop <number>` (creates branch + easy flow to PR when ready via `gh pr create [--title <title>] [--body <description>]` or `gh pr create --fill-verbose` to use the list of commit messages as description)

Creating a batch of issues from a task list or plan markdown file is a common workflow:

1. Read the file and extract tasks
2. `gh issue create` for each task
3. Ask user if you should start on the first issue
4. If yes, `gh issue develop <number of first created issue>`

If specifically asked, you can close issues, though usually this should be done by linking then to a PR that gets merged -- sometimes this is useful for cleaning up old issues though: `gh issue close <number>`

## Pull Requests

**When:** asked to review a PR, diagnose CI failures on a PR, move a draft to ready for review, or prepare a merge.

### Inspect (read-only)

- `gh pr list <number>`
- `gh pr view <number>`
- `gh pr diff <number>`
- `gh pr checks <number>`

### Provide Feedback

- Lightweight: `gh pr comment <number> --body "<notes>"`
- Formal review (when requested): `gh pr review <number> ...`

### Merge (high-risk)

Do **not** merge unless the user explicitly requests it and specifies the strategy. Typically, once reviews are approved and CI checks are passing, a merge with the preferred strategy will happen automatically, so manual merges should be rare and only done with clear user instructions.

- `gh pr merge --squash|--rebase`

**Always** preserve clear linear history, unless the user explicitly request a merge that will create a merge commit. Use `--squash` if the PR consists of many commits, if the PR is a couple of small, clear commits with good messages, a `--rebase` may be preferable. Most of the time though, `--squash` with a clear story is the safest choice.

## GitHub Actions

**When:** running CI, fetching run results, or triggering builds.

- List workflows: `gh workflow list`
- View a workflow: `gh workflow view <workflow>`
- Trigger a run: `gh workflow run <workflow>`
- Watch a run: `gh run watch <run-id>`
- Rerun failed jobs: `gh run rerun <run-id>`

## Other Needs

The `gh` CLI is very deep and well-designed, with great help text. If you need to do a less common operation, check the [reference guide](gh-cli-guide.md) for the right command structure, and always follow the safety rules above. The reference guide may be out of date, so it's good to check the help text or, if necessary, the [latest docs from the manual](https://cli.github.com/manual/).

Overview

This skill helps you safely and effectively use the GitHub CLI (gh) to manage repositories, issues, pull requests, and GitHub Actions beyond basic git operations. It emphasizes read-before-write safety, scoped commands, and protecting secrets so changes are predictable and reversible. Use it to create, fork, clone, trigger CI, and interact with issues and PR workflows from the terminal.

How this skill works

The skill inspects repository context, authentication status, and relevant gh objects before performing actions. It uses read-only commands (list, view, status, diff, checks) to gather state, then prompts or executes gh operations with explicit scoping (-R OWNER/REPO) when the user authorizes changes. High-risk operations require explicit confirmation and a specified strategy.

When to use it

  • Creating, forking, or cloning repositories that require gh capabilities beyond git
  • Listing, summarizing, or creating GitHub Issues and batching tasks into issues
  • Reviewing, diagnosing, or preparing Pull Requests for merge (not merging without explicit consent)
  • Triggering, watching, or re-running GitHub Actions workflows and checking CI results
  • Inspecting repo state or authentication before performing write operations

Best practices

  • Always run read-only checks first: gh repo view, gh auth status, gh pr view, gh issue view, gh run watch
  • Scope every command with -R OWNER/REPO unless you are sure your CWD matches the target repo
  • Never expose tokens or print gh auth token output; keep secrets out of logs
  • Ask for explicit confirmation before destructive actions (delete, close, merge, transfer, archive, release delete)
  • Prefer --squash for merges to keep history linear unless the user requests a merge commit or rebase

Example use cases

  • Create issues from a project task list: parse markdown tasks, gh issue create for each, then begin work with gh issue develop
  • Diagnose a failing PR: gh pr view, gh pr diff, gh pr checks, then post comments or request changes
  • Trigger a workflow after a manual change: gh workflow run <workflow> and gh run watch <run-id> to monitor
  • Prepare a PR for merge: verify checks and approvals, then run gh pr merge --squash only with explicit user approval
  • Fork and clone a repo for quick experimentation while preserving scoped commands with -R

FAQ

How do I confirm I'm operating on the correct repo?

Use gh repo view -R OWNER/REPO for explicit confirmation, or gh repo view if your current working directory is the repository.

What do I do if CI fails on a PR?

Run gh pr checks <number> and gh pr view <number> to inspect failures, then either rerun jobs with gh run rerun <run-id> or leave a comment with gh pr comment <number> summarizing findings.