github-pr-via-gh-cli

github-pr-via-gh-cli is a skill for Claude Code, Codex from chen3feng/agent-skills. It costs 24 tokens per session (1,839 once invoked), scanned A, original, Apache-2.0.

A workflow for opening a GitHub pull request from the command line with GitHub's `gh` tool. A pull request is a request to review and merge changes from one branch into another.

In plain words
What is it for?
It helps create a branch, commit and push changes, fork a repository when needed, and open a pull request with the correct base branch and description.
Why use it?
It handles common decisions that can cause mistakes, such as whether to fork, which branch is the default, and how to submit a multi-part description.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/chen3feng/agent-skills/github-pr-via-gh-cli
Any agent
npx skills add chen3feng/agent-skills --skill github-pr-via-gh-cli
Clone the repo
git clone --depth 1 https://github.com/chen3feng/agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for github-pr-via-gh-cli

README.md
[![agentmods](https://agentmods.dev/badge/skills/chen3feng/agent-skills/github-pr-via-gh-cli.svg)](https://agentmods.dev/skills/chen3feng/agent-skills/github-pr-via-gh-cli)
Your own site
<a href="https://agentmods.dev/skills/chen3feng/agent-skills/github-pr-via-gh-cli"><img src="https://agentmods.dev/badge/skills/chen3feng/agent-skills/github-pr-via-gh-cli.svg" alt="Measured on agentmods" height="20"></a>
Per session 24 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,839 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00024 $0.01839
Opus 5 $0.00012 $0.00920
Sonnet 5 $0.00005 $0.00368
Haiku 4.5 $0.00002 $0.00184

Measured 3d ago against content hash e7c18dc8e9e6, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

github-pr-via-gh-cli scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/github-pr-via-gh-cli/SKILL.md · 178 lines

How it starts

The opening of the file, as written. The whole thing — 178 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Opening a GitHub PR via gh

When to use

The user says "open a PR" / "send a pull request" and gh is available (which gh succeeds). Works equally for first-party repos and forks.

Problem

Getting all of these right on the first try:

  • Do I need to fork, or can I push a branch directly?
  • What's the base branch (main vs master)?
  • Body with multiple paragraphs, backticks, and lists — how to pass?

Solution

  1. Determine push access and the fork question.

    gh auth status                 # who am I?
    git -C <repo> remote -v        # what does origin point to?
    
    • If origin is owned by the authenticated user → push directly to a branch, no fork needed.
    • Otherwise → fork first: gh repo fork --remote=true.
  2. Create a descriptive branch, commit, push.

    git -C <repo> checkout -b <slug>
    git -C <repo> add <paths>
    git -C <repo> commit -F .commit_msg.tmp    # see related skill
    git -C <repo> push -u origin <slug>
    
  3. Check the default branch, don't assume main:

    git -C <repo> symbolic-ref refs/remotes/origin/HEAD | sed 's@^.*/@@'
    
  4. Create the PR with a body file (see related skill):

    gh pr create \
      --repo <owner>/<repo> \
      --base <default-branch> \
      --head <slug> \
      --title "<one-line title>" \
      --body-file pr_body.md
    

    gh prints the PR URL on success. Capture it.

Example

gh pr create --repo chen3feng/cn-doc-style-guide \
  --base master --head add-md-style-tools \
  --title 'Add Python tools for checking and auto-fixing Chinese Markdown docs' \
  --body-file pr_body.md
# → https://github.com/chen3feng/cn-doc-style-guide/pull/1

Pitfalls

  • Anti-pattern — never do this:

    gh pr create --body "$(cat <<'EOF'
    … multi-line body with ``` fences, $(…), backslashes …
    EOF
    )"
    

    This triple-nests double quotes, command substitution, and a heredoc. In zsh (the default agent shell on macOS) any backtick fence or $(…) inside the body will unbalance the parser and the command hangs at cmdand dquote> / cmdand quote> — the agent sees "command interrupted" and the PR is never filed. Always write the body to a file via the editor tool and pass --body-file <path>. See shell-heredoc-and-multiline-strings.

  • --title with backticks or $ through the shell is still fragile; prefer --body-file and keep the title short enough to put in a single-quoted string.

  • --body "…\n…" does NOT give you line breaks. gh takes the value verbatim; \n stays as a two-character literal and the PR body on GitHub will show \n in the middle of sentences. Always use --body-file <path> for anything longer than one line (see shell-heredoc-and-multiline-strings).

  • Very long gh pr create invocations get backgrounded by some agent shells — the command appears to "hang" and the PR URL never comes back. Keep the command short (use --body-file instead of a giant inline --body), and verify with gh pr list --repo <owner>/<repo> --state open afterwards.

  • If you already created the PR and the body is malformed (e.g. literal \n showing up), fix it without a new PR:

Read the full file on GitHub · 178 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 178 lines · 24 tokens per session scan A e7c18dc8e9e6

Subscribe to this mod's changes

github-pr-via-gh-cli is a skill published in the GitHub repository chen3feng/agent-skills (5 stars, last pushed 3mo ago), licensed Apache-2.0. It adds 24 tokens to every session and 1,839 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.