|
15 | 15 | # scripts/team.sh --port <N> opencode server port (default 4096) |
16 | 16 | # scripts/team.sh --kill [session-name] |
17 | 17 | # |
18 | | -# Resuming is the default, not an opt-in: pane 0 runs `claude --continue`, |
19 | | -# which picks up the most recent conversation in this project's directory. |
20 | | -# That matters because killing this tmux session (the usual way to free up |
21 | | -# a port so a second project can use scripts/team.sh at the same time) used |
22 | | -# to also throw away the lead's context — there was no way back into the |
23 | | -# same conversation short of scrolling terminal history. `--continue` fixes |
24 | | -# that: kill the session, come back later, run scripts/team.sh again, the |
25 | | -# lead picks up where it left off. Pass --fresh on the rare run where you |
26 | | -# actually want a clean slate. |
| 18 | +# Resuming is the default, not an opt-in: pane 0 resumes the lead's own |
| 19 | +# Claude conversation, pinned to this session name via a stored UUID (see |
| 20 | +# .agents/.claude-session-id.<session-name>) rather than `claude --continue` |
| 21 | +# (which just means "the most recent conversation in this directory" — with |
| 22 | +# no notion of *which* tmux session started it, so a second team.sh session |
| 23 | +# name in the same repo, or even a one-off `claude` run there, could steal |
| 24 | +# the next --continue). That matters because killing this tmux session (the |
| 25 | +# usual way to free up a port so a second project can use scripts/team.sh at |
| 26 | +# the same time) used to also throw away the lead's context — there was no |
| 27 | +# way back into the same conversation short of scrolling terminal history. |
| 28 | +# The pinned session id fixes that: kill the session, come back later, run |
| 29 | +# scripts/team.sh again, the lead picks up its own thread — never someone |
| 30 | +# else's. Pass --fresh on the rare run where you actually want a clean |
| 31 | +# slate (this also mints a new pinned id, so future resumes follow it). |
27 | 32 | # |
28 | 33 | # Running two projects at once: opencode's server binds one port per |
29 | 34 | # process, so two projects both defaulting to --port 4096 collide — the |
|
66 | 71 |
|
67 | 72 | command -v tmux >/dev/null 2>&1 || { echo "team.sh: tmux not found" >&2; exit 1; } |
68 | 73 |
|
| 74 | +gen_uuid() { |
| 75 | + if command -v uuidgen >/dev/null 2>&1; then |
| 76 | + uuidgen | tr '[:upper:]' '[:lower:]' |
| 77 | + elif [ -r /proc/sys/kernel/random/uuid ]; then |
| 78 | + cat /proc/sys/kernel/random/uuid |
| 79 | + elif command -v python3 >/dev/null 2>&1; then |
| 80 | + python3 -c 'import uuid; print(uuid.uuid4())' |
| 81 | + else |
| 82 | + echo "team.sh: need uuidgen or python3 to mint a Claude session id" >&2 |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | +} |
| 86 | + |
69 | 87 | if tmux has-session -t "$SESSION" 2>/dev/null; then |
70 | 88 | echo "team.sh: session '$SESSION' already exists — attaching" |
71 | 89 | exec tmux attach -t "$SESSION" |
|
74 | 92 | mkdir -p "$REPO_ROOT/.agents" |
75 | 93 | printf '%s' "$PORT" > "$REPO_ROOT/.agents/.oc-port" |
76 | 94 |
|
77 | | -CLAUDE_CMD="claude --continue" |
78 | | -[ "$FRESH" -eq 1 ] && CLAUDE_CMD="claude" |
| 95 | +# Pin pane 0 to one Claude conversation per tmux session name (see usage |
| 96 | +# comment above for why --continue alone isn't enough). |
| 97 | +SESSION_ID_FILE="$REPO_ROOT/.agents/.claude-session-id.$SESSION" |
| 98 | +[ "$FRESH" -eq 1 ] && rm -f "$SESSION_ID_FILE" |
| 99 | + |
| 100 | +if [ -f "$SESSION_ID_FILE" ]; then |
| 101 | + CLAUDE_UUID="$(cat "$SESSION_ID_FILE")" |
| 102 | + # Fall back to re-minting under the same id if the stored conversation is |
| 103 | + # gone (history pruned, project path changed) so the pane never just dies. |
| 104 | + CLAUDE_CMD="claude --resume $CLAUDE_UUID || claude --session-id $CLAUDE_UUID" |
| 105 | +else |
| 106 | + CLAUDE_UUID="$(gen_uuid)" |
| 107 | + printf '%s' "$CLAUDE_UUID" > "$SESSION_ID_FILE" |
| 108 | + CLAUDE_CMD="claude --session-id $CLAUDE_UUID" |
| 109 | +fi |
79 | 110 |
|
80 | 111 | tmux new-session -d -s "$SESSION" -c "$REPO_ROOT" -n team |
81 | 112 |
|
|
0 commit comments