Skip to content

--agent <name> selection is dropped ~1s after startup (race with sign-in / MCP reload) #5124

Open

Description

@wzhmvz

Describe the bug

When starting the CLI with --agent <name>, the custom agent is selected and then silently deselected ~1 s later, before any user input. The banner shows Selected custom agent: my-agent, then MCP Servers reloaded: 1 server connected, and the agent disappears from the status bar; the session falls back to the default agent.

It looks like a race between the startup agent selection and the agent/MCP refresh after sign-in. events.jsonl of an affected session (no user input in between):

14:59:11.603 subagent.selected {"agentName":"my-agent"}
14:59:11.765 subagent.selected {"agentName":"my-agent"}
14:59:11.717 subagent.selected {"agentName":"my-agent"}   <- out of order, concurrent re-selection
14:59:12.400 subagent.deselected {}

The deselect follows Signed in to https://github.com and the MCP client re-init in the process log (Service initialized as client -> task cancelled -> Service initialized as client).

Affected version

1.0.95

Steps to reproduce the behavior

  1. Have a custom agent available (user-level ~/.copilot/agents/my-agent.md, or plugin-provided).
  2. Start interactively: copilot --agent my-agent
  3. Don't type anything; watch the banner and status bar for ~2 s.
  4. Agent is gone from the status bar; events.jsonl shows subagent.deselected.

Expected behavior

The agent passed via --agent stays selected for the whole session.

Additional context

  • Frequency (automated pty launches, no input, 15 s each): dropped 5/6 with a user-level agent (--agent my-agent), 4/6 with a plugin agent (--agent myplugin:my-agent).
  • When MCP startup failed (Failed to start MCP Servers: session not found), the agent was never dropped, which points to the MCP reload / agent-list refresh path clearing the selection.
  • Workaround: run /agent my-agent after startup.
  • macOS (Apple Silicon, arm64), zsh, launched via shell alias with --allow-all and several --deny-tool flags.

Activity

  1. added theissue type on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions