ask-matt
MAmattpocock/skills336k4,217 new stars in the last 7 days
Backs up Codex/Claude/agy sessions across terminals, restores IDs in Ghostty and locates open tabs (保存会话/重启前备份/恢复窗口/会话找不到). Lists, attaches, saves and moves UU Remote sessions to ordinary Ghostty tabs (网易 UU). Audits survivors and takes automatic change-only snapshots (定期增量快照). Switches unmanaged Codex accounts (额度耗尽换号). Minions native_runtime uses Account Manager. Targets Ghostty input and background /compact (批量压缩). Use dedicated workflows for --resume help, standalone screenshots and general tmux administration.
Capture identifiable local Claude Code, Codex CLI, and Antigravity (agy) sessions before a
reboot and reopen recorded IDs afterwards. Manual snapshots grade liveness; automatic backups
store recovery metadata with explicit partial coverage and unknown liveness.
For computer-use observation or interaction with Ghostty, use Kimi computer use
(kimi-cu / mcp__kimi_cu__*). Never use Codex computer use (mcp__cua_repl)
for Ghostty, including screenshots, clicks, typing and tab/window management.
Prefer Kimi for ad hoc interaction. The existing osascript / System Events batch
restore helpers remain allowed under the foreground and reconciliation rules below.
Snapshot, planning and read-only checks may continue through their existing scripts.
If Kimi is unavailable, report that gap rather than substituting Codex computer use;
use an existing script only when it supports the task and is already authorized.
Never use either channel to bypass a host denial.
Snapshot, reconstruction, dry-run and reconciliation can proceed without taking the desktop. Actual restore uses global keyboard/clipboard input and is foreground work even when launched as a background shell job. Apply the current user's foreground authorization. When it already covers this app and action, notify and proceed without requesting another handoff or requiring a lease or idle proof. Coordinate observed competing use. On human takeover, actual agent competition or externally overwritten state, stop input and yield; do not restore your old focus. If foreground use is not authorized, continue preparation and read-only checks until the missing bounded authorization is supplied. Host denials remain binding.
For an authorized background compact operation, use the bundled native Ghostty
input route below. It addresses a bound terminal surface and leaves desktop
focus, tab selection, and the clipboard alone.
For sessions still running under a remote terminal host, check its live roster first and attach the existing sessions. To reopen UU conversations in ordinary Ghostty tabs or keep a recovery bundle before UU quits, follow UU migration.
For missing Codex terminals without confirmed Ghostty ownership, load the installed
read-codex-history Skill and follow its
terminal-session recovery recipe.
If the user has authorized Ghostty as the destination for verified sessions from
another terminal host, use the history reader to establish the original IDs, then
use this Skill to reconstruct and reopen the exact set.
Record the original terminal owner separately from the destination layout.
| You just said / want | Run |
|---|---|
| Quitting for an update / reboot ("重启前保存会话") | snapshot |
| Periodic backup, save only changes ("定期增量快照") | Read automatic-snapshots.md, then ghostty_watch.py install --apply |
| Rebooted, want tabs back ("恢复之前的窗口") | Inspect snapshot coverage first. If absent, outdated or partial (unresolved TUIs or retained-unverified rows), follow candidate selection before reconstructing the selected manifest and restoring it |
| "Which UU terminal sessions are open?" / "在 Ghostty 看 UU 会话" | Read the live roster and attach when opening tabs is requested |
| "Save the UU sessions before it quits" / "把 UU 会话搬到当前窗口的普通标签" | snapshot-uu, then plan and verify the move |
| "I can't find the restored sessions" / "我看不到这些会话" | Locate the existing Ghostty tabs and identify their windows before considering another restore |
| "Was anything lost?" / suspicion after restore | check; when coverage is partial, follow candidate selection before claiming the set is complete |
| Snapshot looks too large, or "which sessions were active after ?" | Follow time-window selection before choosing a restore set |
| One specific session to bring back | restore --only <id-prefix> |
| Compact specific Claude Code sessions in the background (批量压缩 Ghostty 会话) | Follow targeted input to discover sessions, preview and freeze the chosen targets, then run compact --from-plan |
Minions native_runtime session or managed account-adoption error | Follow account-owner selection |
| An existing Account Manager selects a legacy Ghostty terminal through its configured bridge | Follow the legacy terminal port; retain that caller's original operation |
| Unmanaged/legacy Codex quota running out; manually switching account, keeping all Codex work | Start with account-owner selection |
| After a switch, want the same sessions back ("换号后恢复原会话"); opening blocked or delegated | Follow the original-set recovery route |
For recovery, enter that selection route proactively when coverage is incomplete; do not wait for a count challenge. Keep older snapshot/retained IDs eligible even when their last activity ended earlier. Candidate discovery does not prove a tab was open at shutdown. Apply the latest wanted-set reconciliation, including explicit user closures, and verify readable history after restoring; a running process alone does not establish recovery.
Start with account-owner selection. For the selected independent-TUI workflow, follow save before switching and restore or resume the batch. For blocked or delegated reopening, follow the original-set route. Keep command examples, handoff, authorization and acceptance in that SOP. Implementation: ghostty_switch.py.
For an explicitly configured legacy-terminal integration, use the versioned JSON port, its native host, and bound-window AX reader through the terminal-port contract. Keep account policy and credentials with the calling product; preserve its native-runtime and shared-owner routes as separate operations.
Before reopening sessions, follow current-set reconciliation. Keep the same explicit manifest and selection through preview, restore and check.
# Before quitting (from any directory):
python3 <skill-dir>/scripts/ghostty_session.py snapshot
# After selecting the wanted set, preview it before any foreground input:
python3 <skill-dir>/scripts/ghostty_session.py restore --snapshot <manifest.json> --all --dry-run
# Carry the selected --only/--exclude options into this preview, then omit --dry-run to execute.
Without --all, manual manifests select active sessions only; automatic manifests
select their recorded set. Use --all to include waiting/quota/dead/stale/unknown rows.
The snapshot lands in ~/.ghostty-session/snapshots/ (home-relative, survives reboot).
Manual snapshots default to --scope all-cli: recognized interactive CLIs in
Ghostty, other terminal emulators and headless terminal processes. Use
--scope ghostty only for an explicitly Ghostty-only request. Automatic
backups remain Ghostty-only. A connection client such as ToDesk does not identify
the terminal owner: inspect CLI processes, not the remote-access service.
Remote-terminal containers such as NetEase UU Remote (uuyc-mux on
~/Library/Application Support/UURemote/tmux.sock) are non-Ghostty hosts.
--scope all-cli records their live sessions with terminal_owner: non-ghostty.
Automatic Ghostty-only backups exclude them. Use snapshot-uu before quitting
UU and check process survival separately.
Snapshots persist resumable AI sessions, unresolved TUIs and the observed
terminal_inventory, including ordinary-terminal cwd/process evidence. Use the saved
scope and unresolved rows to state coverage; Ghostty-only totals cannot establish
whole-machine session preservation. Non-AI commands remain evidence only.
Manual snapshots capture the Ghostty window/tab tree (windows -> tabs ->
terminal surfaces, with tab titles, name override, per-surface TTY/PID/cwd)
through the Ghostty scripting dictionary when available; window/tab mapping
then reads known in the report and manifest, unknown on fallback. If the user supplies a tab count, record it with snapshot --expected-tabs <N>;
do not use matching session/TTY totals as proof of current-window coverage.
State the window/tab coverage boundary before the update: unmapped_tab_ttys
are plain-shell tabs kept with session: null; sessions_without_tab are
headless or already-closed sessions. An empty observation
refuses to replace the previous backup. Non-AI commands and unresolved argv are
evidence, not instructions to execute automatically.
restore skips already-live IDs by default. It finishes with a bounded auto-check
that prints N/M present, a manual reopen command and a retry command containing only
missing IDs. Read that result before declaring success; per-tab SENT (unverified)
is a paste acknowledgement, not proof that a session reopened. Re-running the same
manifest opens only the IDs still missing. --dry-run prints commands without GUI actions.
Repeat current-set reconciliation after a manual handoff or any change in selection.
After process reconciliation, follow history-readiness acceptance
before claiming that the selected conversations are ready to read.
/compactUse targeted input to discover live Claude Code
sessions with compact --all-claude --dry-run --json. Freeze the chosen targets
with --dry-run --write-plan, inspect their TTYs, session IDs, anchors, titles,
and native terminal IDs, then dispatch with --from-plan. Stagger multiple
targets when they share provider throughput. Use --verify-timeout to read the
independent compact_boundary result for each target.
Read automatic-snapshots.md before installing
or operating scripts/ghostty_watch.py, including an upgrade of its installed
script copies. That SOP owns schedule/enable-state preservation, partial coverage,
change-only writes and native-round verification.
For Codex identity and indexed recovery, use the maintained
daymade-claude-code:read-codex-history dependency. Resolve that Skill's directory
from the current host; install its daymade-claude-code plugin through the host's
ordinary marketplace flow when authorized and absent. The script discovers a source
checkout or a separately installed sibling read-codex-history; other layouts use
--history-reader <reader-skill-dir> or GHOSTTY_CODEX_HISTORY_READER. Missing reader
or state index fails explicitly; do not replace it with a rollout corpus scan.
# Review candidates without writing state or opening tabs:
python3 <skill-dir>/scripts/ghostty_session.py reconstruct \
--history-reader <reader-skill-dir> --dry-run
# Build one chosen set in a NEW file; --only accepts unambiguous ID prefixes:
python3 <skill-dir>/scripts/ghostty_session.py reconstruct \
--history-reader <reader-skill-dir> --since <YYYY-MM-DD> \
--only <id-prefix-1> <id-prefix-2> --out <recovery-manifest.json>
# Restore the full selected set in one invocation, including waiting/quota rows:
python3 <skill-dir>/scripts/ghostty_session.py restore \
--snapshot <recovery-manifest.json> --all
Reconstruction merges the optional --snapshot (otherwise latest, if present) with
bounded recent indexed Codex candidates. --only filters this merged result, so the
output manifest contains exactly the requested rows even when a latest snapshot exists.
It verifies internal rollout identity using
the owning reader and marks each row past-snapshot or indexed-terminal-candidate.
Terminal evidence is source=cli or originator=codex-tui; actual TUIs can report
source=vscode. --terminal-source and --terminal-originator customize those
accepted metadata values. Subagents are excluded by the owning inventory's metadata,
not by underscores in filenames. --codex-home selects a nondefault Codex store.
Past membership proves only that a session appeared in that snapshot. Indexed
terminal candidates prove terminal origin, not that the tab was live at shutdown.
Review timestamps/titles and select the intended set before restore. --limit is a
hard cap on indexed candidates inspected; widen discovery bounds only when needed.
No snapshot means Claude and agy membership remain unknown;
reconstruction does not discover Claude or agy sessions. Preserve explicit
Claude/agy records from a known snapshot rather than claiming an exhaustive recovery.
The new manifest never changes snapshots/latest.json and refuses to overwrite an
existing output. Exit 0 means the selected evidence was verified; exit 1 means the
manifest lists rejected candidates requiring attention; exit 2 means invalid input
or unavailable evidence. Dry-run output is JSON for inspection.
claude and
/usr/local/bin/claude). Option values and prompt text cannot establish identity.
A fork selector names the parent; resolve the child's own ID from verified
transcript evidence, then resume that child without replaying fork or
--fork-session. Fresh TUIs likewise use transcript storage:
the session file born at or after the process started, in the project bucket
of the same cwd, internal identity verified. When several
fresh TUIs share one bucket, transcripts are assigned disjointly — one file
per TUI; an undecidable race (equidistant claims) refuses to the unresolved
section rather than guessing. For Antigravity (agy), argv selectors
(--conversation, -r, --resume) anchor directly; UUID-less agy TUIs are
anchored (lsof-brain) via open ~/.gemini/antigravity-cli/brain/<UUID>
handles filtered to top-level conversations (nesting_depth == 0) in read-only
conversation_summaries.db, failing closed to unresolved when the index is
unavailable or multiple/colliding parent handles appear. Live TUIs matching
neither way are persisted as unresolved rows and printed in the snapshot
report — visible, never silently dropped.dead-channel when a Claude transcript's tail carries a
structured isApiErrorMessage with "Login expired" — restoring such a tab reopens
history but the session stops at /login; the snapshot marks it so you can skip it.
Prose inside a conversation that merely discusses an error never counts.--settings .../settings/<name>.json when present, else
direct.codex resume launches, so opening before the switch finishes
means closing and restoring those tabs again. If switching accounts is the goal,
use the switch SOP instead.osascript keystrokes (System Events).
If the current host denies Ghostty UI automation, do not switch channels to
bypass it: prepare the selected manifest and exact user-run restore command,
then reconcile after permitted execution. Reboot recovery uses read-only
check --snapshot <manifest> --strict; account switching uses
the mode-bound switch check.windows block, restore
orders missing sessions by recorded relative tab order, moves existing selected
tabs through native move_tab actions and reapplies tab-level name override
values through the current TTY/session join. It preserves unrelated live tabs
and independently reads back order and titles. It returns to the initiating tab
only while selection still shows the last restored session; an external selection
is left untouched. If one initiating tab cannot be captured before a pending
restore, it stops before the first paste. Unsupported or unknown layouts retain
session-list order and skip layout writes. Follow
recorded tab layout restoration.no-artifact; restoring
them replays the same codex resume <id> and stays a best effort.If your Claude profiles inject config via environment (e.g. CLAUDE_CONFIG_DIR), record
prefixes in ~/.ghostty-session/profile-env.json so restored tabs boot the same profile
context:
{"research": "CLAUDE_CONFIG_DIR=~/.claude-profiles/research", "family": "HTTP_PROXY=http://127.0.0.1:7890"}
Without it, restores replay captured settings, profile and permission/model flags; process environment beyond argv remains unknown. The mapping is user-local data outside the skill bundle; no default mapping ships.
| Symptom | Cause / fix |
|---|---|
restore reports NOT OBSERVED | reconcile the current wanted set first; retry only still-wanted IDs, excluding intentional closures |
| Recovered sessions are hard to find in Ghostty | Locate their current windows and tabs |
no-artifact on a Codex session | the verified indexed session has no usable rollout; resume remains best-effort |
unknown Codex liveness | reader/index unavailable or identity ambiguous; resolve the dependency/store instead of choosing the first filename match |
dead-channel sessions restored anyway | expected: history reopens, session stops at /login; re-auth or switch provider |
check says present but tab looks empty | another live process already claimed that session id (e.g. resumed in another tab) |
| osascript refuses keystrokes | grant Accessibility (System Events) permission; verify with osascript -e 'tell application "System Events" to get UI elements enabled' |
| a brand-new tab is missing from the session list | a fresh TUI has no argv UUID and its transcript file appears with its first message; until then it shows under unresolved live TUIs. A late first message can fall outside the upper window defined by FIRST_WRITE_WINDOW_SECONDS and the candidate filters in the resolver |
| an obviously active session still shows as unresolved | replay the resolver against the real inputs instead of guessing: python3 -I + importlib to load scripts/ghostty_session.py, then call _claude_candidates(cwd, process_start_epoch) (or _codex_candidates), or _assign_agy_sessions for agy (inspect open brain/<UUID> handles via lsof and conversation_summaries.db read-only indexing). Empty candidates for Claude/Codex point at the filter layer — birth window, or _head_cwd identity verification failing closed on its shared MAX_IDENTITY_HEAD_BYTES head budget or a foreign sessionId — not at multi-TUI assignment. _head_cwd(path, expected_sid=sid) returning None while _head_cwd(path) returns a cwd isolates expected-identity/bounded-head verification; inspect the head to distinguish budget overflow from a foreign, missing, or invalid sessionId |
| a long-open TUI stays unresolved with no transcript of its own | nothing born in its start window means no fresh-TUI anchor: either the tab was never used, or it resumed an older session inside the TUI whose rollout predates the process start (outside the fresh-TUI window by design). Both are correct unresolved behavior — establish which before treating it as a defect |
osascript targeting Ghostty hangs or pops an Automation TCC modal from a remote shell | unapproved remote terminal hosts (e.g., uuyc-mux or another remote-access shell) trigger a blocking macOS Automation consent prompt even on direct tell application "Ghostty"; use native Swift CGWindowListCopyWindowInfo + AXUIElement for read-only inspection and wrap required osascript calls with timeout (see native observation boundary) |
| remote desktop or synthetic Unicode input is silently dropped in some Ghostty tabs while sibling tabs work | a Ghostty tab with an active uncommitted CJK IME preedit (markedText) silently swallows CGEventKeyboardSetUnicodeString (keyCode=0) events while clean tabs keep accepting them; switch the macOS input source to com.apple.keylayout.ABC (or clear the tab's preedit) before remote/synthetic input and restore afterward. For AX readback after input, wait >500 ms to clear Ghostty's AXValue cache (see native observation boundary) |
Some delegated batch runners end by returning an interactive shell in their own terminal; their lifecycle is distinct from the original sessions this skill snapshots and restores. Keep the following evidence boundaries:
Process exited proves only that its
foreground process ended. It does not identify which run it was, why it ended,
or what business result followed — read the run's own saved receipt (its
summary and stderr files) instead of the emulator's exit message.Last login prints the previous login record when a shell starts; it is not an
identifier of the current TTY's session, and matching its timestamp does not
attribute the tab.MAmattpocock/skills336k4,217 new stars in the last 7 days
MAmattpocock/skills336k4,217 new stars in the last 7 days
MAmattpocock/skills336k4,217 new stars in the last 7 days
OBobra/superpowers331k5,030 new stars in the last 7 days
AFaffaan-m/ECC314k3,503 new stars in the last 7 days
AFaffaan-m/ECC314k3,503 new stars in the last 7 days