# Push To Forked PR

Push the current working tree directly to a GitHub PR whose head lives on a **fork**...

- Repository: https://github.com/hoangsonww/Claude-Code-Agent-Monitor (1136 stars)
- Category: Git and review
- License: MIT
- Last updated: 2026-10-31
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill push-to-forked-pr -g -a claude-code -y`
Codex: `npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill push-to-forked-pr -g -a codex -y`
Cursor: `npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill push-to-forked-pr -g -a cursor -y`
Gemini CLI: `npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill push-to-forked-pr -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add hoangsonww/Claude-Code-Agent-Monitor`

## Description

Push the current working tree directly to a GitHub PR whose head lives on a **fork**, without creating a new branch and without pushing to `origin` (which is usually the upstream). Invoke when the user says things like "push straight to PR #N", "push to the forked PR", "update PR from fork", "push these changes to #N directly", "commit and push to the PR", *especially* when they emphasise not creating a new branch or not pushing into the upstream repo. Use this **instead of** plain `git push origin` whenever the PR head repo differs from the local `origin` repo.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# push-to-forked-pr

The whole point of this skill: **`origin` is usually the upstream, but the PR's head is on someone else's fork.** Pushing to `origin` updates the upstream's branch, not the PR. You have to push to the fork.

GitHub allows this in two situations:

1. You are the **fork owner**, straightforward, you own that branch.
2. You are an **upstream maintainer** and the PR has `maintainerCanModify: true` (the "Allow edits from maintainers" checkbox the PR author leaves on by default). GitHub then lets the upstream's auth push to the fork branch.

If neither holds, abort and tell the user only the fork owner can push.

---

## Procedure

### 1. Read the PR's head metadata

```bash
PR_NUMBER=<N>
gh pr view "$PR_NUMBER" --json state,headRefName,headRefOid,headRepository,headRepositoryOwner,maintainerCanModify,url
```

Capture:

- `state`, bail if not `"OPEN"`.
- `headRepository.nameWithOwner` → the **fork** (e.g. `someone/Repo`).
- `headRepositoryOwner.login` → the fork owner.
- `headRefName` → the branch on the fork (usually matches local).
- `headRefOid` → the PR's current head SHA. Your local HEAD must be a descendant.
- `maintainerCanModify` → must be `true` if you are not the fork owner.

If `headRepository.nameWithOwner` matches the upstream's `nameWithOwner`, this PR is **internal**:

```bash
HEAD_BRANCH=$(gh pr view "$PR_NUMBER" --json headRefName --jq .headRefName)
HEAD_REF_OID=$(gh pr view "$PR_NUMBER" --json headRefOid --jq .headRefOid)
git merge-base --is-ancestor "$HEAD_REF_OID" HEAD && echo ok || echo NOT-DESCENDANT   # abort if NOT-DESCENDANT
git push origin "HEAD:${HEAD_BRANCH}"
```

Exit the skill once this push lands, do not continue to the fork-push steps below.

### 2. Confirm you can actually push

The rest: https://github.com/hoangsonww/Claude-Code-Agent-Monitor/blob/HEAD/.agents/skills/push-to-forked-pr/SKILL.md
