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

Approval Boundary Tool for Claude Code Repository Work
A developer built an approval boundary tool that adds a review step before local execution when using Claude Code for repository work. The tool follows a loop: see the plan first, approve once, let the run happen locally, and keep proof afterward.

Three MCP servers for e-commerce research with Claude: Shopify, Amazon, and Google Maps tools
A developer built three MCP servers for Claude to analyze Shopify stores without API keys, score Amazon product opportunities, and find/scored local business leads from Google Maps. All are available on Apify.

Introducing Roam-Code CLI: A Faster, Deterministic Alternative for Code Exploration
Roam-Code CLI replaces Claude Code's explore phase with a faster, deterministic alternative that indexes codebases for improved efficiency.

NaNMesh MCP checks GitHub issues before Claude recommends libraries
NaNMesh MCP is an open-source Model Context Protocol server that crawls GitHub Issues, Stack Overflow, and Reddit for known bugs in development tools. When Claude recommends a library, it can check for real problems before integration.