Automated Session State Management for Claude Code Handoff

Automated Context Preservation for Claude Sessions
A Reddit user has shared a solution for managing context degradation in Claude conversations, particularly addressing issues with autocompact and mid-conversation context loss as conversation windows grow large. The system automatically maintains a live state file throughout sessions without manual intervention.
How It Works
The solution expands on manual handoff commands by incorporating additional hooks:
- A
UserPromptSubmithook fires on every message sent, injecting a directive into Claude's system context that says "check if anything important happened, and if so, update session-state.md" - A
PostToolUsehook tracks which files Claude edits - When
session-state.mdgets too long, the directive automatically switches to "rewrite mode" telling Claude to keep only critical information - Before autocompaction, a
PreCompacthook forces a full state dump so nothing is lost - On session start, the previous session's state is loaded back in
Implementation Details
The automated system consists of approximately 4 shell scripts with no dependencies beyond bash and jq. Installation options include:
- Install as a git submodule
- Copy the hooks into
.claude/hooks/directory
The system maintains a live state file at .claude/session-state.md throughout the session. It also includes a manual /handoff command for deliberate checkpoints, useful for task tracking, bug investigations, and recovery from degraded context.
This type of tool is useful for developers working on complex, multi-session projects with Claude where maintaining context across conversations is critical for continuity and avoiding repetition.
📖 Read the full source: r/ClaudeAI
👀 See Also

Legal MCP Server for Claude Provides Access to 4M+ US Court Opinions
A free, open-source MCP server built with Claude Code gives Claude AI access to 4M+ real US court opinions, providing 18 tools for case law search, citation tracing, Bluebook parsing, Clio practice management, and PACER federal filings without hallucinations.

Session Inspector for Claude Code provides real-time visibility into AI agent operations
Vibeyard, an open-source terminal IDE that wraps Claude Code, has added a Session Inspector feature that provides real-time visibility into Claude Code sessions with timeline tracking, cost breakdowns, tool analytics, and context window monitoring.

Claude-Code v2.1.76 adds MCP elicitation, worktree optimizations, and numerous fixes
Claude-Code v2.1.76 introduces MCP elicitation support for structured input mid-task, adds worktree.sparsePaths for monorepo efficiency, and fixes 20+ issues including deferred tool schema loss, slash command problems, and Remote Control session stability.

context-os: Open-source tool reduces Claude Code token consumption by 27-42%
context-os is a local context optimizer that hooks into Claude Code automatically, compressing tool output before Claude sees it and reducing token consumption by 27-42% depending on content type.