Skip to content

Commit 4e2b89c

Browse files
committed
Detect VS Code agent via VSCODE_AGENT, remove COPILOT_MODEL heuristic
VS Code 1.121+ sets VSCODE_AGENT for agent-initiated terminal commands. Detect it as `vscode-agent` in the User-Agent header. The previous COPILOT_MODEL heuristic reported `copilot-vscode` but COPILOT_MODEL is set by Copilot CLI BYOK users, not specifically by VS Code. The BYOK collapse logic (drop copilot-vscode when COPILOT_CLI is also set) is removed alongside the heuristic; VSCODE_AGENT can legitimately stack with COPILOT_CLI, which now correctly reports `multiple`. See: https://code.visualstudio.com/updates/v1_121
1 parent 311d530 commit 4e2b89c

3 files changed

Lines changed: 24 additions & 31 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### New Features and Improvements
66

7+
* Detect VS Code agent-initiated terminal commands via the `VSCODE_AGENT` environment variable (VS Code 1.121+). The User-Agent header now reports `agent/vscode-agent` when set. The previous `COPILOT_MODEL` heuristic (which reported `agent/copilot-vscode`) has been removed; it produced false positives for Copilot CLI BYOK users and never reliably identified VS Code.
8+
79
### Breaking Changes
810

911
### Bug Fixes

databricks-sdk-java/src/main/java/com/databricks/sdk/core/UserAgent.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,6 @@ private static List<KnownAgent> listKnownAgents() {
267267
new KnownAgent("CLINE_ACTIVE", "cline"), // https://github.com/cline/cline (v3.24.0+)
268268
new KnownAgent("CODEX_CI", "codex"), // https://github.com/openai/codex
269269
new KnownAgent("COPILOT_CLI", "copilot-cli"), // https://github.com/features/copilot
270-
// VS Code Copilot terminal; best-effort heuristic, not officially identified.
271-
new KnownAgent("COPILOT_MODEL", "copilot-vscode"),
272270
new KnownAgent("CURSOR_AGENT", "cursor"), // Closed source
273271
new KnownAgent("GEMINI_CLI", "gemini-cli"), // https://google-gemini.github.io/gemini-cli
274272
new KnownAgent(
@@ -277,6 +275,9 @@ private static List<KnownAgent> listKnownAgents() {
277275
new KnownAgent("KIRO", "kiro"), // https://kiro.dev/ (Amazon)
278276
new KnownAgent("OPENCLAW_SHELL", "openclaw"), // https://github.com/anthropics/openclaw
279277
new KnownAgent("OPENCODE", "opencode"), // https://github.com/opencode-ai/opencode
278+
// Set by VS Code 1.121+ for agent-initiated terminal commands
279+
// (https://code.visualstudio.com/updates/v1_121).
280+
new KnownAgent("VSCODE_AGENT", "vscode-agent"),
280281
new KnownAgent("WINDSURF_AGENT", "windsurf")); // https://codeium.com/windsurf (Codeium)
281282
}
282283

@@ -310,13 +311,6 @@ private static String lookupAgentProvider(Environment env) {
310311
}
311312
}
312313

313-
// Known BYOK false positive: Copilot CLI users often set COPILOT_MODEL
314-
// alongside COPILOT_CLI. Treat that pair as a single copilot-cli signal
315-
// rather than a stacked multi-agent setup.
316-
if (matches.contains("copilot-cli") && matches.contains("copilot-vscode")) {
317-
matches.removeIf(m -> m.equals("copilot-vscode"));
318-
}
319-
320314
if (matches.size() == 1) {
321315
return matches.get(0);
322316
}

databricks-sdk-java/src/test/java/com/databricks/sdk/core/UserAgentTest.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,27 @@ public void testAgentProviderAugment() {
241241
}
242242

243243
@Test
244-
public void testAgentProviderCopilotVscode() {
244+
public void testAgentProviderVscodeAgent() {
245+
setupAgentEnv(
246+
new HashMap<String, String>() {
247+
{
248+
put("VSCODE_AGENT", "1");
249+
}
250+
});
251+
Assertions.assertTrue(UserAgent.asString().contains("agent/vscode-agent"));
252+
}
253+
254+
@Test
255+
public void testAgentProviderCopilotModelAloneNotDetected() {
256+
// COPILOT_MODEL is set by Copilot CLI BYOK users and does not by itself
257+
// identify any agent.
245258
setupAgentEnv(
246259
new HashMap<String, String>() {
247260
{
248261
put("COPILOT_MODEL", "gpt-4");
249262
}
250263
});
251-
Assertions.assertTrue(UserAgent.asString().contains("agent/copilot-vscode"));
264+
Assertions.assertFalse(UserAgent.asString().contains("agent/"));
252265
}
253266

254267
@Test
@@ -415,30 +428,14 @@ public void testAgentProviderExplicitEnvWinsOverKnownAgentEnv() {
415428
}
416429

417430
@Test
418-
public void testAgentProviderCopilotCliAndCopilotVscodeCollapseToCopilotCli() {
419-
// Copilot CLI users (BYOK mode) often set COPILOT_MODEL alongside
420-
// COPILOT_CLI. Treat the pair as a single copilot-cli signal rather
421-
// than a stacked multi-agent setup.
422-
setupAgentEnv(
423-
new HashMap<String, String>() {
424-
{
425-
put("COPILOT_CLI", "1");
426-
put("COPILOT_MODEL", "gpt-4");
427-
}
428-
});
429-
Assertions.assertTrue(UserAgent.asString().contains("agent/copilot-cli"));
430-
}
431-
432-
@Test
433-
public void testAgentProviderCopilotByokCollapseStillMultiple() {
434-
// The Copilot BYOK collapse only drops the copilot-vscode match. If
435-
// another agent is also present, the result is still "multiple".
431+
public void testAgentProviderVscodeAgentAndCopilotCliReportsMultiple() {
432+
// VSCODE_AGENT can legitimately stack with other agents (e.g. running
433+
// Copilot CLI from a VS Code agent terminal).
436434
setupAgentEnv(
437435
new HashMap<String, String>() {
438436
{
437+
put("VSCODE_AGENT", "1");
439438
put("COPILOT_CLI", "1");
440-
put("COPILOT_MODEL", "gpt-4");
441-
put("CLAUDECODE", "1");
442439
}
443440
});
444441
Assertions.assertTrue(UserAgent.asString().contains("agent/multiple"));

0 commit comments

Comments
 (0)