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.
Log in to leave a comment.
The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.
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.
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.