Files
skills/skills/in-progress/spawn/spawn.sh
T
Matt PocockandClaude Opus 4.8 fc73c04a34 feat(spawn): generalise claude-handoff into agent-agnostic spawn skill
SKILL.md now only defines the handoff; per-agent launch mechanics
(claude --bg vs backgrounded codex exec) live in a bundled spawn.sh
the agent runs but never reads. Prompt arrives via heredoc/stdin so
long summaries with quotes survive.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 10:37:53 +01:00

43 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# spawn.sh <claude|codex> <name> [prompt|-]
# Launches a background agent session seeded with the prompt.
# Prompt is read from stdin when the third argument is omitted or '-'.
set -euo pipefail
usage() {
echo "usage: spawn.sh <claude|codex> <name> [prompt|-] (prompt read from stdin when omitted or '-')" >&2
exit 2
}
agent="${1:-}"
name="${2:-}"
prompt="${3:--}"
[ -n "$agent" ] && [ -n "$name" ] || usage
if [ "$prompt" = "-" ]; then
prompt="$(cat)"
fi
[ -n "$prompt" ] || { echo "spawn.sh: empty prompt" >&2; exit 2; }
case "$agent" in
claude)
claude --bg --name "$name" "$prompt"
echo "Spawned claude session '$name'. Manage it with: claude agents"
;;
codex)
slug="$(printf '%s' "$name" | tr '[:upper:] ' '[:lower:]-' | tr -cd 'a-z0-9-')"
dir="${TMPDIR:-/tmp}/codex-spawns"
mkdir -p "$dir"
base="$dir/${slug:-session}-$(date +%Y%m%d-%H%M%S)"
nohup codex exec --sandbox workspace-write --cd "$PWD" \
-o "$base.last.md" - <<<"$prompt" >"$base.log" 2>&1 &
echo "Spawned codex session '$name' (pid $!)."
echo " log: $base.log"
echo " final answer: $base.last.md"
echo " follow with: tail -f $base.log"
;;
*)
usage
;;
esac