`copilot --acp` does not work with `--agent`
- Dominant language
- Shell
- Stars
- 11.2k
- Forks
- 1.9k
- Avg merge
- 14h 16m
- Merged PRs (30d)
- 6
Description
### Describe the bug
Hello! First let me thank you for your hard work. Here is below my described issue. I used copilot a bit to help on having a proper reproducer command and a potential hint. Thanks a lot guys!
---
I created a custom agent in `~/.copilot/agents/test.agent.md`
```
---
name: test
description: A minimal test custom agent
tools: []
---
You are the test custom agent. Always respond by saying: "Hello from test custom agent!"
```
When I launch copilot in "human mode" with `copilot --agent test` it works.
```
● Selected custom agent: test
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
❯ hello
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
● Hello from test custom agent!
```
However when I try to use use ACP, with `copilot --acp --agent test`. It ALWAYS use the default Copilot agent. I can only use my custom agent as subagent, for example by saying "use test agent for <...>".
It seems like when using `--acp`, the `--agent` option is totally ignored.
### Affected version
GitHub Copilot CLI 1.0.65
### Steps to reproduce the behavior
## How to reproduce
#### 1. Create a minimal custom agent file in ~/.copilot/agents/test.agent.md:
```
---
name: test
description: A minimal test custom agent
tools: []
---
You are the test custom agent. Always respond by saying: "Hello from test custom agent!"
```
#### 2. Run this single command in your terminal to initialize a session and print the active agent configuration:
```
(echo '{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion":1,"clientCapabilities":{},"clientInfo":{"name":"test"}}}'; echo '{"jsonrpc":"2.0","id":1,"method":"session/new","params":{"cwd":"'"$(pwd)"'","mcpServers":[]}}'; sleep 6) | copilot --acp --agent test --yolo | grep -o '"id":"agent"[^}]*"currentValue":"[^"]*"'
```
## Expected behaviour
The active agent configuration option should reflect the command-line override ("test"):
```
"id":"agent","name":"Agent","currentValue":"test"
```
## Actual behaviour
The active agent configuration is empty, falling back to standard Copilot:
```
"id":"agent","name":"Agent","currentValue":""
```
### Expected behavior
Copilot should be launched in ACP with my custom agent as main agent. I want my session to have only the tools and context I have defined in my subagent, not with the general copilot gent. I don't want my custom agent to be available just as a tool.
## Expected behaviour
The active agent configuration option should reflect the command-line override ("test"):
```
"id":"agent","name":"Agent","currentValue":"test"
```
### Additional context
- Operating System: Linux (Kernel v24.16.0 or similar)
- CPU Architecture: x86_64 / x64 (installed as @github/copilot-linux-x64)
- Terminal Emulator: Ghostty (term/ghostty)
- Shell: Bash (v5.x)
- Copilot Version: v1.0.65
[copilot-acp-agent-bug.log](https://github.com/user-attachments/files/29375552/copilot-acp-agent-bug.log)
---
## Analysis by Copilot himself
- When starting in `--acp` server mode, the CLI action handler calls `startServerMode({...}, authManager)`. However, the parsed value of `--agent` (`t.agent` / `agentName`) is completely omitted from the configuration object passed to `startServerMode`.
- There is no way for the ACP client to specify the agent in the `session/new` params, and the ACP server does not implement the `session/set_config_option` method, making it impossible to change the active agent after session creation.
An analysis of the bundled index.js reveals exactly where the flow breaks:
#### 1. CLI Flag Parser:
The parser registers the --agent option correctly:
.option("--agent ", "Specify a custom agent to use")
#### 2. Server Mode Activation Block:
When `--acp` is supplied, the CLI invokes `startServerMode` like so:
```js
let { startServerMode: ee } = await Promise.resolve().then(() => (tIn(), Sto));
await ee({
port: de,
stdio: $,
logDir: G,
logLevel: b,
settings: p,
shutdownService: d,
featureFlags: r
}, a)
```
Notice that `t.agent` (the custom agent command-line argument) is completely omitted here! The starting server is never supplied with the `--agent` option context.
#### 3. ACP Protocol Limitations:
- The JSON-RPC request for `session/new` (`Ny.SESSION_CREATE`) does not include any parameter to define or activate an agent dynamically.
- While the ACP protocol schema defines a `session/set_config_option` method, the `registerMethods` routing mechanism on the server lacks an implementation of `setSessionConfigOption` (it is defined in the type definitions/client adapter `OSe` but is completely absent from the actual server class router).
### Suggestion for fix:
Pass the command-line override into `startServerMode` configuration parameters and use it to define the initial/default `currentValue` of the `"agent"` configuration option during session setup.
Contributor guide
Research direction
Start by tracing the ACP launch path in the bundled index.js from the --acp action to startServerMode, checking how the parsed --agent value is handled. Review session/new and the registerMethods routing mentioned in the report, then run the supplied reproducer and confirm that the agent configuration reports "test" rather than an empty value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 66/100