---
description: Safely flush context and resume fresh - distills session state before clearing
argument-hint: ""
allowed-tools:
  - Read
  - Edit
  - Write
  - Bash(date:*)
---

Persist session state then seamlessly resume work. The user should not notice this happening.

**Emergency mode** (compacting/prompt-too-long): Skip reads, distill from in-context memory only, go to Step 3.

---

## Steps

### Step 0: Reset gate + get date

```bash
date +"%m%d%y %H:%M" && rm -f ".claude/logs/.quality-gate-active" ".claude/logs/.session-blocks-$(date +"%m%d-%H")" ".claude/logs/.tool-call-count" ".claude/logs/.compaction-occurred"
```

### Step 1: Read state (parallel, skip in emergency)

Read simultaneously: `.claude/memory.md` + `Daily Notes/MMDDYY.md`

### Step 2: Distill session (from in-context memory)

Extract and compress using **restorable compression**:

1. **Task** — one sentence
2. **Done/remaining** — 2-4 bullets
3. **Decisions** — one line each, WHAT+WHY
4. **Learnings** — rules/facts for knowledge-nominations
5. **Files touched** — full paths of every file read or modified
6. **Active references** — URLs, external resources consulted (pointers only)
7. **Next action** — precise, actionable instruction including which file(s) to read first

### Step 3: Write handoff to daily note

Append to `Daily Notes/MMDDYY.md`:

```markdown
## Session Handoff — HH:MM

**Task:** [one sentence]
**Done:** [bullets]
**Remaining:** [bullets]
**Decisions:** [bullets]
**Files:** [full paths]
**Refs:** [URLs — pointers only]
**Next:** [precise action + which file(s) to read first]
```

### Step 4: Update memory.md (only if changed)

New priorities, threads, decisions → edit. Nothing changed → skip.

### Step 5: Promote and nominate learnings (only if discovered)

**Tier 1: Immediate promotion to `knowledge-base.md`** (high-confidence rules):
- User overrides: `[Source: User directive MMDDYY]`
- Empirical facts: `[Source: Empirical MMDDYY]`

**Tier 2: Nominate to `knowledge-nominations.md`** (lower-confidence):
- `- [MMDDYY] /safe-clear: [learning] | Evidence: [source]`

**When in doubt, promote. A rule that gets corrected later is better than a rule never seen.**

### Step 6: Auto-resume

Do NOT output a resumption prompt. Do NOT ask the user anything. Instead:

1. Re-read `.claude/memory.md` and `.claude/knowledge-base.md`
2. Re-read the daily note handoff you just wrote
3. Re-read the file(s) specified in the **Next** field
4. Immediately execute the Next action

The user should experience a brief pause, then work continuing seamlessly.

Target: 5-7 tool calls, <30 seconds. Emergency: 2-3 calls, <15 seconds.
