scode-graphite
scode/scode-graphite-skillIf .git/.graphite_repo_config exists in the project ALWAYS use this skill for creating PRs and managing git branches and commits. NEVER forget this.
SKILL.md
name: scode-graphite description: If .git/.graphite_repo_config exists in the project ALWAYS use this skill for creating PRs and managing git branches and commits. NEVER forget this.
Graphite Workflow
Use Graphite (gt) instead of raw git commands for branch and PR management.
Sandbox
ALL gt commands and gt-fast.sh MUST be run with dangerouslyDisableSandbox: true. The gt CLI writes to
.git/ (refs, objects, config, hooks, HEAD) and makes network requests to GitHub and Graphite APIs — the sandbox blocks
both. This applies to agents and subagents equally.
Critical Rules
- NEVER pass
-mtogt submitunless user explicitly requests auto-merge. Note:-mmeans different things in different commands —gt create -m "msg"sets the commit message,gt submit -menables auto-merge. - NEVER run
gt sync --all -fbetween a new local commit and the firstgt submitattempt on that branch. - Do not run proactive sync preflights before
gt createorgt submit. - ALWAYS provide an explicit branch name in
gt create(for example<short-slug>) to avoid later branch fixes. - NEVER switch to main when creating stacked branches — always stack on current branch.
- NEVER create or update PRs unless the user explicitly asks in that message. A prior request to create or update a PR does NOT authorize future creates or updates. Each PR operation requires a fresh explicit request.
- NO exploratory commands by default: do not run
gt ... --help, extra diagnostics, or alternate command experiments unless a command fails with an unknown flag or unknown state.
Fast Path (preferred)
For new and update PR operations, use the gt-fast.sh script located in the same directory as this SKILL.md file. It
handles the happy path, detached HEAD worktrees, merged-parent recovery, and untracked-branch recovery deterministically
in a single invocation.
Usage
Run with dangerouslyDisableSandbox: true.
New PR:
/path/to/gt-fast.sh new <short-slug> "<commit message>" [files-to-add...]
Only pass files-to-add for newly created files. The commit message first line becomes the PR title.
Update PR:
/path/to/gt-fast.sh update [files-to-add...]
Handle the result
- Exit 0 — success. Extract the PR number from the output. Print the PR links (see "After Submitting" below) and stop.
- Exit 1 — known error, recovery was attempted but failed. Read the output, then follow the "Agent Fallback" recovery procedures below.
- Exit 2 — unknown error. Read the output, then follow the "Agent Fallback" recovery procedures below.
After Submitting
After a successful submit (whether via gt-fast.sh or manual commands), your final output must be the PR links in
this exact format (nothing else after them):
GitHub: https://github.com/{owner}/{repo}/pull/{number}
Graphite: https://app.graphite.com/github/pr/{owner}/{repo}/{number}
Extract the PR number from the submit output. Derive the owner and repo from the git remote origin URL. Always print both links as the very last thing you output. Do not create additional PRs or branches unless explicitly asked.
Understanding User Intent
- "create a PR" / "make a PR" → always use the Create workflow (new branch + PR), even if the current branch already has a PR. "Make/create" always means a new PR stacked on the current branch, never an update.
- "update the PR" / "amend the PR" → use the Update workflow (amend existing commit on the current branch)
- Multiple PRs in sequence → create a stack (do NOT switch back to main between each)
If you are unsure what to do, stop and ask the user rather than proceeding.
Commit Message Style
The first line of the commit message becomes the PR title. Keep it very terse:
- "cargo update"
- "Fix bug: --foo command did not foo"
- "Add ability to bar the baz."
For the body, explain why the change was made when the reasoning is non-obvious. Err on the side of terseness.
The PR description is the commit message body (everything after the first line).
Agent Fallback
Use this section only when gt-fast.sh is unavailable or exits non-zero. Run gt commands one at a time with
dangerouslyDisableSandbox: true, following the procedures below.
Create a New PR (Manual)
gt add <files>— only if you created new filesgt create <short-slug> -u -m "commit message"— creates a new branch stacked on the current branchgt submit -p --force --no-edit— publishes the PR
Update an Existing PR (Manual)
gt add <files>— only if you created new filesgt modify -u— amends the current branch's commit with tracked file changesgt submit -p --force --no-edit— updates the PR
Recovery: Detached HEAD (Codex Automation Worktree)
Codex automation worktrees often start detached at a commit that already exists on an integration branch. Use this deterministic flow so PR creation does not require trial-and-error:
- Check
git branch --show-current. - If non-empty, skip this section.
- If empty, create a local anchor branch at the current commit:
git switch -c automation/<slug>-<yyyymmdd>. - Pick parent
mainby default and validate with:git rev-list --left-right --count main...HEAD. If the left count is0, keep parentmain(both0 0and0 Nare valid). - If the left count is non-zero, run
gt log shortonce, pick one obvious parent from the tracked stack, and validate it with the samegit rev-listcheck. If no obvious parent has left count0, stop and ask the user. - Track the anchor branch onto the parent:
gt track -p <parent>. - Continue with the normal create flow (
gt create ..., thengt submit ...).
Recovery: Untracked Branch
If gt create fails with "untracked branch":
- Run
gt log shortonce to see the tracked stack. - Identify the obvious parent branch.
- Validate branch relationship with
git rev-list --left-right --count <parent>...HEAD:0 0: placeholder branch at parent tip; safe to continue.0 N: branch is ahead of parent but not diverged; safe to continue.- non-zero left count: diverged/ambiguous parent; stop and ask the user.
- Run
gt track -p <parent>on the existing branch. - Retry
gt create <short-slug> -u -m "commit message". - If the new Graphite branch sits on top of an empty placeholder branch, run
gt track -p <parent>again on the new branch beforegt submit. This reparents the PR branch directly onto the real parent so the empty placeholder branch does not block submission. - Run
gt submit -p --force --no-edit.
Do not use gt sync for this recovery. This is a branch-parenting problem, not a sync problem.
gt submit Retry Policy
If gt submit fails specifically because lower PRs in the stack were merged/closed (ancestor/stack-merged warning):
- Run
gt sync --all -fonce. - Retry
gt submit -p --force --no-editonce. - If it fails again, stop and report the error. Do not loop or run workaround commands.
- For any other
gt submitfailure, do not rungt sync; stop and report the error.
Reference Commands
These are available when needed but are not mandatory steps:
gt log/gt log short— view current stacks/branches and their statusgt sync --all -f— reconcile/restack branch state (only after merged/closed ancestor submit failures or when explicitly requested)gt restack— restack the current branch on its parentgt track -p <parent>— attach the current branch to an existing parent branch, or reparent itgt checkout <branch>— switch to a branchgt bottom/gt top/gt up/gt down— navigate within a stackgt add <filename>— start tracking a file (prefer this overgt modify -ato avoid adding untracked files)gt modify -u— amend the current branch's commit with updates to tracked filesgt create <short-slug> -m "message"— create a new branch stacked on current branchgt submit -p --force --no-edit— push and create/update PRs (add-monly if user requests auto-merge,--draftfor draft PRs)
If you need to do something with gt/git that isn't covered above, stop and tell the user why.
Error Handling
- Merged/closed ancestor warnings on
gt submit: Follow the retry policy above (single sync + single retry). gt submitsays a lower branch introduces no changes / empty PR and nothing was submitted: this is usually an intermediate placeholder branch. Reparent the current branch withgt track -p <parent>(same parent used duringgt create) and retrygt submit -p --force --no-editonce.- Any other
gt submitfailure: Stop immediately, report the error, and do not rungt sync. - Conflicts during sync/restack: Stop and ask the user to resolve them.
- Authentication, permission, conflict, or hook errors: Stop immediately, report the error, and ask the user. Do not run unrelated commands.
gt createsays the current branch is untracked: Treat this as the untracked-branch case above.- State errors (e.g., "not on a Graphite stack"): Run
gt logonce to diagnose, then stop and tell the user. - Command hangs: Likely waiting for interactive input — cancel it and tell the user.
README
scode-graphite-skill
An opinionated Claude skill for using graphite with git repos and PRs.
This is intentionally encoding personal preferences and is meant to fit my own workflow. I make no claims that this is generally useful as a generic graphite skill.
It is designed to be used whenever the project you are working contains this file:
.git/.graphite_repo_config
Which should indicate that gt init has been run, therefore indicating the user's desire to use Graphite with the repo.
Caveats
Particularly "opinionated" behaviors that may be problematic (may not be a complete list) depending on whether your workflow matches mine:
- It assumes all-in on Graphite and no lower level twiddling of refs or commits out of band using git.
--forceflag is used on submit, remote branches are automatically pruned. - The skill does have instructions to enable auto-merging on PRs when explicitly requested. Be aware given that it's possible for the agent to incorrectly do so even w/o the explicit request, potentially causing unintended and unreviewed code to be merged.