Sign in
Explore
Add-ons · HookEveryday codingReviewed

gsd-session-state.sh

SessionStart hook that outputs the head of STATE.md so each session starts oriented.

Kind
Hook
Works with
Claude Code, Gemini / Antigravity
Languages
Shell
Source
gsd-build/get-shit-done @ bdcaab2c752d
Path
hooks/gsd-session-state.sh
License
MIT
Jobs
Context management
InstallCopy it from the source repository, or sign in and let the assistant adapt it for your project.
#!/usr/bin/env bash
# gsd-hook-version: {{GSD_VERSION}}
# gsd-session-state.sh — SessionStart hook: inject project state reminder
# Outputs STATE.md head on every session start for orientation.
#
# OPT-IN: This hook is a no-op unless config.json has hooks.community: true.
# Enable with: "hooks": { "community": true } in .planning/config.json

# Check opt-in config — exit silently if not enabled
if [ -f .planning/config.json ]; then
  ENABLED=$(node -e "try{const c=require('./.planning/config.json');process.stdout.write(c.hooks?.community===true?'1':'0')}catch{process.stdout.write('0')}" 2>/dev/null)
  if [ "$ENABLED" != "1" ]; then exit 0; fi
else
  exit 0
fi

# Build the additionalContext text and emit it as a structured JSON
# envelope per the Claude Code SessionStart hook protocol (#2974). Tests
# parse the JSON and assert on typed fields (state_present: bool,
# config_mode: string, etc) rather than substring-matching free-form text.
STATE_PRESENT="false"
STATE_HEAD=""
if [ -f .planning/STATE.md ]; then
  STATE_PRESENT="true"
  STATE_HEAD=$(head -20 .planning/STATE.md)
fi

CONFIG_MODE="unknown"
if [ -f .planning/config.json ]; then
…