Repository navigation
Description
Problem
When VS Code Copilot Chat (or its subagents) executes a command in the terminal via tools like run_in_terminal or execution_subagent, there is no way for CLI tools to detect that the command was initiated by an AI agent rather than a human user.
Other AI coding agents already set environment variables in spawned subprocesses:
| Agent | Environment Variable(s) |
|---|---|
| Claude Code CLI | CLAUDECODE, CLAUDE_CODE |
| Cursor | CURSOR_AGENT |
| Codex | CODEX_SANDBOX, CODEX_THREAD_ID |
| Gemini CLI | GEMINI_CLI |
| Augment | AUGMENT_AGENT |
| Opencode | OPENCODE_CLIENT, OPENCODE |
| AMP | AMP_CURRENT_THREAD_ID |
| Antigravity | ANTIGRAVITY_AGENT |
There is also a generic convention (AI_AGENT) used by tools like shipfastlabs/agent-detector and discussed in agentsmd/agents.md#136.
Proposal
When Copilot Chat (or a subagent) runs a command in the terminal, set an environment variable such as:
COPILOT_AGENT=1
or follow the generic convention:
AI_AGENT=copilot
This would allow CLI tools to:
- Output machine-readable formats (JSON) instead of ANSI-decorated human-readable text, reducing token usage and improving parsing accuracy
- Disable interactive prompts that would otherwise block the agent
- Skip animations and progress bars that add noise to agent output
Context
The VS Code core team closed microsoft/vscode#258911 arguing that agent terminals should behave like user terminals. However, this is a different request — it is not about changing terminal behavior but about giving programs the ability to optimize their output format when they know an agent is consuming it. The terminal itself stays the same; the program running inside it adapts.
This is analogous to how CI=true allows programs to detect CI/CD environments and adjust behavior accordingly (disable interactive prompts, simplify output, etc.). The same pattern is valuable for AI agent environments.
Real-world use case
The Bootgly PHP Framework test runner (bootgly test) detects AI agents via environment variables and outputs compact JSON instead of ANSI-formatted text when an agent is detected. This dramatically improves the agent's ability to parse test results accurately. However, Copilot Chat currently cannot be detected because it does not set any identifying environment variable when running terminal commands.
Activity
sdairs commentedon May 4, 2026
+1 but more harnesses have adopted
AGENTthanAI_AGENT, so that would be preferable.molisani commentedon May 4, 2026
The proposal referenced seems to be the main focal point of the effort to standardize this environment variable, and it now proposes
AGENTrather thanAI_AGENT.vs-code-engineering commentedon May 6, 2026
This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.
Happy Coding!
vs-code-engineering commentedon May 8, 2026
🙂 This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.
Happy Coding!
Set COPILOT_AGENT env var in agent terminals (#316267)
Set COPILOT_AGENT env var in agent terminals (microsoft#316267)
feat(cli): detect GitHub Copilot agent sessions