How OfficeCLI Auto-Detects AI Agents Like Claude Code for Skill Installation

OfficeCLI uses a two-stage detection process that first scans filesystem configuration directories to confirm an agent is present, then validates runtime capabilities by executing the agent's CLI to verify MCP protocol support before registering the officecli skill.

The OfficeCLI tool from the iOfficeAI/OfficeCLI repository includes an intelligent skill auto-install feature that eliminates manual configuration by automatically discovering AI coding assistants on your system. When you run installation commands, the tool detects whether agents like Claude Code are present and registers the officecli skill through the Multi-Client Protocol (MCP) without user intervention. This detection mechanism combines filesystem scanning with runtime CLI verification to ensure reliable installation across macOS, Linux, and Windows environments.

Understanding the Detection Architecture

The auto-install system is architected across two core components that work sequentially to identify and configure AI agents. The SkillInstaller class maintains a static registry of supported agents and their expected configuration paths, while the McpInstaller implements agent-specific logic for testing CLI availability and manipulating MCP configurations. This separation allows OfficeCLI to support multiple agents—including Claude Code, Cursor, GitHub Copilot, and LM Studio—through a consistent detection interface.

Stage 1: Filesystem-Based Presence Detection

The Agent Mapping Table

At the heart of the detection system is a lookup table defined in src/officecli/Core/SkillInstaller.cs at line 26. This static array maps agent identifiers to their expected configuration directories and binary names, enabling OfficeCLI to quickly determine if an agent is installed by checking for the presence of specific folders on the filesystem.

For Claude Code, the mapping specifies the .claude directory in the user's home folder (~/.claude). The installer checks for this directory's existence alongside verifying that the claude binary is reachable in the system PATH. If both conditions are met, the agent is flagged as installed and ready for skill registration.

// Inside SkillInstaller.cs – maps identifiers to detection data
private static readonly (string[] args, string name, string configDir, string skillDir)[] Agents = {
    (new[] {"claude", "claude-code"}, "Claude Code", ".claude",
     Path.Combine(".claude", "skills")),
    // … other agents …
};

Stage 2: Runtime Capability Verification

Testing the Claude CLI

After confirming the configuration directory exists, OfficeCLI validates that the agent is functional and accessible via its command-line interface. In src/officecli/McpInstaller.cs at line 220, the TryClaudeCli method attempts to execute the claude command with MCP-specific arguments.

This runtime test serves a critical dual purpose: it confirms the CLI binary is properly installed and executable, and it verifies that the Claude Code installation supports MCP operations required for skill registration. The method wraps a call to TryCli with the specific binary name "claude".

// Inside McpInstaller.cs – tries the Claude CLI
private static bool TryClaudeCli(string[] args, out string stdout,
                                 out string stderr, out int exitCode)
{
    return TryCli("claude", args, out stdout, out stderr, out exitCode);
}

The Installation Workflow

Registering the MCP Server

Once detection succeeds, the installation logic in src/officecli/McpInstaller.cs (lines 177-191) performs an atomic update of the agent's MCP configuration. The process follows a defensive pattern: first removing any stale officecli entries to prevent configuration conflicts, then adding a fresh MCP server entry that points to the OfficeCLI binary path (OfficecliPath).

The installer invokes TryClaudeCli with the mcp remove command to clean existing entries (as shown in lines 203-211), followed immediately by mcp add to register the new skill. This registration allows Claude Code to invoke OfficeCLI capabilities on behalf of the user through the MCP protocol.

// Installation logic for Claude Code
if (!TryClaudeCli(new[] {"mcp", "remove", "-s", "user", "officecli"},
                  out _, out _, out _))
{
    InstallJson("Claude Code", GetClaudeConfigPath(), "mcpServers");
}
if (TryClaudeCli(new[] {"mcp", "add", "-s", "user", "officecli",
                        "--", OfficecliPath, "mcp"},
                 out _, out _, out _))
{
    Console.WriteLine("Registered officecli MCP in Claude Code.");
}

Extending Detection to Other Agents

While this analysis focuses on Claude Code, the same two-stage pattern applies to other supported assistants including Cursor, GitHub Copilot, and LM Studio. The modular architecture in SkillInstaller.cs allows new agents to be added by extending the agent mapping table with their respective configuration directories and CLI command names. Each agent implementation in McpInstaller.cs provides specialized methods like TryClaudeCli that handle agent-specific CLI syntax while reusing the core detection infrastructure.

Summary

  • OfficeCLI detects AI agents through a hybrid approach combining filesystem presence checks and runtime CLI validation.
  • The SkillInstaller class maintains the agent mapping table at line 26 of src/officecli/Core/SkillInstaller.cs, linking identifiers like "claude" to their config directories.
  • Claude Code detection specifically checks for the ~/.claude directory and tests the claude mcp command via TryClaudeCli at line 220 of src/officecli/McpInstaller.cs.
  • The installation routine performs an atomic update by removing stale MCP entries (lines 203-211) before registering new ones (lines 177-191).
  • The architecture supports extensibility for multiple agents including Claude Code, Cursor, GitHub Copilot, and LM Studio through the unified detection interface.

Frequently Asked Questions

How does OfficeCLI detect if Claude Code is installed?

OfficeCLI performs a two-stage detection: first checking for the presence of the ~/.claude configuration directory defined in the SkillInstaller mapping table, then executing the claude mcp command via the TryClaudeCli method to verify the CLI is functional and supports MCP operations.

What happens if the Claude CLI is not in PATH?

If the claude binary is not found or executable in the system PATH, the TryClaudeCli method returns false and the installer skips MCP registration for Claude Code. The installation may continue for other detected agents, or the user may need to verify their Claude Code installation is properly configured.

Where does OfficeCLI store the skill configuration for Claude Code?

The skill configuration is stored within Claude Code's native MCP configuration, located in the ~/.claude directory. OfficeCLI modifies this configuration programmatically using the claude mcp add command to register the officecli skill as an available MCP server.

Can OfficeCLI auto-install skills for other AI agents besides Claude Code?

Yes, the SkillInstaller.cs mapping table includes entries for multiple agents including Cursor, GitHub Copilot, and LM Studio. Each agent follows the identical detection pattern: filesystem presence verification followed by CLI capability testing specific to that agent's implementation in McpInstaller.cs.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →