Skip to content

Commit daad420

Browse files
jrusso1020claude
andcommitted
fix(cli): let an agent's own name beat editor and host markers
TERM_PROGRAM=cursor|windsurf and Replit's REPL_ID only say where a shell runs. They now sit in their own list, checked after the AI_AGENT / AGENT name check, so Amp in a Cursor terminal or Devin in Replit report as themselves, and an unknown AI_AGENT there keeps its discovery hints. agentOnly had no users left, so it is gone. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent c14f258 commit daad420

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

‎packages/cli/src/telemetry/agent_runtime.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,16 @@ describe("detectAgentRuntime: agents seen in discovery hints", () => {
556556
expect(detectAgentRuntime()).toBe(runtime);
557557
});
558558

559+
it.each([
560+
[{ TERM_PROGRAM: "cursor", AI_AGENT: "amp" }, "amp"],
561+
[{ REPL_ID: "r", AGENT: "devin_20261101_agent" }, "devin"],
562+
[{ TERM_PROGRAM: "windsurf", AI_AGENT: "some-new-agent" }, "other_ai_agent"],
563+
])("lets an agent's own name beat the editor or host: %j -> %s", async (env, runtime) => {
564+
Object.assign(process.env, env);
565+
const { detectAgentRuntime } = await import("./agent_runtime.js");
566+
expect(detectAgentRuntime()).toBe(runtime);
567+
});
568+
559569
it("lets Claude Code's own shell marker beat the Agent SDK version key", async () => {
560570
process.env["CLAUDECODE"] = "1";
561571
process.env["CLAUDE_AGENT_SDK_VERSION"] = "0.2.0";

‎packages/cli/src/telemetry/agent_runtime.ts‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ export type AgentRuntime =
6969

7070
interface VendorRule {
7171
name: Exclude<AgentRuntime, null>;
72-
/** Check returns true when the named agent is driving the CLI. */
72+
/** Check returns true when the named agent (or, in WORKSPACE_RULES, that editor or host) runs the CLI. */
7373
check: (env: NodeJS.ProcessEnv) => boolean;
74-
/** Narrower than `check` when `check` also matches a person in that editor's terminal or host. */
75-
agentOnly?: (env: NodeJS.ProcessEnv) => boolean;
7674
}
7775

7876
// Ordering matters: the FIRST rule that matches wins. Put more specific rules
@@ -313,11 +311,15 @@ const VENDOR_RULES: VendorRule[] = [
313311
name: "claude_agent_sdk",
314312
check: (env) => typeof env["CLAUDE_AGENT_SDK_VERSION"] === "string",
315313
},
316-
// Editor terminals and hosted workspaces: these mark where the shell runs,
317-
// not that an agent drives it, so every agent marker above wins over them.
314+
];
315+
316+
// Editor terminals and hosted workspaces mark where a shell runs, not that an
317+
// agent drives it. Checked after every agent marker, the AI_AGENT name check
318+
// included, and never counted by isAgentDriven().
319+
const WORKSPACE_RULES: VendorRule[] = [
318320
// Cursor's TERM_PROGRAM identifies the IDE terminal only.
319321
// Source: https://docs.cursor.com/en/agent/terminal
320-
{ name: "cursor", check: (env) => env["TERM_PROGRAM"] === "cursor", agentOnly: () => false },
322+
{ name: "cursor", check: (env) => env["TERM_PROGRAM"] === "cursor" },
321323
// Windsurf (Codeium) integrated terminal — exports TERM_PROGRAM=windsurf.
322324
// Attested across many independent detectors (nx
323325
// packages/nx/src/native/ide/detection.rs, adonisjs/application, ag-grid
@@ -329,15 +331,13 @@ const VENDOR_RULES: VendorRule[] = [
329331
{
330332
name: "windsurf",
331333
check: (env) => env["TERM_PROGRAM"]?.toLowerCase() === "windsurf",
332-
agentOnly: () => false,
333334
},
334335
// Replit — REPL_ID and REPLIT_USER are long-documented environment
335336
// variables exposed inside every Replit workspace.
336337
// Source: https://docs.replit.com/replit-workspace/configuring-the-environment
337338
{
338339
name: "replit",
339340
check: (env) => typeof env["REPL_ID"] === "string" || typeof env["REPLIT_USER"] === "string",
340-
agentOnly: () => false,
341341
},
342342
];
343343

@@ -449,16 +449,17 @@ export function detectAgentRuntime(): AgentRuntime {
449449
for (const rule of VENDOR_RULES) {
450450
if (rule.check(process.env)) return rule.name;
451451
}
452-
return aiAgentFallback(process.env);
452+
return (
453+
aiAgentFallback(process.env) ??
454+
WORKSPACE_RULES.find((rule) => rule.check(process.env))?.name ??
455+
null
456+
);
453457
}
454458

455459
/** An agent is running this shell, not a person typing in an editor's terminal or a hosted workspace. */
456460
export function isAgentDriven(env: NodeJS.ProcessEnv = process.env): boolean {
457461
if (isGeminiManagedAgent()) return true;
458-
return (
459-
VENDOR_RULES.some((rule) => (rule.agentOnly ?? rule.check)(env)) ||
460-
aiAgentFallback(env) !== null
461-
);
462+
return VENDOR_RULES.some((rule) => rule.check(env)) || aiAgentFallback(env) !== null;
462463
}
463464

464465
/** Observed harness marker, not proof of a vendor, benchmark, or human user. */

0 commit comments

Comments
 (0)