Catch the common mistake of pasting a prompt meant for one terminal tab / Claude Code session
into a different one. If you run multiple Claude Code sessions side-by-side — tab 1 on the
foo PR, tab 2 on the bar PR — it's easy to paste tab 2's prompt into tab 1 and have it start
editing the wrong branch. This stops that before any work happens.
Two layers, both user-scoped (nothing project-specific required):
| File | Role |
|---|---|
session-context.sh |
Hook (UserPromptSubmit). Injects the current tab's git identity — repo, branch, PR, files the branch touches — into context on every prompt. Makes the mispaste impossible to miss. |
wrong-session-guard.SKILL.md |
Skill. Structured compare + halt. When a prompt clearly concerns different work than the injected context, it stops and asks whether you pasted into the wrong tab. |
The hook auto-detects your repo's default branch (main / master / dev), so no config.
# 1) Skill
mkdir -p ~/.claude/skills/wrong-session-guard
curl -fsSL <this-gist>/wrong-session-guard.SKILL.md -o ~/.claude/skills/wrong-session-guard/SKILL.md
# 2) Hook
mkdir -p ~/.claude/hooks
curl -fsSL <this-gist>/session-context.sh -o ~/.claude/hooks/session-context.sh
chmod +x ~/.claude/hooks/session-context.shThen register the hook in ~/.claude/settings.json (merge into any existing UserPromptSubmit
array — don't replace it):
{
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{ "type": "command", "command": "bash $HOME/.claude/hooks/session-context.sh" }
]
}
]
}
}Restart Claude Code (hooks load at startup).
- The script carries no secrets. Its output, however, includes your live branch names, PR titles, and changed file paths — fine for normal use, just remember that if you share raw session logs from a private repo.
- Requires
git;gh(GitHub CLI) is optional and only used to show the bound PR. - Calibrated to bias toward proceeding — it only halts on a clear cross-wire, so the happy path stays frictionless.
Built with Claude Code.