Gh Cli Ops
Overview
Use gh + git to manage GitHub repositories, automation, and releases with repeatable, safe workflows.
Quick start (context)
- Use the wrapper so commands are logged:
scripts/ghx auth status, scripts/ghx repo view, git status -sb.
- Identify the task category and use the matching section or the command map in
references/gh-command-map.md.
- Prefer JSON output (
--json ... --jq ...) for scripted reads; ask before destructive changes (delete, merge, release delete, secret overwrite).
- Review
references/auto-summary.md to adapt based on recent successes/failures.
Automation wrapper (required)
- Use
scripts/ghx for all gh commands to log outcomes to references/usage-log.jsonl.
- The wrapper auto-updates
references/auto-summary.md after each command to capture what worked or failed.
- If you must run
gh directly (e.g., debugging), run scripts/track_command.sh gh ... afterward with the same args.
Task map
See references/gh-command-map.md for a task-to-command mapping and safe defaults.
Workflows & runs
- Use
gh workflow list/view/run to inspect or trigger workflows. Ensure the workflow supports on: workflow_dispatch before running.
- Provide inputs via
-f/-F or --json when needed; confirm expected inputs from the workflow file.
- Use
gh run list/view/watch/rerun/download to monitor or re-run jobs; use gh run view --log/--log-failed for logs.
- For deploys, identify the deploy workflow and trigger it via
gh workflow run with the correct --ref and inputs.
- If
gh workflow run fails with HTTP 403 and Resource not accessible by integration, check for GITHUB_TOKEN or GH_TOKEN in the environment. Unset them or replace with a PAT that has workflow permissions, then retry.
- Quick fix for local shells:
GITHUB_TOKEN= gh workflow run "<workflow>" -f key=value (clears the env var for that command).
- In GitHub Actions, prefer
GH_TOKEN set to a PAT or GitHub App token when you need to trigger workflows; the default GITHUB_TOKEN can be too limited for dispatching other workflows.
Secrets & variables
- Use
gh secret for Actions/Dependabot/Codespaces secrets; use gh variable for Actions/Dependabot variables.
- Scope to repo/org/environment as needed; check
gh secret set --help and gh variable set --help for scope flags.
- Prefer stdin or
--body to avoid shell history; confirm overwrite and scope with the user.
Releases & tags
- Use
gh release list/view/create/download/delete.
- Prefer
--generate-notes for release notes when appropriate; confirm tag names and target commits.
Deployments & environments
- For deployment environments, use environment-scoped secrets/variables (
-e <env>).
- For deployment history or custom deploy APIs, use
gh api with --paginate and --jq as needed.
PRs, issues, and repo admin
- Use
gh pr and gh issue for everyday collaboration.
- Use
gh repo view/fork/clone/sync for repo operations.
- Keep git operations (branching, rebasing, pushing) explicit and separate from gh steps.
API & advanced
- Use
gh api for endpoints not covered by built-in commands.
- Capture JSON with
gh api ... --jq or --paginate for large lists.
Troubleshooting auth
Resource not accessible by integration usually means the CLI is using an integration token (often GITHUB_TOKEN) that cannot dispatch workflows. Prefer a PAT stored via gh auth login --with-token or set GH_TOKEN to a PAT with workflow permissions; avoid leaving GITHUB_TOKEN exported in local shells.
GH_TOKEN/GITHUB_TOKEN environment variables override stored gh auth. If you see unexpected 403s, unset them or replace with a PAT/GitHub App token that has Actions/workflow permissions before retrying.
Self-improving loop (automated + manual)
Automated (always on when using scripts/ghx):
- Command outcomes are logged to
references/usage-log.jsonl.
scripts/auto_improve.py updates references/auto-summary.md and can append repeatable learnings to references/gh-ops-notes.md.
Manual (when new patterns are discovered):
- Append new command patterns, flags, or pitfalls to
references/gh-ops-notes.md.
- If a command/flag is missing or changed, update
references/gh-command-map.md.
- Run
scripts/refresh_gh_reference.sh to refresh references/gh-help.md from the locally installed gh.
Resources
scripts/
scripts/ghx: wrapper that logs gh command outcomes and triggers auto-summary updates.
scripts/track_command.sh: logs command outcomes to references/usage-log.jsonl.
scripts/auto_improve.py: generates references/auto-summary.md and auto-notes.
scripts/refresh_gh_reference.sh: regenerate references/gh-help.md from local gh help output.
references/
references/gh-command-map.md: task-to-command map and safe defaults.
references/gh-help.md: auto-generated help snapshot from the local gh version.
references/gh-ops-notes.md: living notes for patterns, pitfalls, and team conventions.
references/auto-summary.md: auto-generated success/failure summary for recent commands.
references/usage-log.jsonl: append-only command log (redacted).
1---2name: gh-cli-ops3description: GitHub CLI (gh) operations for repos, PRs/issues, workflows/runs, secrets/variables, releases/tags, and deployment-related automation. Use when a request involves gh commands, GitHub Actions workflows/runs, secrets or variables, releases, deployments/environments, or coordinating git with GitHub.4---56# Gh Cli Ops78## Overview9Use gh + git to manage GitHub repositories, automation, and releases with repeatable, safe workflows.1011## Quick start (context)121. Use the wrapper so commands are logged: `scripts/ghx auth status`, `scripts/ghx repo view`, `git status -sb`.132. Identify the task category and use the matching section or the command map in `references/gh-command-map.md`.143. Prefer JSON output (`--json ... --jq ...`) for scripted reads; ask before destructive changes (delete, merge, release delete, secret overwrite).154. Review `references/auto-summary.md` to adapt based on recent successes/failures.1617## Automation wrapper (required)18- Use `scripts/ghx` for all gh commands to log outcomes to `references/usage-log.jsonl`.19- The wrapper auto-updates `references/auto-summary.md` after each command to capture what worked or failed.20- If you must run `gh` directly (e.g., debugging), run `scripts/track_command.sh gh ...` afterward with the same args.2122## Task map23See `references/gh-command-map.md` for a task-to-command mapping and safe defaults.2425## Workflows & runs26- Use `gh workflow list/view/run` to inspect or trigger workflows. Ensure the workflow supports `on: workflow_dispatch` before running.27- Provide inputs via `-f`/`-F` or `--json` when needed; confirm expected inputs from the workflow file.28- Use `gh run list/view/watch/rerun/download` to monitor or re-run jobs; use `gh run view --log/--log-failed` for logs.29- For deploys, identify the deploy workflow and trigger it via `gh workflow run` with the correct `--ref` and inputs.30- If `gh workflow run` fails with `HTTP 403` and `Resource not accessible by integration`, check for `GITHUB_TOKEN` or `GH_TOKEN` in the environment. Unset them or replace with a PAT that has workflow permissions, then retry.31- Quick fix for local shells: `GITHUB_TOKEN= gh workflow run "<workflow>" -f key=value` (clears the env var for that command).32- In GitHub Actions, prefer `GH_TOKEN` set to a PAT or GitHub App token when you need to trigger workflows; the default `GITHUB_TOKEN` can be too limited for dispatching other workflows.3334## Secrets & variables35- Use `gh secret` for Actions/Dependabot/Codespaces secrets; use `gh variable` for Actions/Dependabot variables.36- Scope to repo/org/environment as needed; check `gh secret set --help` and `gh variable set --help` for scope flags.37- Prefer stdin or `--body` to avoid shell history; confirm overwrite and scope with the user.3839## Releases & tags40- Use `gh release list/view/create/download/delete`.41- Prefer `--generate-notes` for release notes when appropriate; confirm tag names and target commits.4243## Deployments & environments44- For deployment environments, use environment-scoped secrets/variables (`-e <env>`).45- For deployment history or custom deploy APIs, use `gh api` with `--paginate` and `--jq` as needed.4647## PRs, issues, and repo admin48- Use `gh pr` and `gh issue` for everyday collaboration.49- Use `gh repo view/fork/clone/sync` for repo operations.50- Keep git operations (branching, rebasing, pushing) explicit and separate from gh steps.5152## API & advanced53- Use `gh api` for endpoints not covered by built-in commands.54- Capture JSON with `gh api ... --jq` or `--paginate` for large lists.5556## Troubleshooting auth57- `Resource not accessible by integration` usually means the CLI is using an integration token (often `GITHUB_TOKEN`) that cannot dispatch workflows. Prefer a PAT stored via `gh auth login --with-token` or set `GH_TOKEN` to a PAT with workflow permissions; avoid leaving `GITHUB_TOKEN` exported in local shells.58- `GH_TOKEN`/`GITHUB_TOKEN` environment variables override stored gh auth. If you see unexpected 403s, unset them or replace with a PAT/GitHub App token that has Actions/workflow permissions before retrying.5960## Self-improving loop (automated + manual)61Automated (always on when using `scripts/ghx`):621. Command outcomes are logged to `references/usage-log.jsonl`.632. `scripts/auto_improve.py` updates `references/auto-summary.md` and can append repeatable learnings to `references/gh-ops-notes.md`.6465Manual (when new patterns are discovered):661. Append new command patterns, flags, or pitfalls to `references/gh-ops-notes.md`.672. If a command/flag is missing or changed, update `references/gh-command-map.md`.683. Run `scripts/refresh_gh_reference.sh` to refresh `references/gh-help.md` from the locally installed `gh`.6970## Resources71### scripts/72- `scripts/ghx`: wrapper that logs gh command outcomes and triggers auto-summary updates.73- `scripts/track_command.sh`: logs command outcomes to `references/usage-log.jsonl`.74- `scripts/auto_improve.py`: generates `references/auto-summary.md` and auto-notes.75- `scripts/refresh_gh_reference.sh`: regenerate `references/gh-help.md` from local gh help output.7677### references/78- `references/gh-command-map.md`: task-to-command map and safe defaults.79- `references/gh-help.md`: auto-generated help snapshot from the local gh version.80- `references/gh-ops-notes.md`: living notes for patterns, pitfalls, and team conventions.81- `references/auto-summary.md`: auto-generated success/failure summary for recent commands.82- `references/usage-log.jsonl`: append-only command log (redacted).