Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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"})
  • 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": ""}),
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Discloses pure read behavior, signal combination, and fallback to 'unknown' when confidence is low. With no annotations, the description fully covers behavioral expectations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Concise, well-structured description with purposeful sections (what, returns, when to use, when not, behavior). Every sentence contributes value without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given zero parameters and presence of output schema, the description fully covers all necessary context: detection methods, confidence, and unknown case. No gaps remain.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

No parameters exist, and schema coverage is 100% trivially. Baseline score of 4 applies as description adds no parameter details but none are needed.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool detects the user's current project from working directory, active window, and recent activity, specifying the return values (project ID, detection method, confidence) and distinguishing it from the sibling 'identify_project'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly states when to use ('starting a session', user asking 'where am I') and when not to use ('classifying arbitrary text' with sibling alternative 'identify_project'), providing clear context for agent decision.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/ContextPulse/contextpulse'

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