| name | init-sh |
| description | Generate an executable init.sh that bootstraps the dev environment (install, build, test, run commands) so fresh sessions can recreate state in one command. |
| when_to_use | Reach for this at the start of a project, after major tooling changes (new package manager, new build step), or when a fresh session needs to recreate state in one command. Do NOT use for resuming an existing session — use `/session-resume` instead; init-sh produces the script, session-resume reads it. |
| disable-model-invocation | true |
| allowed-tools | ["Read","Write","Glob","Grep","Bash"] |
| logical | repo-root init.sh exists, is executable, idempotent, and ends with one-line written-bytes report |
/init-sh — Bootstrap Script for Long-Running Sessions
Write an executable init.sh at the repo root that recreates the dev environment. Anthropic's pattern: pair it with claude-progress.txt so a fresh-context agent can catch up with two commands (bash init.sh, then read progress).
Process
-
Detect stack. Read (not just glob) the files that exist:
package.json → Node. Extract the scripts.start|dev, scripts.test, scripts.build.
composer.json → PHP/Laravel. Note scripts block; note artisan presence.
pyproject.toml / requirements.txt → Python. Note pytest, uvicorn, fastapi.
Cargo.toml → Rust. Standard cargo run / cargo test.
go.mod → Go. Standard go run ./... / go test ./....
Makefile → extract targets named install|setup|bootstrap|dev|test|run|start.
.env.example → note that it exists; agent will need to copy to .env.
docker-compose.yml / Dockerfile → note container-based setup.
-
Compose init.sh. Generate a script that:
- Sets
set -euo pipefail at the top.
- Installs dependencies (idempotent: only if the lock / vendor dir is missing or stale).
- Copies
.env.example to .env if .env missing (never clobbers).
- Runs any one-off migrations / seeders if detectable from the stack.
- Prints the dev-server command (does NOT start it — the agent chooses when).
- Prints the test command as a comment.
-
Idempotency check. Every step must be safe to re-run. Use [ ! -f ], [ ! -d ], or tool-specific no-op commands (npm ci is safer than npm install for re-runs).
-
Write + chmod. Use Write for the file, then chmod +x init.sh via Bash.
-
Report — one line: init.sh written (<N> bytes). Run: bash init.sh.
Execution Checklist
Output Structure
#!/usr/bin/env bash
set -euo pipefail
[ -f package-lock.json ] && [ ! -d node_modules ] && npm ci
[ -f composer.json ] && [ ! -d vendor ] && composer install
[ -f requirements.txt ] && [ ! -d .venv ] && python3 -m venv .venv && . .venv/bin/activate && pip install -r requirements.txt
[ -f .env.example ] && [ ! -f .env ] && cp .env.example .env
echo "dev server: <command>"
echo "test: <command>"
Known Failure Modes
- No recognizable stack → write a stub init.sh with a TODO comment; tell the user explicitly.
chmod +x fails → report; don't claim success.
- Existing init.sh at repo root → read it first; ask the user before overwriting.
Integration
- Committed
init.sh is picked up by surface-progress.sh (SessionStart) — future sessions get a hint to run it.
/session-resume reads progress + spec + features; if init.sh exists, reminds the user to run it first.
- Listed under
/rest-audit Reliability axis (environment reproducibility).