AgentSkillsCN

test-claude-resume-sid

测试 Claude Code 的 --resume 参数是否能保留会话 ID(SID),抑或会创建新的会话 ID。此技能适用于验证智能体会话行为、调试智能体管理系统,或确认在恢复会话时,同一会话的 SID 是否能在多个进程中保持一致。可响应诸如“测试 resume sid”“验证会话是否被保留”“检查 resume 是否能维持相同的会话 ID”等请求。

SKILL.md
--- frontmatter
name: test-claude-resume-sid
description: Test whether Claude Code --resume preserves the session ID (SID) or creates a new one. This skill should be used when verifying agent session behavior, debugging agent-management systems, or confirming that resuming a session maintains the same SID across multiple processes. Triggers on requests like "test resume sid", "verify session preservation", or "check if resume keeps the same session ID".

Test Claude Resume SID

Overview

This skill tests whether Claude Code's --resume <sid> flag preserves the original session ID or creates a new one (fork behavior). This is critical for agent-management systems that need to track sessions by SID across multiple processes.

When to Use

  • Verifying that cc --resume <sid> maintains session identity
  • Debugging agent-management server assumptions about SID:PID mappings
  • Confirming session behavior before implementing agent orchestration
  • Testing if multiple resumed processes share the same SID

Quick Start

Run the automated test script:

bash
python ~/.claude/skills/test-claude-resume-sid/scripts/test_resume_sid.py

Options:

  • --suffix <name>: Custom suffix for tmux session (default: random)
  • --keep: Keep tmux session alive after test for manual inspection

What the Test Does

  1. Creates a detached tmux session
  2. Runs cc "test prompt" in pane 0
  3. Extracts the session ID (SID) from the output
  4. Splits into 3 panes (horizontal + vertical split)
  5. Runs cc --resume <sid> in panes 1 and 2
  6. Extracts SIDs from all 3 panes
  7. Reports whether all SIDs match

Expected Results

PASS: All 3 panes show the SAME session ID

  • --resume preserves the original SID
  • Multiple processes can share one session identity
  • Agent-management servers can rely on requested_sid == observed_sid

FAIL: Panes show DIFFERENT session IDs

  • --resume created new SIDs (forked)
  • Each process has its own session identity
  • Agent-management servers must track resume_from_sid vs observed_sid

Manual Test Steps

To run the test manually:

bash
# 1. Create tmux session
tmux new-session -d -s sid-test -x 180 -y 50

# 2. Run initial cc
tmux send-keys -t sid-test:0.0 'cc "Hi, my secret is abc123"' Enter

# 3. Wait ~5 seconds, then capture SID
tmux capture-pane -t sid-test:0.0 -p | grep -oE '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'

# 4. Split panes
tmux split-window -h -t sid-test:0.0
tmux split-window -v -t sid-test:0.1

# 5. Resume in new panes (replace <SID> with actual SID)
tmux send-keys -t sid-test:0.1 'cc --resume <SID>' Enter
tmux send-keys -t sid-test:0.2 'cc --resume <SID>' Enter

# 6. Wait ~5 seconds, then capture all panes
tmux capture-pane -t sid-test:0.0 -p | grep -i "agent id"
tmux capture-pane -t sid-test:0.1 -p | grep -i "agent id"
tmux capture-pane -t sid-test:0.2 -p | grep -i "agent id"

# 7. Attach to inspect
tmux attach -t sid-test

Verifying via Logs

To confirm SID:PID mapping in centralized logs:

bash
# Find all PIDs for a given SID
grep "<SID>" ~/centralized-logs/claude/sse_lines.jsonl | \
  python -c "
import sys, json, re
pids = set()
for line in sys.stdin:
    obj = json.loads(line.strip())
    meta = obj.get('metadata', '{}')
    if isinstance(meta, str):
        m = re.search(r'\"pid\":(\d+)', meta)
        if m: pids.add(int(m.group(1)))
for p in sorted(pids): print(p)
"

If resume preserves SID, expect 3+ unique PIDs for the same SID.

Resources

scripts/

  • test_resume_sid.py - Automated test script that creates tmux session, runs cc commands, extracts SIDs, and reports results