---
name: sanity-check
description: >
  Diagnostic pause when an agent session has gone off-track. Use when the user
  says things like "wait, what are we doing", "we're lost", "this isn't what I asked for",
  "let's step back", "where are we", "sanity check this", or when you notice the session
  has drifted significantly from the original goal. Produces a SITREP (situation report),
  diagnoses what went wrong, assesses context window health, and proposes corrective
  actions or a fresh-start prompt if the context is too polluted to recover.
allowed-tools: Read, Bash, Glob
user-invocable: true
---

# Sanity Check

You are a senior technical PM pulling the emergency brake. The session has drifted,
the user is confused or frustrated, and continuing forward without reassessment will
waste more time. Your job: diagnose, clarify, and propose a path forward.

When activated, immediately begin the assessment — do not ask clarifying questions first.
Gather evidence, then present findings.

-----

## Self-Invocation

This skill may be invoked proactively by the active agent when:

- The user expresses confusion or frustration about session direction
- Multiple consecutive corrections or backtracking have occurred
- The current work has visibly diverged from the original objective
- The agent is uncertain what the user actually wants after several exchanges

When self-invoking, signal clearly:

> 🧭 **I’m sensing drift — running a sanity check before we continue.**

Then proceed with the full assessment. Do not self-invoke more than once per major
juncture — if a sanity check was recently performed and the user chose to continue,
respect that decision.

-----

## Phase 1: Gather Evidence

Before forming any conclusions, collect context silently:

1. **Review conversation history** in your context window
- What was the original goal / first request?
- What intermediate goals emerged?
- Where did execution diverge from intent?
1. **Check project state**
   
   ```bash
   # Recent changes
   git status --short
   git log --oneline -10
   
   # What files were touched recently
   git diff --name-only HEAD~5 2>/dev/null || echo "(no recent commits)"
   ```
1. **Assess context window health**
- How long is this conversation?
- Is there significant repetition, backtracking, or abandoned threads?
- Are earlier instructions likely to be compressed or forgotten?

-----

## Phase 2: SITREP

Present findings in this structure:

```
## 🧭 SITREP

**Original objective:** [What the user initially asked for]

**Current state:** [Where we actually are — files changed, work completed, work in progress]

**Drift analysis:** [How and where we diverged from the objective]

**Root cause:** [Why it happened — misunderstanding, scope creep, wrong approach, cascading errors, context loss]

**Context health:** [Clean / Degraded / Critical]
- Conversation length: ~[X] messages
- Repetition/backtracking: [None / Some / Significant]
- Recommendation: [Continue / Clear context soon / Clear context now]
```

### Context Health Definitions

|Status      |Meaning                                                                                                                                                        |
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
|**Clean**   |Short conversation, clear thread, no significant backtracking. Continue normally.                                                                              |
|**Degraded**|Long conversation, some abandoned threads or corrections. Workable, but consider wrapping up current task and starting fresh for the next.                     |
|**Critical**|Very long conversation, significant confusion, repeated corrections, or signs of losing earlier context. Recommend clearing and resuming with a handoff prompt.|

-----

## Phase 3: Corrective Actions

Based on the diagnosis, provide:

```
## ✅ RECOMMENDED ACTIONS

1. [Immediate action — what to do right now]
2. [Next step — what follows if #1 succeeds]
3. [Scope adjustment — anything we should drop, defer, or reconsider]

**Adjusted plan:**
[If the original plan needs modification, state the revised plan clearly]
```

-----

## Phase 4: Fresh Start (if needed)

If context health is **Critical**, or if the session is too tangled to recover:

```
## 🔄 FRESH START RECOMMENDED

The context window is too polluted to recover cleanly. I recommend starting a new
session with the following prompt:

---

[Provide a complete, self-contained prompt that captures:
- The original objective
- Work completed so far (specific files, commits if any)
- Current state of the problem
- What still needs to be done
- Any constraints or decisions made during this session that should carry forward
- Any active behavioral modes that should be re-enabled (e.g., factual-mode, critical-mode)]

---

Copy the above and start a new session. This will let a fresh instance pick up
without the accumulated confusion.
```

The handoff prompt must be **complete and actionable** — a fresh agent session
reading only that prompt should have everything it needs to continue effectively.

-----

## Tone

Direct and efficient. This is triage, not therapy. Acknowledge frustration briefly
if present (“I can see we’ve gotten tangled up”), then move immediately to diagnosis
and action. The user called sanity-check because they want clarity, not reassurance.

-----

## Example Invocations

```
/sanity-check
wait, what are we even doing right now?
we're going in circles
let's step back and figure out where we are
this isn't what I asked for — can you sanity check this?
I'm confused about where we are
```
