list_projects
View all Claude Code projects and their session counts to track development activity and manage workflows.
Instructions
List all Claude Code projects with session counts
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- Core handler function that lists all projects in ~/.claude/projects, counts sessions per project, formats display names, and returns sorted list.def get_projects() -> list[dict]: """Get all projects.""" base_path = get_base_path() projects = [] if not base_path.exists(): return projects for project_dir in base_path.iterdir(): if project_dir.is_dir() and not project_dir.name.startswith('.'): # Count sessions session_count = len(list(project_dir.glob("*.jsonl"))) projects.append({ "name": project_dir.name, "display_name": format_project_name(project_dir.name), "session_count": session_count }) return sorted(projects, key=lambda p: p["name"])
- src/claude_session_manager_mcp/server.py:535-543 (registration)Registers the 'list_projects' tool in the MCP list_tools() function, including its description and input schema (no parameters required).Tool( name="list_projects", description="List all Claude Code projects with session counts", inputSchema={ "type": "object", "properties": {}, "required": [] } ),
- Dispatches tool calls to the get_projects() handler within the main @mcp.call_tool() function.if name == "list_projects": result = get_projects()
- Helper function returning the base directory path for Claude projects.def get_base_path() -> Path: """Get base path for Claude projects.""" return Path(os.path.expanduser("~/.claude/projects"))
- Helper function to format raw project directory names into user-friendly display names.def format_project_name(name: str) -> str: """Format project name for display.""" if name.startswith('-'): name = name[1:] name = name.replace('--', '/.') parts = name.split('-') if len(parts) > 1: last = parts[-1] if last in ('com', 'org', 'net', 'io', 'dev', 'md', 'txt', 'py', 'js', 'ts'): parts[-2] = parts[-2] + '.' + last parts = parts[:-1] name = '/' + '/'.join(parts) if name.startswith('/Users/young'): name = '~' + name[len('/Users/young'):] return name