Skip to content

Conversation

@Stanzilla
Copy link
Contributor

Current Behavior

When running Nx commands from VS Code Copilot's chat panel, Nx does not detect that it's running inside an AI agent. This means the TUI is enabled, which doesn't work well with AI agents that expect plain text output.

Expected Behavior

Nx should detect when it's running from VS Code Copilot's chat panel and disable the TUI accordingly, similar to how it handles Claude Code, Cursor, and Repl.it.

Related Issue(s)

Fixes #33698

Implementation

Added detection for VS Code Copilot by checking if the PATH environment variable contains github.copilot-chat. When VS Code Copilot runs terminal commands, it adds its CLI tool path (e.g., .../globalStorage/github.copilot-chat/copilotCli) to the PATH.

Changes:

  • Added is_vscode_copilot() function to detect VS Code Copilot
  • Added is_vscode_copilot_from_path() helper for testability
  • Updated is_ai_agent() to include VS Code Copilot detection
  • Added unit tests for the new detection logic

@Stanzilla Stanzilla requested review from a team as code owners December 8, 2025 22:02
@Stanzilla Stanzilla requested a review from AgentEnder December 8, 2025 22:02
@netlify
Copy link

netlify bot commented Dec 8, 2025

👷 Deploy request for nx-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 9e83719

@vercel
Copy link

vercel bot commented Dec 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Dec 9, 2025 11:23am

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Dec 9, 2025

View your CI Pipeline Execution ↗ for commit cbbcf4f

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ❌ Failed 1h 39m 57s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 2m 37s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 12s View ↗
nx-cloud record -- nx format:check ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-09 11:16:50 UTC

Copy link
Contributor

@nx-cloud nx-cloud bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nx Cloud is proposing a fix for your failed CI:

We fixed the Rust formatting violation in the VS Code Copilot detection test by moving the .to_string() method call to a separate line with proper indentation. This change resolves the nx:format-native task failure while preserving the PR's functionality to detect VS Code Copilot as an AI agent.

We could not verify this fix.

Suggested Fix changes
diff --git a/packages/nx/src/native/utils/ai.rs b/packages/nx/src/native/utils/ai.rs
index ba8098f603..01ffb0c378 100644
--- a/packages/nx/src/native/utils/ai.rs
+++ b/packages/nx/src/native/utils/ai.rs
@@ -216,7 +216,8 @@ mod tests {
         // Test with PATH containing copilot-chat
         assert!(
             is_vscode_copilot_from_path(Some(
-                "/usr/bin:/some/path/globalStorage/github.copilot-chat/copilotCli:/usr/local/bin".to_string()
+                "/usr/bin:/some/path/globalStorage/github.copilot-chat/copilotCli:/usr/local/bin"
+                    .to_string()
             )),
             "Should detect VS Code Copilot with github.copilot-chat in PATH"
         );

Because this branch comes from a fork, it is not possible for us to apply fixes directly, but you can apply the changes locally using the available options below.

Apply changes locally with:

npx nx-cloud apply-locally tKdo-8oIK

Apply fix locally with your editor ↗   View interactive diff ↗


🎓 Learn more about Self-Healing CI on nx.dev

Add detection for VS Code Copilot chat by checking if the PATH
environment variable contains 'github.copilot-chat'. This ensures
the TUI is disabled when running commands from VS Code Copilot's
chat panel, providing better output for AI agents.

Ref nrwl#33698
Copy link
Collaborator

@MaxKless MaxKless left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Stanzilla I appreciate the PR!
I went into VSCode to verify and it looks like the copilot string is also added to PATH in the regular vscode terminal, not just when running through copilot itself (see below).
This would mean that the TUI won't be shown in the vscode terminal which isn't what we want. So I think we'll need another approach here...

Image

@Stanzilla
Copy link
Contributor Author

Thanks for catching that @MaxKless! You're right - I just verified and the github.copilot-chat path is present in the regular VS Code terminal as well, not just in Copilot agent mode.

I've checked the environment more thoroughly, and unfortunately there doesn't appear to be a unique environment variable that distinguishes Copilot agent mode from regular VS Code terminal usage:

  • GIT_PAGER=cat is set, but this might also be common in regular VS Code
  • No COPILOT_* or similar specific env vars are set
  • TTY status is the same in both cases (stdin/stdout/stderr all report as terminals)
  • Parent process is the same VS Code helper

Do you have any suggestions for how we might detect Copilot agent mode specifically? Some possibilities:

  1. Is there perhaps a VS Code extension API that could set a specific env var when running from agent mode?
  2. Could Copilot itself set something like GITHUB_COPILOT_AGENT=1 when invoking terminal commands?
  3. Should we file an issue with the Copilot team to request an environment variable for this use case?

Alternatively, would it make sense to approach this from a different angle - perhaps detecting that the terminal is not truly interactive in some way, even if it reports as a TTY?

fn is_vscode_copilot_from_path(path: Option<String>) -> bool {
match path {
Some(path) => {
let is_copilot = path.contains("github.copilot-chat");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this in the PATH just means that the copilot extension is installed. There's actually intentionally not a way right now to determine whether the session is being driven by AI because I worry about tools starting to behave differently if we offer that and therefore start working differently when ideally the agent would be able to handle everything.

What do you think? microsoft/vscode#253945 (comment)

Do most other terminals driven by AI include environment variables now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the code present here, at least Claude, Replit and Cursor are. That's what NX detects right now to do exactly what you were worried about. But is that still a problem for you? Do you see any other good way this could be handled in tools like NX? You don't actually have access to the harness etc, the only thing you could do is try to force it via agent instructions?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tyriar thanks for chiming in here! At least there's a solid workaround which is setting NX_TUI=false in the terminal profile setting @Stanzilla (you could also add an instruction to your AGENTS.md or whatever to always run tasks with NX_TUI=false).

@Tyriar I get where you're coming from with not wanting to have tools adapt too much to whether they're being driven by an agent or human. Right now TUIs kind of don't work well with the text-based approach agents have to input/output, so this being broken is a side effect of that decision.
Other tools we looked into do have a way of telling agent invocations apart from regular ones and it's helpful for us.
Seems like either choice will have its drawbacks - one of them immediately relevant today though while the other one is more theoretical in the future. Tricky for sure :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI Auto Exit does not work in VSCode

3 participants