How do you run Copilot CLI from a script?
Why B is the answer
Use -p or --prompt, with an approval option if it must change files
Programmatic use needs -p or --prompt. To let Copilot modify and execute files, you also pass one of the approval options.
In detail
- -p or --prompt runs one prompt from a script.
- An approval option is needed if it must change files.
- Approve only the tools the script needs.
Use case
An illustrative scenario, not a real incident.
A nightly script needs a summary of the changelog. It runs Copilot CLI with -p. A second script that edits files also passes an approval option.
See it in different ways
flowchart TD A["copilot"] --> B["Interactive session"] B --> C["Ask and execute mode"] B --> D["Plan mode"] E["copilot -p"] --> F["Programmatic run"]
mindmap
root((Copilot))
Editor
Inline suggestions
Chat
Agent mode
GitHub
Cloud agent
Code review
Spaces
Terminal
Copilot CLI
Plan modeflowchart TD
Q{"Must it change files?"}
Q -->|"No"| A0["Use -p"]
Q -->|"Yes"| A1["Use -p with an approval option"]Key point: Scripts use -p or --prompt.
Why the other options are wrong
- A. Call the plan mode shortcut from a shell command in your CI workflow
- Plan mode is interactive, and not how a script runs Copilot.
- C. Start the interactive session and pipe keystrokes into the terminal
- Piping keystrokes into an interactive session is fragile.
- D. Open the editor from the script and paste your prompt into Copilot Chat
- A script cannot rely on an editor and pasted text.

