Skip to content

fix(windows): support npm shims in agent authentication - #2970

Open
janburzinski wants to merge 2 commits into
generalaction:mainfrom
janburzinski:fix/windows-codex-login-pty
Open

fix(windows): support npm shims in agent authentication#2970
janburzinski wants to merge 2 commits into
generalaction:mainfrom
janburzinski:fix/windows-codex-login-pty

Conversation

@janburzinski

Copy link
Copy Markdown
Collaborator

Description

Fix Codex authentication on Windows when an npm installation exposes an extensionless POSIX shim before codex.cmd.

Previously, Emdash could pass the extensionless shim directly to node-pty/ConPTY, causing: Failed to spawn PTY: Cannot create process, error code: 193

This change:

  • filters extensionless Windows command matches when a runnable .cmd, .bat, .com, or .exe candidate exists
  • launches trusted static authentication commands through the appropriate Windows command wrapper
  • supports both the interactive codex login PTY and the codex login status check
  • keeps the Windows script adapter behind an explicit windowsScript: 'trusted' boundary
  • prevents generic TUI prompts and user-controlled arguments from entering the cmd.exe serializer
  • adds regression coverage for command resolution, Windows argument escaping, trusted auth execution, and untrusted TUI pass-through

The trust boundary is intentionally limited to plugin-owned static authentication commands. Generic Windows npm-shim TUI execution remains outside the scope of this PR.

Related issues

https://discord.com/channels/1422831935553667175/1530791430929256508

Testing

tested this on my windows 10 computer

Checklist
  • I kept this PR small and focused
  • I ran a self-review before opening this PR
  • I ran the relevant local checks or explained why not
  • I updated docs when behavior or setup changed
  • I added or updated tests when behavior changed, or explained why not
  • I only added comments where the logic is not obvious
  • I used Conventional Commits for commit
    messages and, when possible, the PR title
@greptile-apps

greptile-apps Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds trusted Windows npm-shim support for static agent authentication commands.

  • Filters extensionless Windows command matches when executable shim candidates are available.
  • Routes trusted .cmd and .bat authentication commands through cmd.exe for buffered and PTY execution.
  • Marks shared, Claude, and OpenCode authentication status commands as trusted while leaving generic TUI execution unchanged.
  • Adds regression coverage for command resolution, escaping, authentication execution, and trust-boundary behavior.

Confidence Score: 5/5

The PR appears safe to merge.

The previously reported Windows status-shim issue is fixed: Claude, OpenCode, and shared authentication checks now propagate the trusted-script marker through the agent-config runtime's NodeExecutionContext, which wraps resolved .cmd and .bat shims with cmd.exe.

Important Files Changed

Filename Overview
packages/core/src/exec/windows-script-command.ts Introduces the explicitly gated Windows command wrapper and argument serializer used for trusted authentication scripts.
packages/core/src/exec/node-execution-context.ts Applies trusted Windows script resolution before buffered child-process execution.
packages/core/src/pty/node/node-pty-spawner.ts Applies the same trusted wrapper to interactive authentication PTY launches without changing generic TUI execution.
packages/core/src/host-dependencies/runtime/probe.ts Prefers runnable Windows executable extensions over extensionless command matches.
packages/plugins/src/agents/helpers/auth.ts Propagates the trusted-script marker through shared static authentication status checks.
packages/plugins/src/agents/impl/claude/auth.ts Correctly marks Claude's static authentication status invocation for Windows shim adaptation.
packages/plugins/src/agents/impl/opencode/auth.ts Correctly marks OpenCode's static authentication status invocation for Windows shim adaptation.
packages/runtime/src/agent-config/runtime/auth.ts Marks the plugin-owned interactive authentication command as trusted for PTY execution.

Sequence Diagram

sequenceDiagram
  participant UI as Agent configuration UI
  participant Runtime as AgentConfigRuntime
  participant Host as AgentPluginHost
  participant Exec as NodeExecutionContext
  participant Cmd as cmd.exe
  participant Agent as Agent npm shim
  UI->>Runtime: Refresh authentication status
  Runtime->>Host: checkAuthStatus(provider)
  Host->>Exec: exec(cli, static args, windowsScript: trusted)
  Exec->>Exec: Resolve .cmd/.bat wrapper
  Exec->>Cmd: /d /s /c escaped command
  Cmd->>Agent: Run authentication status command
  Agent-->>Runtime: Authentication output
Loading

Reviews (2): Last reviewed commit: "fix(auth): route Windows status shims th..." | Re-trigger Greptile

Comment thread packages/plugins/src/agents/helpers/auth.ts
@janburzinski janburzinski changed the title text fix(windows): support npm shims in agent authentication Jul 31, 2026
@janburzinski

Copy link
Copy Markdown
Collaborator Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant