Skip to main content
Glama

should_reset_context

Determines when to reset Claude's conversation context by analyzing context usage, task completion, git status, and session duration to maintain effective AI assistance.

Instructions

Get intelligent recommendation on whether to reset context. Analyzes context usage, todo completion, git state, and session duration.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
working_directoryNoWorking directory for git operations. Defaults to current directory.

Implementation Reference

  • The handler logic for 'should_reset_context' which analyzes context budget, todos, and git status to recommend a reset.
    async def _should_reset_context(arguments: dict[str, Any]) -> dict:
        """Get intelligent reset recommendation."""
        working_dir = arguments.get("working_directory") or _get_working_directory()
    
        # Get context budget
        transcript_parser = TranscriptParser()
        budget = transcript_parser.get_context_budget()
        session_start = transcript_parser.get_session_start_time()
    
        # Get todos
        session_id = None
        if transcript_parser.transcript_path:
            todo_parser = TodoParser()
            session_id = todo_parser.extract_session_id_from_transcript_path(
                transcript_parser.transcript_path
            )
    
        todos = TodoParser().get_latest_todos()
        if session_id:
            todos = TodoParser().get_todos_for_session(session_id)
    
        # Get git state
        git = GitUtils(working_dir)
        git_state = git.get_state()
    
        # Calculate session duration
        duration_minutes = None
        if session_start:
            delta = datetime.now(session_start.tzinfo) - session_start
            duration_minutes = int(delta.total_seconds() / 60)
    
        # Build reasoning
        reasoning = []
        blockers = []
    
        # Context usage analysis
        if budget.status == "critical":
            reasoning.append(f"Context {budget.percentage_used}% full (critical threshold)")
        elif budget.status == "low":
            reasoning.append(f"Context {budget.percentage_used}% full (low threshold)")
        else:
            reasoning.append(f"Context {budget.percentage_used}% full (sufficient)")
    
        # Todo analysis
        all_done = len(todos.in_progress) == 0 and len(todos.pending) == 0
        if all_done and todos.total_count > 0:
            reasoning.append("All todos completed")
        elif len(todos.in_progress) > 0:
            reasoning.append(f"{len(todos.in_progress)} todos still in progress")
        if len(todos.pending) > 0:
            reasoning.append(f"{len(todos.pending)} todos pending")
    
        # Git state analysis
        if git_state.has_uncommitted_changes:
            blockers.append(f"{git_state.uncommitted_file_count} uncommitted files")
            reasoning.append(f"Uncommitted changes: {git_state.uncommitted_file_count} files")
        else:
            reasoning.append("Clean git state (no uncommitted changes)")
    
        # Duration analysis
        if duration_minutes:
            hours = duration_minutes // 60
            mins = duration_minutes % 60
            reasoning.append(f"Session duration: {hours}h {mins}m")
    
        # Decision logic
        safe_to_reset = not git_state.has_uncommitted_changes
        should_reset = False
        confidence = "low"
    
        if budget.status == "critical" and safe_to_reset:
            should_reset = True
            confidence = "high"
        elif budget.status == "low" and all_done and safe_to_reset:
            should_reset = True
            confidence = "high"
        elif budget.status == "low" and safe_to_reset:
            should_reset = True
            confidence = "medium"
        elif all_done and safe_to_reset and duration_minutes and duration_minutes > 60:
            should_reset = True
            confidence = "medium"
    
        # Generate suggested summary
        completed = [t.content for t in todos.completed]
        if completed:
            summary_items = completed[:3]
            if len(completed) > 3:
                summary_items.append(f"...and {len(completed) - 3} more")
            suggested_summary = "Completed: " + ", ".join(summary_items)
        else:
            suggested_summary = "Session work in progress"
    
        return {
            "should_reset": should_reset,
            "confidence": confidence,
            "reasoning": reasoning,
            "safe_to_reset": safe_to_reset,
            "blockers": blockers,
            "suggested_summary": suggested_summary,
        }
  • Registration and invocation point of 'should_reset_context' within the MCP server's request handling loop.
    elif name == "should_reset_context":
        result = await _should_reset_context(arguments)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TimEvans/ccsession'

If you have feedback or need assistance with the MCP directory API, please join our Discord server