Launching skill: self-clear


Base directory for this skill: C:\Users\decid\.claude\skills\self-clear

# /self-clear

Wipes THIS agent's conversation (`/clear`), then ~200ms later TYPES a self-note
as a fresh user prompt so the agent wakes on a clean context and proceeds.

## Run it

One script does everything. Just run:

```powershell
& "C:\Users\decid\.claude\skills\self-clear\scripts\self-clear.ps1"
```

Expect: `SELF-CLEAR armed: id=<agent_id> winpid=<n> hwnd=<n> — /clear queued; self-note typed in ~200ms`

Then stop — end your turn promptly so the queued `/clear` fires.

## What the script does

1. `owl whoami` → resolves this session's `agent_id` (context-independent, survives the wipe). No perch → it aborts WITHOUT clearing and tells you to `/spt:ready` or `/spt:live` first.
2. Walks the parent chain (`pwsh → claude.exe → … → WindowsTerminal`) to the ancestor **pid that owns a visible top-level window** (enumerated by owner pid — not the program's default "main window", which is wrong when a host serves several windows). Since each WT window is its own process, that pid uniquely identifies this session's window. **Reliably focuses it** via `AttachThreadInput` (a background process can't otherwise hold the foreground) and **hard-verifies it genuinely holds the foreground** — aborts WITHOUT clearing and WITHOUT sending any keys if it can't.
3. Re-verifies foreground with **zero gap**, then types `/clear{ENTER}` in one SendKeys — **queued**; only fires when this turn ends.
4. Spawns a **detached** waker: waits 200ms (past turn-end + wipe), reliably re-focuses the captured `hwnd`, and — **only if that exact HWND genuinely holds the foreground** — **types** `Proceed with next steps` + Enter as a fresh user prompt. Otherwise it aborts the SendKeys (HWND identity is the guard; no title-match — Claude Code's terminal title animates and changes across `/clear`).

Why this matters: `SendKeys` hits whatever window is foreground *at send time*. The fix attaches our input queue to the foreground thread so the focus steal actually holds, confirms the target is truly foreground, and aborts rather than type blind — so the note can never leak into the window you're working in.

The delay + detachment are deliberate: the prompt must be typed **after**
`/clear` takes effect, so it lands on the clean context and starts a new turn.

Why typed, not `owl send`: after `/clear` the session sits idle awaiting user
input. A spooled owl message can't self-start a turn — it surfaces only during an
already-active turn (PreToolUse hook) or in a live Monitor stream (whose buffer
`/clear` wipes). So a self-addressed owl note never woke the agent. A typed prompt
deterministically starts a turn AND is the re-seed.

## Caveats

- Focus targets the window owned by this session's ancestor pid (enumerated by owner pid). It still can't pick a specific tab when one window hosts multiple tabs; clean when the agent's tab is active.
- The waker types only when our exact window is foreground. If you switch to a different window/tab during the ~200ms gap, the wake-note SendKeys is aborted (the agent stays cleared but unwoken) — stay in the agent window for the wake.
- The note is typed via SendKeys, so the terminal must stay the foreground-able window of `winpid`. Don't close/replace the terminal in the gap.
- SendKeys reserves `+ ^ % ~ ( ) { } [ ]`; the default note text uses none. If you customize the note, escape those chars.
- The waker waits only ~200ms after the script returns, so stop promptly — if your turn runs longer, the prompt could be typed before the wipe completes.

ARGUMENTS: W5 DONE + doyle GATE PASS (@edf03e0, nit @f0cfa0c). Tree clean @c336811 on v0.13.0-delivery-control. NEXT = W4 picker UX (doyle assigned mine, doyle gates). Read V0.13.0-W4-PICKER-UX-PLAN.md — 4 fixes: (1) open on Pick-existing, n=Create new; (2) auto-attach after Start-new+Resume, h=headless; (3) controlled-by shows node NAME via node_label_display not hex; (4) drop pid=Some(...)/internals leak from Start-new output. GROUND the picker code FIRST (anchors in plan). Extend REQ-RUN-PICKER; live keypress = HITL verify. Discipline: tests via ONE spt-test-engineer background no-Monitor ≤4-iter; gates = clippy --workspace --all-targets -D warnings + traceable-reqs check EXIT=0 + real cargo build -p spt --bin spt; never clobber running daemon exe. Tag REQ evidence same commit. Commit trailer: Co-authored by: todlando.


/clear


Running self-clear. W4 resume context is durable in `V0.13.0-W4-PICKER-UX-PLAN.md` @c336811 + the commune.


PowerShell

Self-clear context, re-seed for W4


SELF-CLEAR armed: id=todlando winpid=11076 hwnd=65976 title="⠐ Proceed with next steps" — focus held + /clear queued; self-note typed in ~200ms (waker aborts unless our window holds foreground)


Proceed with next steps


Self-clear armed. Ending turn so `/clear` fires.

W5 done + doyle GATE PASS. Tree clean @c336811. W4 picker UX queued — plan + commune durable. Waking fresh on clean context.