Retrieves information from local Git repositories, such as branch status, uncommitted changes, and commit history, to inform session state and management.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Claude Session MCPcheck context budget and tell me if I should reset"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Claude Session MCP
An MCP (Model Context Protocol) server that provides Claude Code with programmatic session awareness - the ability to query context usage, read todos, track session history, sync planning docs, and make intelligent reset recommendations.
Why This Exists
Claude Code agents, slash commands, and hooks need to make smart decisions about session management:
Before spawning a sub-agent: Check if there's enough context budget remaining
Before expensive operations: Verify we're not at 90% context and about to trigger compaction
When resuming work: Know what todos are already in progress to avoid duplication
During long sessions: Programmatically update
.context/dev/{branch}/planning docsEnd of task: Get intelligent recommendations on whether to reset context
This MCP server makes all of that possible by exposing session state through 5 core tools.
Features
5 Session Awareness Tools
Tool | Purpose | Use Cases |
| Query context window usage and remaining capacity | Gate operations when context is critical, warn before spawning agents |
| Unified snapshot of todos, git state, context files, session info | Check existing todos before creating new ones, verify branch state |
| What's been accomplished (files modified, todos completed, commits) | Auto-generate session summaries, resume after context reset |
| Programmatically update | Log decisions as you work, mark tasks complete in real-time |
| Intelligent recommendations for when to reset context | End-of-task automation, proactive warnings |
Installation
Prerequisites
Python 3.11+ (tested on 3.13)
uv package manager
Claude Code CLI
Install Steps
Configuration
Option 1: Global Configuration
Add to ~/.claude/mcp.json:
Option 2: Project-Level Configuration
Add to <your-project>/.claude/mcp.json:
Verify Installation
After restarting Claude Code, the tools will be available to agents and slash commands. You can verify by asking:
"Can you check the context budget using the MCP tools?"
Tool Reference
1. check_context_budget
Query current context window usage and remaining capacity.
Parameters:
context_limit(optional): Maximum context tokens. Default: 156,000 (200K × 0.78 threshold)
Returns:
Status Values:
sufficient: < 60% usedlow: 60-80% usedcritical: > 80% used
Example Usage in Slash Command:
2. get_session_state
Get a unified snapshot of current session state.
Parameters:
working_directory(optional): Working directory for git operations. Defaults to current directory.
Returns:
Example Usage in Agent:
3. get_session_history
Get what has been accomplished this session.
Parameters:
working_directory(optional): Working directory for git operations. Defaults to current directory.
Returns:
Example Usage in
4. sync_planning_doc
Programmatically update .context/dev/{branch}/ planning documents.
Parameters:
mode(required): One of:append_progress_log: Add timestamped entry to Progress Logupdate_active_work: Replace Active Work sectionmark_tasks_complete: Mark tasks as[x]in Implementation Plan
completed_tasks(array): Tasks completed (forappend_progress_logormark_tasks_complete)in_progress(string): Current work description (forupdate_active_work)decisions(array): Key decisions made (forappend_progress_log)blockers(array): Current blockers (forupdate_active_workorappend_progress_log)next_steps(array): Next immediate steps (forupdate_active_work)working_directory(optional): Working directory. Defaults to current directory.
Returns:
Example 1: Append Progress Log
Example 2: Update Active Work
Example 3: Mark Tasks Complete
This will change:
To:
5. should_reset_context
Get intelligent recommendation on whether to reset context.
Parameters:
working_directory(optional): Working directory. Defaults to current directory.
Returns:
Decision Logic:
Condition | Recommendation |
Context >80% + clean git + todos done |
|
Context 60-80% + todos done + clean git |
|
Context 60-80% + clean git |
|
Context >60% + uncommitted changes |
|
Session >60min + todos done + clean git |
|
Example Usage in Hook:
Use Cases
Use Case 1: Smart Agent Spawning
Problem: Agent spawns a sub-agent, but context is at 85%, causing immediate compaction and lost context.
Solution:
Use Case 2: Avoid Duplicate Todos
Problem: After context reset, agent creates duplicate todos for work already in progress.
Solution:
Use Case 3: Real-Time Planning Doc Updates
Problem: Planning docs in .context/dev/{branch}/ only get updated at end of session, losing valuable decision history.
Solution:
Use Case 4: Automated Session Summaries
Problem: Manually writing session summaries before context reset is tedious and error-prone.
Solution:
Architecture
How It Works
Transcript Discovery: Scans
/tmp/claude-code-transcripts/for the most recent.jsonlfileToken Counting: Parses transcript to sum
input_tokens + output_tokens + cache_creation_input_tokens + cache_read_input_tokensTodo Parsing: Reads
~/.claude/todos/{session_id}*.jsonfiles (handles agent spawns)Git Operations: Subprocess calls to
gitCLI for branch, status, commitsPlanning Doc Updates: Markdown section parsing with regex, preserves formatting
File Locations
Context Limit Calculation
Claude Code triggers /compact at ~78% of the 200K context window:
Thresholds:
Sufficient: < 60% of limit (< 93,600 tokens)
Low: 60-80% of limit (93,600 - 124,800 tokens)
Critical: > 80% of limit (> 124,800 tokens)
Development
Running Tests
Test Coverage
47 passing tests covering:
Transcript parsing (token counting, session start time, edge cases)
Git utilities (state detection, commits, planning doc paths)
Todo parsing (session todos, agent spawns, latest todos)
All 5 MCP tools (integration tests with mocked dependencies)
Project Structure
Adding New Features
New parser: Add to
src/ccsession/parsers/New tool: Add handler in
server.pyunderhandle_tool_call()Add tests: Create
tests/test_*.pywith fixturesUpdate docs: Document in this README
Troubleshooting
MCP server not found
Error: MCP server 'claude-session' not found
Solution:
Check
~/.claude/mcp.jsonor<project>/.claude/mcp.jsonexistsVerify
cwdpath points to correct directoryRestart Claude Code to reload MCP config
No transcript found
Error: Tools return empty/zero values
Solution:
Verify
/tmp/claude-code-transcripts/directory existsCheck that
.jsonlfiles are being created during sessionsMCP uses most recent file by modification time
Planning doc not found
Error: sync_planning_doc returns "Plan file not found"
Solution:
Verify
.context/dev/{branch}/{branch}-detailed-plan.mdexistsCheck you're on the correct git branch
Planning doc path follows pattern: branch name with dashes, not slashes
Tests failing
Error: Import errors or test failures
Solution:
Acknowledgments
Transcript parsing logic ported from ccusage by @ryoppippi
Built with the MCP Python SDK
Designed for Claude Code
License
MIT License - see LICENSE file for details
Contributing
Contributions welcome! Please:
Fork the repository
Create a feature branch (
git checkout -b feat/amazing-feature)Add tests for new functionality
Ensure all tests pass (
uv run pytest)Submit a pull request
Future Enhancements
Potential Wave 2+ features (see PLAN.md for full list):
Session comparison: Diff two sessions to see what changed
Cost tracking: Token usage → USD cost estimates
Time tracking: How long was spent on each task
Planning doc templates: Auto-generate planning docs from templates
Multi-session search: Find when/where specific work was done
Session replay: Reconstruct what happened in a previous session
See something missing? Open an issue!