Skip to content

Commit b5757ea

Browse files
authored
Merge pull request cli#13244 from cli/kw/agent-skills
docs(skills): add gh and gh-skill agent skills
2 parents 3a6d4de + 74d3773 commit b5757ea

2 files changed

Lines changed: 197 additions & 0 deletions

File tree

skills/gh-skill/SKILL.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
name: gh-skill
3+
description: Manage agent skills with gh skill. Use this skill to discover, preview, install, update, and publish Agent Skills so an agent can self-manage the skills available in its environment.
4+
---
5+
6+
# Managing skills with `gh skill`
7+
8+
`gh skill` installs, previews, searches, updates, and publishes
9+
[Agent Skills](https://agentskills.io). An agent can use it to keep its
10+
own skill set in sync with one or more GitHub repositories.
11+
12+
The command is also aliased as `gh skills`. Prefer the canonical singular
13+
`gh skill` in scripts and docs.
14+
15+
## Search
16+
17+
```bash
18+
gh skill search <query> # free-text search
19+
gh skill search <query> --owner <org> # restrict to one owner
20+
gh skill search <query> --limit 20 --page 2
21+
gh skill search <query> --json skillName,repo,description
22+
```
23+
24+
## Preview before installing
25+
26+
```bash
27+
gh skill preview <owner>/<repo> <skill-name>
28+
gh skill preview <owner>/<repo> <skill-name>@v1.2.0 # pin a version
29+
```
30+
31+
## Install
32+
33+
```bash
34+
gh skill install <owner>/<repo> <skill-name>
35+
gh skill install <owner>/<repo> <skill-name>@v1.2.0
36+
gh skill install <owner>/<repo> skills/<scope>/<skill-name> # exact path, fastest
37+
gh skill install ./local-skills-repo --from-local
38+
```
39+
40+
`<owner>/<repo>` and `<skill-name>` are both required.
41+
42+
Useful flags:
43+
44+
- `--agent <id>` - target host (e.g. `github-copilot`, `claude-code`,
45+
`cursor`, `codex`, `gemini-cli`). Repeat for multiple. Default is
46+
`github-copilot` when non-interactive. You should know what agent you are,
47+
so set this appropriately to install for yourself.
48+
- `--scope project|user` - `project` (default) writes inside the current
49+
git repo; `user` writes to the home directory and applies everywhere.
50+
- `--pin <ref>` - pin to a tag, branch, or commit SHA. Mutually exclusive
51+
with `--from-local` and with inline `@version` syntax.
52+
- `--allow-hidden-dirs` - also discover skills under dot-directories such
53+
as `.claude/skills/`. Don't use this unless you need to, it comes with risks.
54+
- `--force` - overwrite an existing install.
55+
56+
## Update
57+
58+
```bash
59+
gh skill update --all # update every installed skill
60+
gh skill update <skill> # update one
61+
gh skill update <skill> --force
62+
gh skill update --unpin # drop the pin and move to latest
63+
```
64+
65+
## Publish
66+
67+
Publishing turns a repo into a discoverable skill source. Skills are
68+
discovered with these conventions:
69+
70+
- `skills/<name>/SKILL.md`
71+
- `skills/<scope>/<name>/SKILL.md`
72+
- `<name>/SKILL.md` (root-level)
73+
- `plugins/<scope>/skills/<name>/SKILL.md`
74+
75+
Each `SKILL.md` needs YAML frontmatter:
76+
77+
```yaml
78+
---
79+
name: my-skill # must equal the directory name
80+
description: One sentence... # required, recommended <= 1024 chars
81+
license: MIT # optional but recommended
82+
---
83+
```
84+
85+
### Validate, then publish
86+
87+
```bash
88+
gh skill publish --dry-run # validate only, no release
89+
gh skill publish --dry-run ./path/to/repo # validate a specific dir
90+
gh skill publish --fix # auto-strip install metadata
91+
gh skill publish --tag v1.0.0 # non-interactive publish
92+
gh skill publish # interactive publish flow
93+
```
94+
95+
`--fix` and `--dry-run` are mutually exclusive. `--fix` only rewrites
96+
install-injected `metadata.github-*` keys and does not publish; commit
97+
the result and re-run `publish`.
98+
99+
The publish flow will:
100+
101+
1. Add the `agent-skills` topic to the repo (so search can find it).
102+
2. Use `--tag` (or prompt for one in a TTY).
103+
3. Auto-push any unpushed commits.
104+
4. Create a GitHub release with auto-generated notes.
105+
106+
Always pass `--tag` so it doesn't fall through to the interactive flow.
107+
108+
## Self-management pattern for agents
109+
110+
A reasonable loop:
111+
112+
1. `gh skill search <topic> --json skillName,repo,namespace`
113+
2. `gh skill preview <repo> <skill>` to inspect the `SKILL.md`.
114+
3. `gh skill install <repo> <skill> --agent <host> --pin <ref>` for a
115+
reproducible install.
116+
4. Periodically `gh skill update --all` to refresh.

skills/gh/SKILL.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
name: gh
3+
description: Patterns for invoking the GitHub CLI (gh) from agents. Covers structured output, pagination, repo targeting, search vs list, gh api fallback.
4+
---
5+
6+
# Reference
7+
8+
## Interactivity policy
9+
10+
`gh` already does the right thing in non-TTY contexts: it skips the pager,
11+
strips ANSI color, and errors out fast with a helpful message instead of
12+
prompting (e.g. `must provide --title and --body when not running interactively`).
13+
You don't need to defensively set `GH_PAGER` or pass `--no-pager` (no such
14+
flag exists).
15+
16+
## Parsing JSON
17+
18+
Human output from `gh` is column-formatted. If you want structured data:
19+
20+
- Add `--json field1,field2,...` for structured output.
21+
- Run a command with `--json` and **no field list** to print the full set of
22+
available fields, then pick what you need.
23+
- Use `--jq '<expr>'` for filtering without piping through a separate `jq`.
24+
- Use `--template '<go-template>'` (alongside `--json`) when you want shaped
25+
text output. Note that `--template`/`-T` collides with a body-template flag
26+
on a few commands (e.g. `gh pr create -T`, `gh issue create -T`); always
27+
check `--help` before assuming which one you're hitting.
28+
29+
## Pagination and silent truncation
30+
31+
List commands cap results.
32+
33+
- `gh issue list`, `gh pr list`, `gh search ...`: pass `-L N` (`--limit N`).
34+
The default is usually 30.
35+
- `gh issue list` / `gh pr list` do not expose aggregate totals like
36+
`totalCount` via `--json`. If you need a true total, use `gh api graphql`
37+
to query `totalCount`; otherwise, treat `-L` as the cap for the current call.
38+
- For raw API calls use `gh api --paginate <path>`. Combine with
39+
`--jq` and (optionally) `--slurp` to assemble one array.
40+
41+
## Repo targeting
42+
43+
`gh` infers the repo from the cwd's git remotes.
44+
45+
Pass `--repo OWNER/REPO` (`-R`) to override the resolved CWD repo.
46+
47+
## Search vs list
48+
49+
- `gh search issues|prs|code|repos|commits|users` uses GitHub's search
50+
index and accepts the full search syntax (`is:open`, `author:`,
51+
`label:`, `repo:owner/name`, `in:title`, ...). Pass the entire query as
52+
one quoted string, the same way you would for `--search`:
53+
`gh search issues "is:open author:foo repo:cli/cli"`. Prefer it for
54+
anything cross-repo or filtered by author/label.
55+
- `gh issue list --search "..."` and `gh pr list --search "..."` accept
56+
the same syntax but are scoped to one repo.
57+
58+
## Fall back to `gh api` for anything `--json` doesn't expose
59+
60+
Sometimes useful data isn't on the typed commands. Examples:
61+
62+
- Review-thread comments on a PR: `gh api repos/{owner}/{repo}/pulls/{n}/comments`
63+
(the `--comments` flag on `gh pr view` shows issue-level comments only).
64+
- Arbitrary GraphQL: `gh api graphql -f query='...' -F var=value`.
65+
- REST shortcuts: `gh api repos/{owner}/{repo}/...` - note the
66+
`{owner}/{repo}` placeholder is filled in for you when run from a repo
67+
with detected remotes; pass them literally if you want determinism.
68+
69+
## Authentication
70+
71+
- `gh auth status` prints the active host(s), user, and which env var (if
72+
any) is being honored.
73+
- `gh auth status --json` is supported.
74+
75+
## Other notes
76+
77+
- `gh pr checkout <n>` switches branches. Use `gh pr diff <n>` or
78+
`gh pr view <n>` if you only need to read.
79+
- `NO_COLOR`, `CLICOLOR_FORCE`, and `GH_FORCE_TTY` are honored. Set
80+
`GH_FORCE_TTY=1` if you want TTY-style output (colors, tables, the
81+
pager, interactivity) inside an agent harness; leave it unset unless needed.

0 commit comments

Comments
 (0)