$ recombobulate _
home / tips / run-setup-scripts-on-every-session-with-the-sessionstart-hook
0

Run Setup Scripts on Every Session with the SessionStart Hook

bagwaa @bagwaa · Mar 26, 2026 · Workflows
run-setup-scripts-on-every-session-with-the-sessionstart-hook

The SessionStart hook fires whenever a Claude Code session begins or resumes. It is the right place for one-time setup tasks: loading environment variables, logging when work started, or printing a reminder before the first prompt.

// .claude/settings.json
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "echo \"Session started: $(date)\" >> ~/claude-sessions.log"
          }
        ]
      }
    ]
  }
}

A powerful pattern is injecting environment variables that persist for the whole session. Write to the $CLAUDE_ENV_FILE path and every subsequent Bash command in that session has access to those variables:

#!/bin/bash
# ~/.claude/hooks/session-start.sh
if [ -n "$CLAUDE_ENV_FILE" ]; then
  echo "export NODE_ENV=development" >> "$CLAUDE_ENV_FILE"
  echo "export PROJECT_ROOT=$(pwd)" >> "$CLAUDE_ENV_FILE"
fi

Point your hook at the script:

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/hooks/session-start.sh"
          }
        ]
      }
    ]
  }
}

The hook runs synchronously before Claude's first turn, so any variables or side effects are in place before Claude does anything.

Use SessionStart to make every session feel pre-configured rather than starting from scratch.


via Claude Code Hooks Reference

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Scan Pending Changes for Security Issues with /security-review

The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.

bagwaa @bagwaa · 1 hour ago
0
Write Property-Based Tests with fast-check and Claude

Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.

bagwaa @bagwaa · 2 hours ago
0
Generate a Typed API Client SDK from Your OpenAPI Spec with Claude

Give Claude your OpenAPI spec and ask for a handcrafted typed API client — clean method names, custom error handling, and TanStack Query hooks, without the ugly auto-gen output.

bagwaa @bagwaa · 2 hours ago