Files
Holocron/docs/research/copilot-cli-agents/copilot-cli-agents.md
T
Defame1297andClaude Opus 5.5 40fcb08e94 docs(research): record Copilot CLI agent behaviour from docs
Findings for Wayfinder research ticket #187 (map #166): subagent
delegation from --agent sessions, pinned model handling, the agent
tool alias for strict tool lists, and preToolUse deny/ask hooks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012CqgnwEGtmfsjcoG9QwByN
2026-11-22 16:34:06 +00:00

30 KiB

Copilot CLI: custom agents, subagent delegation, pinned models and preToolUse hooks

Wayfinder research ticket, Gitea Mortis/Holocron #187 (map #166). Docs-only: Copilot CLI was not installed and no account was used, so nothing here was tested hands-on. Researched 2026-11-22.

Every claim is backed by a primary source: docs.github.com, or the github/copilot-cli repository's changelog.md, releases or issues. The docs.github.com pages carry no version or date, so they are cited as "retrieved 2026-11-22". At that date the newest changelog entry is 1.0.114 (2026-11-18). Changelog entries are cited as vX.Y.Z (date). Some entries appear twice, in both 1.0.106 and 1.0.107, and this note cites the earlier one.

Answers

  1. Delegation from a --agent session: Yes, in both interactive and -p mode, as far as the docs and changelog show. The session agent dispatches subagents through the task tool, custom agents included, and the default tools: ["*"] keeps task available. No doc page says in so many words "a session started with --agent can delegate", so this is inferred. Agents are *.agent.md (or *.md) files in ~/.copilot/agents/, .github/agents/, .claude/agents/, plugin agents/, or org/enterprise repositories.
  2. Pinned model: Yes, it is honoured now, with caveats. #980 (ignored entirely) was fixed in 0.0.415 (2026-02-23). #2950 (ignored when the agent is delegated to via a prompt) was closed on 2026-10-04 as "resolved as of v1.0.91", but no 1.0.91 changelog entry mentions it. #4437 (a .claude/agents model: hijacking a .github/agents agent) is still open, and a fix was announced for v1.0.104. An explicit --model, a subagents override, or an Auto session model still beats the pinned model unless the agent sets model-policy: required.
  3. tools and delegation: Yes. A restricted tools list must include the subagent tool. The documented custom-agent alias is agent, with compatible aliases custom-agent and Task (case-insensitive). The CLI's underlying tool is named task, with companions read_agent, write_agent and list_agents. runSubagent is not documented for Copilot CLI.
  4. preToolUse with deny and ask: Yes, both are documented. permissionDecision takes "allow", "deny" or "ask". Hooks live in .github/hooks/*.json, ~/.copilot/hooks/*.json, settings files, plugins or agent frontmatter. ask has been supported since 1.0.4 (2026-03-11), but autopilot and cloud agent convert it to deny, and -p behaviour for ask is not documented. Open bug #3590 reports the TUI auto-approving ask since 1.0.53.

Q1. Delegation from a --agent session, and how custom agents are defined

Delegation

  • The main agent "can choose to delegate a task to a subsidiary subagent process" using a custom agent. You can also run a custom agent for the whole session with /agent, by naming it in a prompt, or with copilot --agent=<id> --prompt "...". Source: Invoke custom agents, retrieved 2026-11-22.
  • "Selecting a custom agent for a whole session and delegating a subtask to one are different uses of the same profile." Source: About custom agents (CLI), retrieved 2026-11-22.
  • The CLI command reference names the "Session agent (the default agent, or a custom agent selected with --agent)" as a role distinct from a "Custom agent spawned as a subagent — through the task tool". It also documents nesting: "When the depth limit is reached, the innermost agent cannot spawn further subagents." The default max depth is 6 (maximum 256). Source: CLI command reference, Custom agents reference, retrieved 2026-11-22.
    • The changelog contradicts the depth default. It says "Lower the default maximum sub-agent nesting depth from 6 to 4" in v1.0.71 (2026-07-16). I'm not certain which value is current. Either way, maxDepth can only be changed on usage-based billing plans.
  • tools defaults to ["*"] (all tools), so an agent without a tools list has task. Source: same CLI command reference, "Custom agent frontmatter fields".
  • -p / prompt mode: the changelog records subagent dispatch working headlessly:
    • v1.0.49 (2026-05-18): "Plugins loaded via --plugin-dir now correctly register their agents as available task(agent_type=...) subagents in prompt mode".
    • v1.0.81 (2026-08-27): "--agent <plugin>:<agent> works headlessly".
    • v1.0.106 (2026-11-05): "In -p mode, a sub-agent's streamed reply now ends with a line break ... the task tool's row".
  • Issue #4437 (CLI 1.0.79) contains a working repro in which a custom orchestrator agent with tool task spawns task(agent_type: developer, ...). That is user evidence, not documentation.
  • Not documented: no page explicitly says that a custom agent selected with --agent together with -p can delegate to another custom agent. The evidence above strongly implies it can, but I'm not certain without a hands-on test.

Definition: locations and precedence

From the CLI command reference, "Custom agent locations", retrieved 2026-11-22. When two agents share an ID, the first one loaded wins.

Priority Scope Location
1 (highest) User ~/.copilot/agents/
2 Project .github/agents/, from the cwd up to the Git root (deepest wins)
3 Project .claude/agents/, from the cwd up to the Git root
4 Added root .github/agents/ and .claude/agents/ under --add-dir / /add-dir directories
5 Plugin <plugin>/agents/
6 (lowest) Remote Organization or enterprise agents
  • Naming: a file named *.agent.md or *.md. The agent ID is the file name minus that extension, and subdirectories are joined with --: agents/team/reviewer.agent.md becomes team--reviewer. The name field does not deduplicate. Sources: the CLI command reference above, and Create custom agents for CLI, retrieved 2026-11-22.
  • Discovery changes in the changelog:
    • Agents are discovered recursively: v1.0.55 (2026-05-28).
    • Nested .github/agents directories are found from subdirectories: v1.0.62 (2026-06-13).
    • Agents added to .github/agents/ during a session are used without reloading: v1.0.109 (2026-11-10).
    • The original feature shipped in v0.0.353 (2025-10-28).

Frontmatter fields

The field names differ between docs pages. The CLI command reference uses camelCase (modelPolicy, reasoningEffort). The CLI how-to and the --model option text use kebab-case (model-policy, strict-tools-list). Changelog v1.0.88 also uses reasoning-effort. I'm not certain whether both spellings are accepted. Kebab-case is what the how-to example and the changelog use.

Field Meaning (source)
description Required. Shown in the agent list and in the task tool (CLI ref).
name Optional display name, usable with --agent (CLI ref).
tools List of tools; the default is ["*"] (CLI ref). The config reference also allows a comma-separated string.
model Model for the agent; inherits the outer agent's model when unset (CLI ref). The how-to says to use the provider-qualified ID for BYOK models. Display names have been accepted since v1.0.24.
models List of models in priority order; overrides model (CLI ref). Changelog v1.0.83 instead says model itself can hold a list.
modelPolicy / model-policy preferred (default) or required (CLI ref, how-to).
reasoningEffort / reasoning-effort Default effort (CLI ref; changelog v1.0.66, v1.0.88).
strict-tools-list true limits the agent to the listed tool groups "without adding the usual default tools" (how-to).
include-custom-instructions Lets the agent receive AGENTS.md, CLAUDE.md and copilot-instructions.md when it runs as a subagent (CLI ref, how-to; v1.0.86).
infer "Allow auto-delegation by the main agent", default true (CLI ref). The config reference marks it retired in favour of disable-model-invocation and user-invocable (v0.0.411, 2026-02-17).
disable-model-invocation true means the agent must be selected by hand and is not auto-delegated (config ref).
user-invocable false hides the agent from the picker so it is only reachable programmatically (config ref; v0.0.412).
mcp-servers Per-agent MCP servers (CLI ref, config ref).
hooks Agent-scoped hooks that apply only while the agent is selected (hooks ref; v1.0.97).
deferred-tool-loading Opt-in tool search (changelog v1.0.52).

Source for the config-reference rows: Custom agents configuration, retrieved 2026-11-22.

  • Unknown frontmatter keys produce a warning instead of blocking the load since v0.0.415 (2026-02-23).
  • Since v1.0.106 (2026-11-05), -p --agent prints a warning to stderr for frontmatter keys that Copilot ignores.
  • A custom agent whose name matches a built-in agent (explore, task, general-purpose, code-review, research, rubber-duck, security-review) is not offered for delegation, because "delegating to that name always runs the built-in agent". Source: v1.0.106 (2026-11-05).

Q2. Is a pinned model honoured?

Current documented behaviour

From the CLI command reference, frontmatter fields, retrieved 2026-11-22:

  • The pinned model applies "whether the agent is dispatched through the task tool or started directly".
  • Precedence, highest first:
    1. an explicit per-call value (the task call's model argument);
    2. the subagents override in ~/.copilot/settings.json or the /subagents picker;
    3. the agent's model, models or reasoningEffort;
    4. the parent session's value.
  • "A declared model or effort that can't be honored falls back to the session's value instead of failing the dispatch — unless the agent declares modelPolicy: "required"", in which case dispatch is refused.
  • "When the session model is set to Auto (server-selected), subagents always inherit the resolved session model regardless of this field." Changelog v1.0.33 (2026-04-20) says the same: "Sub-agents in auto mode now inherit the session model".
  • The --model option: "An explicit --model takes precedence over a custom agent's model unless the agent sets model-policy: required." Changelog v1.0.106 (2026-11-05) agrees: "Use explicit --model with custom agents unless the agent requires a specific model".

Issues about the pinned model being ignored

Issue Title Status Fix / cross-check
#980 Model from agent.md isn't recognized Closed, completed, 2026-04-07 A comment says it was fixed in v0.0.415. The changelog for v0.0.415 (2026-02-23) agrees: "Custom agents support the model field ... unknown fields now warn instead of blocking agent load". Before that, 0.0.400 reported agent uses unsupported fields: model for a .github/agents/*.agent.md file.
#2950 Calling custom agent via prompt ignores configured model in agent.md Closed, completed, 2026-10-04 Reported on 1.0.35. --agent honoured the model, but delegation through a prompt did not; a commenter adds that orchestrator subagents all ran on the orchestrator's model. It was closed by an automated comment saying "resolved as of v1.0.91". The v1.0.91 changelog has no matching entry, so I can't confirm which release fixed it. Candidate entries: v1.0.85 (2026-09-16), "Subagent launches honor explicit model, reasoning effort, and context tier preferences ..."; v1.0.62 (2026-06-13); v1.0.22 (2026-04-09), "Plugin agents respect the model specified in their frontmatter".
#2758 Feature Request: Allow sub-agents to use the model specified in frontmatter/task() — add opt-out for the cost-multiplier guard Open (filed 2026-04-16) Logs show Downgrading subagent model from "claude-sonnet-4.6" (1x) to session model "gpt-4.1" (0x), a downgrade applied when the session runs on a 0x model. No changelog entry removes this guard. The modelPolicy: required behaviour (refuse instead of substitute) may change it, but I'm not certain whether the guard still exists.
#4437 Repo .claude/agents/*/AGENT.md model: field overrides session model for Copilot custom agents, breaking subagent spawns on BYOK providers Open, more-info-needed Reported on 1.0.79. On 2026-10-26 a collaborator said a fix "will ship in the next release (v1.0.104)". The v1.0.104 changelog has no matching entry. The issue is still open.
#3891 Sub-agent model: override is silently dropped in BYOK / custom-provider mode Closed, completed, 2026-07-16 Changelog v1.0.62 (2026-06-13): "Keep custom agents on their configured model when using BYOK providers"; v1.0.65 (2026-06-24): "Keep custom-agent subagent model selections when using BYOK providers".
#2133, #3070 model array syntax rejected / accept array Closed, completed Changelog v1.0.83 (2026-09-04): model can be a list.
#2845 Model name shown in UI is different from the actual model loaded when custom agent enabled Open Display-only. Not verified further.
#5241 Copilot app: selecting a custom agent ... doesn't apply its model or reasoning-effort Open Affects the Copilot desktop app, not the CLI.
  • apm-specific issues: I found none. Searches for "apm" and ".github/agents model" in github/copilot-cli returned no issue about agents deployed by apm.
  • The issues that do involve .github/agents/ are #980 (.github/agents/*.md) and #4437, where a .github/agents/<name>.md agent picks up the model: of a same-named .claude/agents agent.
  • Copilot CLI itself has no notion of who wrote a file. An apm-deployed .github/agents/*.agent.md is treated like any other project agent, as far as the docs say.

Q3. Which tool a tools list needs for delegation

  • Custom-agent tool alias table. Source: Custom agents configuration, "Tool aliases", retrieved 2026-11-22.
    • The relevant row: primary alias agent, compatible aliases custom-agent and Task, purpose: "Allows a different custom agent to be invoked to accomplish a task."
    • "All aliases are case insensitive."
    • "All unrecognized tool names are ignored". A misspelled alias therefore fails silently and does not raise an error.
  • CLI tool names. Source: CLI command reference, "Agent and task delegation tools", retrieved 2026-11-22.
    • task ("Run subagents")
    • list_agents
    • read_agent ("Check background agent status")
    • write_agent ("Send a message to a running agent")
  • Changelog:
    • v0.0.380 (2026-01-13): "Custom agent tool aliasing for the task tool".
    • v1.0.64 (2026-06-23): "Keep task companion tools available to custom agents that use the task or agent alias". This implies that listing agent or task also brings in read_agent, write_agent and list_agents.
  • Hooks naming: in Claude-format hooks, the runtime tool task maps to the Claude name Agent. Source: CLI hooks reference, retrieved 2026-11-22.
  • Recommendation: list agent, which is the documented primary alias. Listing task (the raw tool name) is also accepted per v1.0.64.
  • runSubagent: not documented for Copilot CLI on any page I read.
  • strict-tools-list: without it, the CLI adds "the usual default tools" to a restricted list (how-to page). Not documented: whether task is one of those default tools. Don't rely on it; list agent explicitly.
  • Older bugs in this area (closed):
    • #556, "Copilot CLI --agent use does not respect tool filtering", closed 2026-02-25.
    • #4594 and #4023: the web and search aliases bound no tools. Closed 2026-10-26; fixed in v1.0.100 (2026-10-19) and v1.0.106.
    • #3531: Claude-style scalar tools: Read, Write, Bash. Closed not_planned by its reporter (not GitHub staff), who said the scalar form already loads on 1.0.55.

Q4. preToolUse hooks: deny and ask before a shell command

All points below come from the CLI hooks reference, retrieved 2026-11-22, unless noted.

Config locations (all matching entries run)

  • Policy: /etc/github-copilot/policy.d/*.json. Root-owned, loaded first, and cannot be disabled.
  • Repository: .github/hooks/*.json.
  • User: ~/.copilot/hooks/*.json (or $COPILOT_HOME/hooks/). Added in v0.0.422 (2026-03-05).
  • Inline hooks key in settings files:
    • repository: .github/copilot/settings.json, .github/copilot/settings.local.json, .claude/settings.json, .claude/settings.local.json;
    • user: ~/.copilot/settings.json.
    • ~/.copilot/config.json is no longer read for hooks.
  • Plugins: hooks.json or hooks/hooks.json.
  • Agent-scoped: a hooks map in a custom agent's frontmatter. CLI only, and active only while that agent is selected (v1.0.97, 2026-10-13).
  • Trust: repository hooks load only after folder trust is confirmed (v1.0.8). In -p they load only when the folder is already trusted, COPILOT_ALLOW_ALL is set, or GITHUB_COPILOT_PROMPT_MODE_REPO_HOOKS=true (CLI command reference env vars; changelog v1.0.40 and v1.0.49). Since v1.0.111 (2026-11-13), the CLI warns when -p --trust-folder runs from a subdirectory and skips the root hooks.

Schema

{
  "version": 1,
  "hooks": {
    "preToolUse": [
      { "type": "command", "bash": "./scripts/guard.sh", "powershell": "...", "command": "...",
        "cwd": ".", "env": { "K": "V" }, "timeoutSec": 30, "matcher": "bash|powershell" }
    ]
  }
}
  • type is command (the default) or http. HTTP entries take url (which must be https for preToolUse), headers and allowedEnvVars.
  • command is the cross-platform fallback for bash and powershell. exec and args run without a shell.
  • timeoutSec defaults to 30; timeout is an alias.
  • matcher is a regex anchored as ^(?:PATTERN)$ against toolName. The changelog says the matcher was ignored before v1.0.36 (2026-04-24).
  • PascalCase PreToolUse with the Claude-style nested matcher/hooks structure is also accepted (v1.0.6). Its matcher uses Claude tool names, so bash and powershell match as Bash.

Input on stdin

  • camelCase (preToolUse): { sessionId, timestamp (Unix ms), cwd, toolName, toolArgs }. toolArgs is typed unknown.
    • Not documented: whether toolArgs arrives as a JSON string or an object. I'm not certain.
  • The shell tool is named bash or powershell.
  • PascalCase (PreToolUse): { hook_event_name, session_id, timestamp (ISO 8601), cwd, tool_name ("Bash"), tool_input }.
  • Subagent calls also carry agentId, agentType and parentAgentId. Hooks fire for subagent tool calls since v1.0.49 (2026-05-18).

Output on stdout

  • permissionDecision: "allow", "deny" or "ask".
  • permissionDecisionReason: required for deny.
  • modifiedArgs: replacement tool arguments.
  • If any hook returns deny, the tool call is blocked.

Exit codes and failure modes

  • Exit 0: stdout is parsed.
  • Exit 2: treated as a deny that a stdout allow cannot override. Exit-2 deny was added in v1.0.70 (2026-07-09).
  • Any other non-zero exit, or a crash, fails closed: the call is denied with "Denied by preToolUse hook (hook errored)". Since v1.0.57 (2026-06-01) a hook error denies the call instead of allowing it.
  • Command-hook timeouts fail open, "even for preToolUse and policy hooks". So do HTTP hook network errors and non-2xx responses. Changelog v1.0.67 (2026-06-30): "Allow tool calls to continue when hooks time out".

Is ask actually supported?

  • Documented: yes. Changelog v1.0.4 (2026-03-11): "Hooks can now request user confirmation before tool execution with 'ask' permission decision". When the CLI can show the prompt, the user can deny with feedback, which is forwarded to the agent (v1.0.64).
  • Documented exceptions:
    • Under autopilot, ask is denied (v1.0.97).
    • Under cloud agent, ask is treated as deny.
    • In ACP mode, ask goes to the ACP client since v1.0.109 (2026-11-10), after #5396, which was closed.
  • -p (non-interactive) mode: not documented for ask. The hooks reference points -p and CI users to permissionRequest hooks for programmatic allow and deny instead.
  • Issues:
    • #3590, "PreToolUse hook permissionDecision: "ask" auto-approved by TUI since v1.0.53": open. The prompt flashes and is auto-approved; 1.0.52 worked. Later changelog entries assume ask prompts work: v1.0.64 forwards rejection feedback, and v1.0.108 (2026-11-09) gives parallel calls their own confirmation. I'm not certain whether #3590 still reproduces on 1.0.114.
    • #4135, "Hook ask decisions show raw JSON instead of diff view": open. Cosmetic.
    • #4237, "Steering message in preToolUse "ask" denial is silently dropped": closed, completed, 2026-09-19.
    • #2647, "preToolUse "ask" feedback is not shown to the agent": closed, completed, 2026-09-25.
    • #2893, "preToolUse hooks silently bypassed under parallel tool calls (timeout->allow fallback + serial dispatch)": open (reported on 1.0.35). The documented timeout fail-open behaviour is the root cause. The hooks reference now says hooks for different calls in a parallel batch run concurrently, which may address the serial-dispatch half.
    • #2540, "Plugin-defined preToolUse hooks (hooks.json) do not fire": open, more-info-needed (reported on 1.0.18).
    • #5326, "Denied by preToolUse hook from ".github/hooks/rtk-rewrite.json" (hook errored)": open, on 1.0.104 in cloud. It shows how a repository hook that errors blocks every call (fail-closed). This matters here because this repo uses rtk.

Limitations for delivery agents

These are the open bugs and undocumented behaviours that could affect our custom agents deployed by apm into .github/agents/. The status of each is as of 2026-11-22.

  1. The pinned model can be overridden without notice.
    • An explicit --model, a user subagents override, or an Auto session model all beat the agent's model (CLI command reference; v1.0.106).
    • A model that can't be resolved falls back to the session model without failing.
    • Mitigation: model-policy: required (documented). Its camelCase/kebab-case spelling is inconsistent across the docs.
  2. #4437, open. A same-named .claude/agents/<name>/AGENT.md with a model: field overrides the .github/agents/<name>.md agent's model. A fix was announced for v1.0.104 but no changelog entry confirms it. This matters if apm deploys an agent to both .claude/agents/ and .github/agents/ under the same ID.
    • Separate point, from the documented precedence: .github/agents/ outranks .claude/agents/, and ~/.copilot/agents/ outranks both. A user-level agent with the same ID silently replaces the repo-deployed one.
  3. #2758, open. A cost-multiplier guard reportedly downgrades a subagent's pinned model to the session model when the session runs on a 0x model. I'm not certain it still applies.
  4. #2950, closed. Its auto-close cites v1.0.91, but no changelog entry confirms the fix. Verify on the installed version that orchestrator-delegated subagents run on their pinned models.
  5. The subagent tool must be in tools. A restricted tools list needs agent (or custom-agent, Task or task) for the orchestrator to delegate. Unrecognized names are silently ignored. Not documented: whether task is among the "default tools" added when strict-tools-list is off.
  6. Subagents don't get AGENTS.md by default. Custom agents spawned as subagents do not receive AGENTS.md, CLAUDE.md or copilot-instructions.md unless they set include-custom-instructions: true. This is documented behaviour, not a bug.
  7. #5124, open. The --agent <name> selection is dropped about 1 second after interactive startup (a race with sign-in or MCP reload), and the session silently falls back to the default agent. Reported on 1.0.95. v1.0.108 has a related fix ("Keep built-in agents selected with --agent active ..."), which covers built-in agents only. I'm not certain it fixes custom agents.
  8. #4752, open. --agent <name> does not find agents that exist only under an --add-dir directory (1.0.83). This doesn't matter for agents in the repo's own .github/agents/.
  9. #5543, open (filed 2026-11-21). Subagents started by other subagents always run synchronously. mode: "background" is silently ignored and write_agent refuses them. This affects multi-level delivery chains.
  10. Subagent limits. Concurrency is plan-capped (Free 2, Pro 4, Business 16, Enterprise 32), and depth defaults to 6 per the docs or 4 per changelog v1.0.71. Both limits are adjustable only on usage-based billing.
  11. Name collisions with built-in agents. An agent that shares a built-in's name is never delegated to (v1.0.106). Avoid task, explore, general-purpose, code-review, research, rubber-duck and security-review as agent IDs or names.
  12. The ask hook is unreliable.
    • #3590 (open): the TUI auto-approves ask since 1.0.53.
    • ask is denied under autopilot and under cloud agent.
    • -p behaviour is not documented.
    • Don't make ask the only safety gate; use deny, or exit code 2, for hard stops.
  13. Hooks fail open on timeout. Command-hook timeouts allow the call, even for preToolUse (documented). Open issue #2893 describes the bypass. A guard hook must be fast and well inside timeoutSec.
  14. Repo hooks may not load in -p. They load only in a trusted folder, with COPILOT_ALLOW_ALL, or with GITHUB_COPILOT_PROMPT_MODE_REPO_HOOKS=true. Since v1.0.111, the CLI warns when -p runs from a subdirectory and skips the root hooks.
  15. #2540, open. Plugin-defined preToolUse hooks reportedly never fire. This is relevant if hooks are shipped through an apm or Copilot plugin instead of .github/hooks/.

Sources