/** * @file Which AI agent is invoking this process, read from the environment the * running agent injects. * The answer comes from env, never from a stdin payload: a Claude Code hook * gets `{tool_name,…}` on stdin but no agent id, and Codex/OpenCode use * entirely different invocation contracts. The cross-agent signal is * `AI_AGENT`; tool-specific markers are the fallback. * The complement is `ai/discover`, which answers which agents are INSTALLED * on PATH. This answers which one is DRIVING. */ import type { DetectedAgent } from './context.js'; /** * Detect which AI agent is invoking the current process, from the environment. * * Resolution order: * * 1. `AI_AGENT` — the cross-agent signal, which Claude Code sets. Its leading * token names the family. * 2. Tool-specific markers as a fallback: `CLAUDECODE=1` / `CLAUDE_CODE_*` → * claude; `OPENCODE_TERMINAL` / `OPENCODE` → opencode; `CODEX_*` → codex. * * Returns `undefined` when no agent signal is present (a plain shell, CI, a * non-agent subprocess) — callers should treat that as "agent-agnostic", not an * error. * * Note: a hook receives NO agent id in its stdin payload; this env read is the * only reliable signal. Different agents also invoke hooks differently (Claude: * stdin JSON; Codex: its own hooks; OpenCode: plugin callbacks), so a * `.claude/hooks/` script is fundamentally Claude-invoked — `detectAgent()` is * most useful for scripts/skills that want to branch on the active agent, or * when an agent delegates to another. * * @example * const detected = detectAgent() * if (detected?.agent === 'claude') { ... } */ export declare function detectAgent(): DetectedAgent | undefined;