get_active_project
Determine your current project by analyzing working directory, active window title, and recent activity. Returns project ID, detection method, and confidence score. Ideal for session initialization or answering 'where am I'.
Instructions
Detect the user's current project from working directory, active window, and recent activity.
Returns project ID, detection method (cwd / window-title / activity-blend), and confidence.
USE WHEN: starting a session and you need to load the right project's context, or when the user says "where am I" / "what am I working on." NOT FOR: classifying arbitrary text — use identify_project.
BEHAVIOR: pure read; combines multiple signals. Returns "unknown" if nothing matches above the confidence floor.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The actual MCP tool handler for get_active_project. Accepts cwd and window_title parameters, delegates detection to ActiveProjectDetector, and returns JSON with project name, overview, and source.
@mcp_app.tool() def get_active_project(cwd: str = "", window_title: str = "") -> str: """Detect which project is currently in focus based on CWD and/or window title. If both are empty, returns null. Pass the current working directory to get instant project detection for any Claude Code session. """ project = _detector.detect( cwd=cwd or None, window_title=window_title or None, ) if project: info = _registry.get(project) return json.dumps({ "project": project, "overview": info.overview[:200] if info else "", "source": "cwd" if cwd else "window_title", }) return json.dumps({"project": None, "reason": "Could not detect active project"}) - The @mcp_app.tool() decorator registers get_active_project as an MCP tool.
@mcp_app.tool() def get_active_project(cwd: str = "", window_title: str = "") -> str: - ActiveProjectDetector class — implements the detection logic. Checks if the current working directory is under a project root, and then checks window title for project name or alias matches.
class ActiveProjectDetector: def __init__(self, registry: ProjectRegistry, projects_root: Path | None = None): self.registry = registry self.projects_root = projects_root or Path.home() / "Projects" def detect( self, cwd: str | None = None, window_title: str | None = None, app_name: str | None = None, ) -> str | None: # 1. CWD-based detection if cwd: cwd_path = Path(cwd).resolve() try: rel = cwd_path.relative_to(self.projects_root.resolve()) project_name = rel.parts[0] if rel.parts else None if project_name and self.registry.get(project_name): return project_name except ValueError: pass # 2. Window title contains project directory name if window_title: title_lower = window_title.lower() for project in self.registry.list_all(): if project.name.lower() in title_lower: return project.name for alias in project.aliases: if alias.lower() in title_lower: return project.name return None - The tool's parameters are defined in the function signature: cwd (str, default '') and window_title (str, default ''). The return type is str (JSON-serialized).
@mcp_app.tool() def get_active_project(cwd: str = "", window_title: str = "") -> str: """Detect which project is currently in focus based on CWD and/or window title. If both are empty, returns null. Pass the current working directory to get instant project detection for any Claude Code session. """ project = _detector.detect( cwd=cwd or None, window_title=window_title or None, ) if project: info = _registry.get(project) return json.dumps({ "project": project, "overview": info.overview[:200] if info else "", "source": "cwd" if cwd else "window_title", }) return json.dumps({"project": None, "reason": "Could not detect active project"}) - scripts/canary_health_check.py:239-239 (registration)Health check script that imports and tests the get_active_project tool as part of integration testing.
("project", "get_active_project", project.get_active_project, {"cwd": "", "window_title": ""}),