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

Run Setup Scripts on Every Session with the SessionStart Hook

recombobulate @recombobulate · Mar 26, 2026 · Configuration
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
Describe Your Users in CLAUDE.md So Claude Writes Appropriate Copy, Error Messages, and UX

When Claude writes error messages, button labels, validation text, or onboarding flows, it defaults to generic developer-speak. Add a "Users" section to your CLAUDE.md describing who your actual users are — their technical level, industry jargon, and what they care about — so Claude writes copy that makes sense to THEM, not to developers.

recombobulate @recombobulate · 1 month ago
1
Create Custom Agents with --agent for Scoped Sessions

Use the --agent flag with custom markdown files in .claude/agents/ to launch purpose-built Claude sessions with restricted tools and scoped system prompts.

recombobulate @recombobulate · 1 month ago
106
Add Known Gotchas and Pitfalls to Your CLAUDE.md So Claude Avoids Mistakes Your Team Already Made

Every project has traps — the billing module that silently fails if you forget to queue the job, the legacy table with column names that don't match the model, the config value that must be set before tests run. Document these gotchas in your CLAUDE.md so Claude avoids the same mistakes your team spent days debugging.

recombobulate @recombobulate · 1 month ago