S

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.

HookCommunityautomationv1.0.0MIT
0 views0 copies

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.md in 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:

  1. Checks if .claude/session-context.md exists
  2. If found: reads and outputs the content with age indicator
  3. If stale (>48h): adds a warning
  4. If not found: outputs a brief "starting fresh" message
  5. Claude receives this context as part of the session initialization
Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates