---
name: wrong-session-guard
description: Guard against a prompt pasted into the WRONG terminal tab / Claude session. Run this FIRST, before doing any work, whenever a new task prompt references a specific PR, branch, ticket, feature, file, module, or component. Compares the prompt's subject against this session's actual git branch and recent work; if they clearly describe different work (e.g. prompt is about "bar PR" but this session is the "foo PR"), HALT and ask the user to confirm they pasted into the right tab instead of proceeding. Skip only for trivial/context-free prompts (greetings, "what does this do", questions about the current diff).
allowed-tools: Bash, AskUserQuestion
---

# wrong-session-guard

Catches the common mistake of pasting a prompt meant for one Claude session (tab 2 = "bar PR")
into a different session (tab 1 = "foo PR"). Each tab is pinned to its own branch/worktree, so a
mispaste means doing real work in the wrong context. Fail loud and early — before any edits.

## When to run

Run as the **first action** on a new task prompt that names specific work: a PR, branch, ticket,
feature area, file path, module, function, table, or component.

Do **not** run for context-free prompts: greetings, "continue", "what does this do?", "explain this
diff", or follow-ups that clearly build on the current conversation.

## Step 1 — establish THIS session's context (cheap, always)

```bash
git rev-parse --show-toplevel
git branch --show-current
git log --oneline -8
# default branch (main/master/dev), then the files THIS branch touches vs it:
base="$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null)"
git diff --name-only "${base}...HEAD" 2>/dev/null | head -40
gh pr view --json number,title,headRefName 2>/dev/null || true  # PR bound to this branch, if any
```

Also fold in the **current conversation**: which files/subsystems have we been editing this session?

## Step 2 — extract the incoming prompt's subject

From the pasted prompt, identify what it is actually about:

- explicit anchors: branch name, `PR #`, ticket ID, file paths, directory, package, table, component
- topical anchors: the feature/subsystem in prose (e.g. "the abuse-strikes ledger", "the landing redirect")

## Step 3 — compare and score the mismatch

**Strong mismatch (HALT)** — any of:

- Prompt names a branch / PR# / ticket that ≠ this session's branch/PR.
- Prompt's file paths or directories don't exist on this branch's diff and are a different subsystem
  than what this session has been working on.
- Prompt's feature area is disjoint from both the branch's diff and the conversation so far.

**Weak / ambiguous (WARN, then proceed)**:

- Overlapping area but different files, or the prompt is generic enough to plausibly belong here.

**Match (proceed silently)**:

- Prompt anchors line up with this branch's diff, PR, or the ongoing conversation. Do not mention the
  guard at all — no friction on the happy path.

Bias toward **proceeding** when signals are weak; only HALT on a *clear* cross-wire. False halts are
more annoying than a rare miss.

## Step 4 — on a strong mismatch, HALT

Do **not** read/edit/run anything toward the task. Report the collision plainly, then use
`AskUserQuestion` to force an explicit choice:

> ⚠️ This looks like it was meant for a different tab.
> - **This session** is on `foo/branch` (PR #123 — "foo feature").
> - **Your prompt** is about "bar feature" (mentions `path/to/bar`, PR #456).
>
> Did you paste into the wrong window?

Options:

1. **Wrong tab — stop** (recommended): do nothing; user will re-paste in the correct session.
2. **Right tab — proceed anyway**: intentional cross-branch work; continue with the task.

Only start the actual work if the user picks "proceed anyway". Never silently guess through a strong
mismatch.
