8a3abff2d6
- lib.sh: TMUX_SERVER_NAME env var, _tmux helper, shim externalized to TMPDIR with recursive guard, resolve_tmux_server helper for YAML-driven server routing - multi-agent-create: --tmux-server opt-in flag, YAML tmux_server field for orphan prevention - multi-agent-delete/resume/status/agent-sessions-monitor: use resolve_tmux_server to auto-route to correct isolated server - SKILL.md × 4: documented isolation server workflow - Verified by claude review (R1+re-run) + agy R2 patches (orphan prevention + shim location fix)
6.9 KiB
6.9 KiB
name, description, version, author, license, platforms, environments, metadata
| name | description | version | author | license | platforms | environments | metadata | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| multi-agent-delete | Terminate an agent tmux session (claude, antigravity/agy) and update ~/PuKi/lab/agent_sessions/agent-sessions.yaml to mark it terminated with timestamp. Does NOT delete on-disk conversation artifacts (jsonl/db) — those are preserved for future resume. Use when ending a work session, switching to a different one, or cleaning up before a fresh start. | 1.0.0 | godopu | MIT |
|
|
|
Multi-Agent Delete — Terminate an Agent tmux Session
Companion skills:
multi-agent-create(start),multi-agent-resume(re-attach),agent-sessions-monitor(live status). Tmux Isolation:delete명령은 YAML의tmux_server필드를 자동으로 파싱하여 해당 격리 서버의 세션을 안전하게 종료(kill)하므로,TMUX_SERVER_NAME환경변수를 수동으로 지정할 필요가 없습니다. Single source of truth:~/PuKi/lab/agent_sessions/agent-sessions.yaml.
What this skill does
Stop an agent's tmux session and mark the YAML entry as terminated. Preserves:
- The tmux session's recorded
pane.pid / cmd / cwd / mcp_attachmentsfor audit - The agent's on-disk conversation (claude
*.jsonl, agyconversations/*.db) — so the user canmulti-agent-resumelater - The
start_commandso a futuremulti-agent-create --session <name>reproduces the same tmux spec
The user explicitly chooses:
- soft delete (default): update YAML only; leave tmux running. Useful when "delete" really means "I'm done with this card".
- hard delete:
tmux kill-session+ update YAML. The default when the user says "kill it" or "end the session".
Pre-flight
SESSION_NAME=<workspace>-creator-<agent> # convention
AGENT_SESSIONS_YAML=~/PuKi/lab/agent_sessions/agent-sessions.yaml
# 1) Session is registered?
python3 -c "
import yaml
d = yaml.safe_load(open('$AGENT_SESSIONS_YAML'))
names = [s['name'] for s in d.get('tmux_sessions', [])]
if '$SESSION_NAME' not in names:
print('NOT in YAML — refusing to delete (no audit trail). Use multi-agent-create first, or pass --force-no-yaml.')
raise SystemExit(1)
"
# 2) Already terminated?
ALREADY=$(python3 -c "
import yaml
d = yaml.safe_load(open('$AGENT_SESSIONS_YAML'))
s = [x for x in d['tmux_sessions'] if x['name']=='$SESSION_NAME'][0]
print(s.get('status', 'unknown'))
")
if [ "$ALREADY" = "terminated" ]; then
echo "Already terminated at $(python3 -c "import yaml; d=yaml.safe_load(open('$AGENT_SESSIONS_YAML')); print([x for x in d['tmux_sessions'] if x['name']=='$SESSION_NAME'][0].get('terminated_at',''))")"
echo "Re-running will just refresh the timestamp. Continue? (--yes to skip)"
fi
Workflow
# 1. soft delete (YAML only — tmux left running)
bash ~/PuKi/lab/agent_sessions/skills/multi-agent-delete/scripts/delete_session.sh \
--session "$SESSION_NAME" --mode soft
# 2. hard delete (default — kill tmux + update YAML)
bash ~/PuKi/lab/agent_sessions/skills/multi-agent-delete/scripts/delete_session.sh \
--session "$SESSION_NAME" --mode hard
# 3. hard delete + clean up on-disk conversation (DANGEROUS)
# — this prevents any future resume. Use only when user is certain.
bash ~/PuKi/lab/agent_sessions/skills/multi-agent-delete/scripts/delete_session.sh \
--session "$SESSION_NAME" --mode hard --purge-conversation
The script:
- Verifies the session is in agent-sessions.yaml
- Captures the
last_visible_statusfromtmux capture-pane(so we have a final TUI snapshot for audit) - For
hardmode:tmux kill-session -t <name>(which auto-SIGTERMs children including the agent) - For
purge-conversation: deletes~/.claude/projects/.../jsonl(claude) or~/.gemini/antigravity-cli/conversations/...db+brain/...(agy) - Updates the YAML entry:
- name: <SESSION_NAME> status: terminated terminated_at: 2026-06-17T...Z terminated_at_epoch: ... # all original fields preserved
Pitfalls
tmux kill-sessiondoesn't just kill the session — it sends SIGHUP to the pane's child processes too. This is usually what you want (the agent process dies, no zombie reparenting to init). But if you wanted to keep the agent running outside tmux for some reason, usesoftmode.- Don't delete on-disk artifacts by default — the agent's
*.jsonl/conversations/*.dbis the data thatmulti-agent-resumeneeds.--purge-conversationis for when the user is genuinely done with the conversation and wants zero recovery chance. - YAML is append-only until you write a delete — if a previous run left the entry as
runningbut tmux is actually dead (crash, host reboot), the YAML is stale. Runningmulti-agent-delete --mode hardwill detect "tmux already dead, just update YAML" and proceed. - Don't delete the
claude_session_id_own: nullplaceholder — when the user creates a fresh session withmulti-agent-createand never sent a message, the entry hasclaude_session_id_own: null. Deletion must preserve that field (it's the audit trail showing "this tmux session never produced a session id of its own"). - Monitor skill may still be tracking — if
agent-sessions-monitoris running a heartbeat loop, deleting a session while it watches will trigger itstmux ls != yamlreconciliation. That's expected — let the monitor run, it will mark the entry asterminatedon its own. Don't fight it.
Verification
# 1. tmux gone
tmux has-session -t "$SESSION_NAME" 2>/dev/null && echo "STILL ALIVE" || echo "OK: tmux gone"
# 2. YAML has terminated entry
python3 -c "
import yaml
d = yaml.safe_load(open('$AGENT_SESSIONS_YAML'))
s = [x for x in d['tmux_sessions'] if x['name']=='$SESSION_NAME'][0]
assert s['status'] == 'terminated', f'expected terminated, got {s[\"status\"]}'
assert s.get('terminated_at'), 'missing terminated_at'
print(f'OK: terminated at {s[\"terminated_at\"]}')
print(f' preserved: pane.pid={s[\"pane\"][\"pid\"]}, cmd={s[\"pane\"][\"cmd\"]}, cwd={s[\"pane\"][\"cwd\"]}')
"
# 3. (if --purge-conversation) disk artifacts gone
[ -f "$HOME/.claude/projects/<projkey>/<uuid>.jsonl" ] && echo "WARN: jsonl still exists" || echo "OK: jsonl purged"
When NOT to use this skill
- Just detaching →
tmux detach(Ctrl-B d) or just close the terminal. The tmux session keeps running. - Stopping the agent inside but keeping tmux → send
Ctrl-Cor/exit(claude) /Ctrl-D(agy) viatmux send-keys. The tmux session stays but the agent process is gone; you can thenmulti-agent-createagain to spawn a fresh agent in the same tmux session. - Replacing an existing session with a new one →
multi-agent-delete --mode hardfirst, thenmulti-agent-create.