Remote GitHub PR
Use this skill when the user wants a change made directly on GitHub without a local clone or local worktree.
Core rules
- Do not clone the repository.
- Do not create or edit local copies of the target repo just to make the change.
- Prefer
gh apiREST calls over GraphQL when either works. - Make the smallest possible remote change that fully satisfies the request.
- Do not open a PR until you have verified the remote branch contains the intended diff.
When this skill is a good fit
- The user says
不用克隆代码到本地,直接用gh远程修改,直接提PR, or similar. - The change is focused and can be made by editing one or a few existing files remotely.
- The repo is on GitHub and the current
ghsession has permission to read, push, and open PRs.
When to stop and realign
- The repo cannot be identified confidently from the user's wording.
- The change is broad enough that reading many files locally would normally be safer.
- The remote edit would require generating many new files or doing multi-file refactors with high risk.
- The target file cannot be found remotely or the repo permissions are insufficient.
Workflow
- Identify the repository.
- Confirm
gh auth statussucceeds. - Discover the target file and current content remotely.
- Read only the minimum content needed to understand the requested change.
- Create a new remote branch from the default branch or the user-specified base branch.
- Apply the change through GitHub APIs.
- Read the changed file back from the new branch.
- Compare the branch against base and verify the final diff is exactly what was intended.
- Create the PR only after the diff is clean.
- Return the PR URL and summarize the final remote change.
Repo discovery
Prefer this order:
- If the user gives
owner/repo, use it directly. - If the user gives a product or service nickname like
backend crm, search likely GitHub repos withgh search repos. - If multiple repos are plausible, stop and ask the user which one they mean.
Useful commands:
gh auth status
gh search repos "backend crm org:Mercaso" --limit 20
gh api repos/OWNER/REPO --jq '.default_branch'
gh api repos/OWNER/REPO/git/trees/BRANCH?recursive=1
Remote file editing
Prefer the GitHub Contents API for small file edits:
- Read the current file SHA and content from the base branch.
- Decode the content carefully.
- Apply a precise text change.
- Upload the updated file to the feature branch with the current file SHA.
For content reads, strip newlines from base64 before decoding:
$b64 = gh api repos/OWNER/REPO/contents/path/to/file?ref=master --jq .content
$text = [System.Text.Encoding]::UTF8.GetString(
[System.Convert]::FromBase64String(($b64 -replace "`r|`n", ""))
)
Safety checks for edits
- Prefer exact string replacement over clever regex when the target text is short and stable.
- If regex is necessary, verify the replacement result before uploading.
- If the replacement does not change the text, stop and inspect the source instead of forcing a write.
- After writing, always read the file back from the feature branch.
- Always inspect the compare diff before creating the PR.
Branch creation
Create a dedicated feature branch remotely from the base branch commit SHA.
Suggested naming — derive the prefix from the agent executing this skill:
- If you are Codex:
codex/<short-task-slug> - If you are Claude (Claude Code / Cowork):
claude/<short-task-slug> - Any other agent: use its lowercase name as the prefix
- include a date suffix when collision risk is high
If uncertain about which agent you are, confirm via shell env before creating
the branch (e.g. Claude Code sets CLAUDECODE=1):
[ -n "$CLAUDECODE" ] && echo claude || echo codex
Example:
$baseSha = gh api repos/OWNER/REPO/git/ref/heads/master --jq .object.sha
gh api -X POST repos/OWNER/REPO/git/refs -f ref="refs/heads/codex/my-change" -f sha="$baseSha"
Diff verification
Always compare the feature branch to base before opening the PR:
gh api repos/OWNER/REPO/compare/master...codex/my-change
Review:
ahead_by- changed files
- patch content
Do not create the PR if the diff contains accidental deletions, empty-file writes, malformed replacements, or unrelated changes.
Recovery
If a remote write goes wrong:
- Do not open the PR.
- Fix the same branch with a corrective commit.
- Re-run file readback and compare checks.
- Only continue once the final diff matches the requested change.
PR creation
Use a concise title and body that explain:
- what changed
- why it changed
- how you verified it remotely
Example:
gh pr create --repo OWNER/REPO --base master --head codex/my-change --title "Increase prod memory limit to 1024Mi" --body "## Summary
- update prod deploy memory limit to 1024Mi
## Verification
- read back the changed file from the remote branch
- compared feature branch against master and confirmed the final diff is only the intended line change"
Response checklist
Before telling the user the work is done, confirm all of these are true:
- repo identified
- auth valid
- branch created
- file changed remotely
- changed file read back successfully
- compare diff matches intent
- PR created successfully
Example triggers
不用克隆代码到本地,直接用 gh 改一下然后提 PRremote edit this GitHub repo and open a PR直接在 GitHub 上改配置文件,创建新分支use gh only, no local checkout