todo_write
Create and manage structured task lists for coding sessions to organize multi-step tasks, track progress, and ensure thoroughness in completing complex projects.
Instructions
Use this tool to create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user. It also helps the user understand the progress of the task and overall progress of their requests.
When to Use This Tool
Use this tool proactively in these scenarios:
Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
User explicitly requests todo list - When the user directly asks you to use the todo list
User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
After receiving new instructions - Immediately capture user requirements as todos. Feel free to edit the todo list based on new information.
After completing a task - Mark it complete and add any new follow-up tasks
When you start working on a new task, mark the todo as in_progress. Ideally you should only have one todo as in_progress at a time. Complete existing tasks before starting new ones.
When NOT to Use This Tool
Skip using this tool when:
There is only a single, straightforward task
The task is trivial and tracking it provides no organizational benefit
The task can be completed in less than 3 trivial steps
The task is purely conversational or informational
NOTE that you should use should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.
Examples of When to Use the Todo List
Examples of When NOT to Use the Todo List
python print("Hello World")
This will output the text "Hello World" to the console when executed.
Executes: npm install
The command completed successfully. Here's the output: [Output of npm install command]
All dependencies have been installed according to your package.json file.
Task States and Management
Task States: Use these states to track progress:
pending: Task not yet started
in_progress: Currently working on (limit to ONE task at a time)
completed: Task finished successfully
cancelled: Task no longer needed
Task Management:
Update task status in real-time as you work
Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
Only have ONE task in_progress at any time
Complete current tasks before starting new ones
Cancel tasks that become irrelevant
Task Breakdown:
Create specific, actionable items
Break complex tasks into smaller, manageable steps
Use clear, descriptive task names
When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes | Unique identifier for the Claude Desktop session (generate using timestamp command) | |
| todos | Yes | The complete todo list to store for this session |
Implementation Reference
- The MCP tool handler function for 'todo_write', registered dynamically via the tool's register method. This is the entrypoint called by the MCP framework.@mcp_server.tool(name=self.name, description=self.description) async def todo_write( ctx: MCPContext, session_id: SessionId, todos: Todos, ) -> str: ctx = get_context() return await tool_self.call(ctx, session_id=session_id, todos=todos)
- Core execution logic of the TodoWriteTool, performing parameter extraction, validation, todo normalization, storage in TodoStorage, and generating a status summary.async def call( self, ctx: MCPContext, **params: Unpack[TodoWriteToolParams], ) -> str: """Execute the tool with the given parameters. Args: ctx: MCP context **params: Tool parameters Returns: Tool result """ tool_ctx = self.create_tool_context(ctx) self.set_tool_context_info(tool_ctx) # Extract parameters session_id = params.get("session_id") todos = params.get("todos") # Validate required parameters for direct calls (not through MCP framework) if session_id is None: await tool_ctx.error("Parameter 'session_id' is required but was None") return "Error: Parameter 'session_id' is required but was None" if todos is None: await tool_ctx.error("Parameter 'todos' is required but was None") return "Error: Parameter 'todos' is required but was None" session_id = str(session_id) # Validate session ID is_valid, error_msg = self.validate_session_id(session_id) if not is_valid: await tool_ctx.error(f"Invalid session_id: {error_msg}") return f"Error: Invalid session_id: {error_msg}" # Normalize todos list (auto-generate missing fields) todos = self.normalize_todos_list(todos) # Validate todos list is_valid, error_msg = self.validate_todos_list(todos) if not is_valid: await tool_ctx.error(f"Invalid todos: {error_msg}") return f"Error: Invalid todos: {error_msg}" await tool_ctx.info(f"Writing {len(todos)} todos for session: {session_id}") try: # Store todos in memory TodoStorage.set_todos(session_id, todos) # Log storage stats session_count = TodoStorage.get_session_count() await tool_ctx.info( f"Successfully stored todos. Total active sessions: {session_count}" ) # Provide feedback about the todos if todos: status_counts = {} priority_counts = {} for todo in todos: status = todo.get("status", "unknown") priority = todo.get("priority", "unknown") status_counts[status] = status_counts.get(status, 0) + 1 priority_counts[priority] = priority_counts.get(priority, 0) + 1 # Create summary summary_parts = [] if status_counts: status_summary = ", ".join( [f"{count} {status}" for status, count in status_counts.items()] ) summary_parts.append(f"Status: {status_summary}") if priority_counts: priority_summary = ", ".join( [ f"{count} {priority}" for priority, count in priority_counts.items() ] ) summary_parts.append(f"Priority: {priority_summary}") summary = ( f"Successfully stored {len(todos)} todos for session {session_id}.\n" + "; ".join(summary_parts) ) return summary else: return f"Successfully cleared todos for session {session_id} (stored empty list)." except Exception as e: await tool_ctx.error(f"Error storing todos: {str(e)}") return f"Error storing todos: {str(e)}"
- Pydantic-style schema definitions using TypedDict and Annotated for input parameters: session_id and todos list of TodoItems with content, status, priority, id.class TodoItem(TypedDict): """A single todo item.""" content: Annotated[ str, Field( description="Description of the task to be completed", min_length=1, ), ] status: Annotated[ Literal["pending", "in_progress", "completed"], Field(description="Current status of the task"), ] priority: Annotated[ Literal["high", "medium", "low"], Field(description="Priority level of the task"), ] id: Annotated[ str, Field(description="Unique identifier for the task", min_length=3), ] SessionId = Annotated[ str | int | float, Field( description="Unique identifier for the Claude Desktop session (generate using timestamp command)", ), ] Todos = Annotated[ list[TodoItem], Field( description="The complete todo list to store for this session", min_length=1, ), ] class TodoWriteToolParams(TypedDict): """Parameters for the TodoWriteTool. Attributes: session_id: Unique identifier for the Claude Desktop session (generate using timestamp command) todos: The complete todo list to store for this session """ session_id: SessionId todos: Todos
- mcp_claude_code/tools/todo/__init__.py:22-45 (registration)Registers the TodoWriteTool instance by creating it in get_todo_tools() and passing to ToolRegistry.register_tools which calls tool.register(mcp_server).def get_todo_tools() -> list[BaseTool]: """Create instances of all todo tools. Returns: List of todo tool instances """ return [ TodoReadTool(), TodoWriteTool(), ] def register_todo_tools(mcp_server: FastMCP) -> list[BaseTool]: """Register all todo tools with the MCP server. Args: mcp_server: The FastMCP server instance Returns: List of registered tools """ tools = get_todo_tools() ToolRegistry.register_tools(mcp_server, tools) return tools
- In-memory storage class used by todo_write to persist todo lists per session_id.class TodoStorage: """In-memory storage for todo lists, separated by session ID. This class provides persistent storage for the lifetime of the MCP server process, allowing different Claude Desktop conversations to maintain separate todo lists. Each session stores both the todo list and a timestamp of when it was last updated. """ # Class-level storage shared across all tool instances # Structure: {session_id: {"todos": [...], "last_updated": timestamp}} _sessions: dict[str, dict[str, Any]] = {} @classmethod def get_todos(cls, session_id: str) -> list[dict[str, Any]]: """Get the todo list for a specific session. Args: session_id: Unique identifier for the Claude Desktop session Returns: List of todo items for the session, empty list if session doesn't exist """ session_data = cls._sessions.get(session_id, {}) return session_data.get("todos", []) @classmethod def set_todos(cls, session_id: str, todos: list[dict[str, Any]]) -> None: """Set the todo list for a specific session. Args: session_id: Unique identifier for the Claude Desktop session todos: Complete list of todo items to store """ cls._sessions[session_id] = {"todos": todos, "last_updated": time.time()} @classmethod def get_session_count(cls) -> int: """Get the number of active sessions. Returns: Number of sessions with stored todos """ return len(cls._sessions) @classmethod def get_all_session_ids(cls) -> list[str]: """Get all active session IDs. Returns: List of all session IDs with stored todos """ return list(cls._sessions.keys()) @classmethod def delete_session(cls, session_id: str) -> bool: """Delete a session and its todos. Args: session_id: Session ID to delete Returns: True if session was deleted, False if it didn't exist """ if session_id in cls._sessions: del cls._sessions[session_id] return True return False @classmethod def get_session_last_updated(cls, session_id: str) -> float | None: """Get the last updated timestamp for a session. Args: session_id: Session ID to check Returns: Timestamp when session was last updated, or None if session doesn't exist """ session_data = cls._sessions.get(session_id) if session_data: return session_data.get("last_updated") return None @classmethod def find_latest_active_session(cls) -> str | None: """Find the chronologically latest session with unfinished todos. Returns the session ID of the most recently updated session that has unfinished todos. Returns None if no sessions have unfinished todos. Returns: Session ID with unfinished todos that was most recently updated, or None if none found """ from mcp_claude_code.prompts.project_todo_reminder import has_unfinished_todos latest_session = None latest_timestamp = 0 for session_id, session_data in cls._sessions.items(): todos = session_data.get("todos", []) if has_unfinished_todos(todos): last_updated = session_data.get("last_updated", 0) if last_updated > latest_timestamp: latest_timestamp = last_updated latest_session = session_id return latest_session
- mcp_claude_code/tools/__init__.py:83-85 (registration)Top-level registration call within register_all_tools that invokes the todo tools registration.todo_tools = register_todo_tools(mcp_server) for tool in todo_tools: all_tools[tool.name] = tool