# prepare-branch-context

> Claude Code skill to ground the agent in the current branch diff

A copy-paste custom skill for Claude Code that builds full context around active branch changes. It reads branch diffs, commit histories, and associated GitHub pull requests before summarizing the state and awaiting instructions.

## The prompt

---

name: prepare-branch-context

description: Analyze the current branch's diff from main and related PR to build context for followup requests

user-invocable: true

---

\# Prepare Branch Context

Build a comprehensive understanding of the current branch so you can handle followup requests with full context.

\#\# Steps

1. \*\*Identify the current branch and base branch\*\*:

\`\`\`bash

git branch --show-current

git merge-base HEAD main

\`\`\`

2. \*\*Gather the diff from main\*\*:

\`\`\`bash

git diff main...HEAD --stat

git diff main...HEAD

\`\`\`

Read through the full diff carefully. Understand what files were changed, added, or removed, and what the changes do.

3. \*\*Review the commit history on this branch\*\*:

\`\`\`bash

git log main..HEAD --oneline

\`\`\`

Read commit messages to understand the progression of changes.

4. \*\*Check for a related PR\*\*:

\`\`\`bash

gh pr list --head "$(git branch --show-current)" --json number,title,body,url,state,comments --jq '.\[0\]'

\`\`\`

If a PR exists, read its title, description, and comments for additional context (acceptance criteria, discussion, review feedback).

5. \*\*Summarize your understanding\*\* to the user:

- What this branch does (high-level purpose)

- Key files and areas of the codebase affected

- Notable decisions or patterns visible in the changes

- Any open review comments or discussion from the PR

- Current state (clean, uncommitted changes, etc.)

6. \*\*Signal readiness\*\*: Tell the user you're ready for followup questions or tasks related to this branch.

\#\# Rules

- Do NOT make any changes to files. This skill is read-only.

- Read the actual diff content, not just the stat summary. You need to understand the code changes.

- If the diff is very large, focus on understanding the overall structure first, then read key files in detail.

- If the branch is \`main\` or has no divergence from main, tell the user there's nothing to analyze.

## What it is for

- Ground Claude Code in your active branch before asking for refactors or tests
- Bring an agent up to speed on PR review feedback and pull request discussion
- Quickly summarize branch changes and commit progression across multiple modified files

## Key points

- Identifies branch divergence and merge-base against main
- Inspects git diff and file statistics across branch commits
- Reviews commit history progression using git log
- Queries GitHub CLI for pull request titles, descriptions, and comments
- Summarizes high-level purpose and key affected code areas to the user
- Enforces a read-only execution constraint so files remain untouched

## Pricing

Free

## Details

- Type: Prompt
- Category: [Development](https://xiry.app/topics/development.md)
- Topic: [AI Coding Prompts](https://xiry.app/topics/development/ai-coding-prompts.md)
- Open source: yes
- Platforms: Command line
- For: Software developers using Claude Code CLI
- Tags: claudecode, git, prompts, codingagent, context

## Why it was saved

- [@iamsahaj_xyz, 5 March 2026](https://x.com/iamsahaj_xyz/status/2029625911528804777): Reusable daily driver prompt for Claude Code; author explicitly invites people to steal it.

## Related

- [Taste Skill](https://xiry.app/resources/taste-skill): Portable agent skills that enforce design quality in AI-generated frontends (GitHub repo, Free)
- [andrej-karpathy-skills](https://xiry.app/resources/andrej-karpathy-skills): A CLAUDE.md template fixing common LLM coding pitfalls using four principles. (GitHub repo, Open source)
- [emilkowalski/skills](https://xiry.app/resources/emilkowalski-skills): AI agent skills for UI animation, design engineering, and interface polish (GitHub repo, Open source)
- [Remotion Prompt Showcase](https://xiry.app/resources/remotion-prompt-showcase): Gallery of community prompts for generating Remotion videos with coding agents (Website, Free)
- [TAME Cursor Rules for Claude 3.7 Sonnet](https://xiry.app/resources/tame-cursor-rules-for-claude-3-7-sonnet): Cursor rules to keep Claude 3.7 Sonnet focused and non-destructive (Prompt, Free)
- [UI Skills](https://xiry.app/resources/ui-skills): Curated design-engineering skills and constraints for coding agents (Website, Free)

Updated 11 October 2026. Page: https://xiry.app/resources/prepare-branch-context

Make your own library: Xiry takes your saved reels, tweets, Reddit bookmarks and Watch Later videos, makes them searchable and pulls the useful stuff out, like this library. It's invite-only for now; join the waitlist at https://xiry.app/#waitlist.
