Session Context Loader Hook
Automatically loads previous session context when starting a new Claude Code session. Reads saved state from a context file to maintain continuity across conversations. Remembers current tasks, branch, decisions, and blockers.
Hook Type
SessionStart -- Fires when a new Claude Code session begins.
Description
This hook loads a saved context file at the start of every session, giving Claude immediate awareness of where you left off. It reads from .claude/session-context.md which contains your current task, branch, recent decisions, and any blockers. Combined with the Session Summary Saver hook, this creates persistent memory across sessions.
Patterns/Rules
- Triggers on every new session start
- Reads from
.claude/session-context.mdin the project root - If the file doesn't exist, outputs a brief "no previous context" message
- The context file should be kept concise (under 50 lines) to avoid wasting tokens
- Works best paired with the Session Summary Saver hook
Configuration
{ "hooks": { "SessionStart": [ { "matcher": "", "hooks": [ { "type": "command", "command": "if [ -f .claude/session-context.md ]; then echo '--- PREVIOUS SESSION CONTEXT ---'; cat .claude/session-context.md; echo '--- END CONTEXT ---'; else echo 'No previous session context found. Starting fresh.'; fi" } ] } ] } }
Enhanced Version (with staleness check)
{ "hooks": { "SessionStart": [ { "matcher": "", "hooks": [ { "type": "command", "command": "bash -c 'FILE=.claude/session-context.md; if [ -f \"$FILE\" ]; then AGE=$(( ($(date +%s) - $(stat -f%m \"$FILE\" 2>/dev/null || stat -c%Y \"$FILE\" 2>/dev/null)) / 3600 )); echo \"--- PREVIOUS SESSION CONTEXT (${AGE}h ago) ---\"; cat \"$FILE\"; echo \"--- END CONTEXT ---\"; if [ $AGE -gt 48 ]; then echo \"WARNING: Context is over 48 hours old. Verify it is still relevant.\"; fi; else echo \"No previous session context. Starting fresh.\"; fi'" } ] } ] } }
Example Context File (.claude/session-context.md)
# Session Context - Updated 2025-03-25 ## Current Task Refactoring auth middleware to support session-based auth (replacing JWT) ## Branch feat/session-auth (branched from develop) ## Progress - [x] Created session store with Redis backend - [x] Updated login endpoint to create sessions - [ ] Migrate /api/user routes to use session middleware - [ ] Update frontend to handle session cookies ## Key Decisions - Using Redis for session store (not database) - Session TTL: 24 hours, sliding window - Keeping JWT for API-to-API auth (internal services only) ## Blockers - Need to test CORS cookie behavior with the React frontend
Action
At session start:
- Checks if
.claude/session-context.mdexists - If found: reads and outputs the content with age indicator
- If stale (>48h): adds a warning
- If not found: outputs a brief "starting fresh" message
- Claude receives this context as part of the session initialization
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Pre-Commit Security Scanner
Pre-commit hook that scans staged files for hardcoded secrets, API keys, passwords, and sensitive data patterns before allowing commits.
Agents Md Watcher
Streamline your workflow with this automatically, loads, agents, configuration. Includes structured workflows, validation checks, and reusable patterns for automation.
Automated Build Inspector
Boost productivity using this automatically, trigger, build, processes. Includes structured workflows, validation checks, and reusable patterns for automation.