In one sentence
Copilot CLI is Copilot living inside the terminal.
It helps you ask, plan, edit, and execute โ just like Copilot in VS Code. But it has CLI-specific features and harness, so let's explore those together.
Not Copilot used without leaving your IDE, but Copilot that operates within the shellโs working context.
Key Features
A full-stack AI environment packed into a single terminal.
- Multi-file context awareness: Treats the entire repository as a single workspace.
- Code generation & editing: Make edits from the terminal, review diffs, and approve.
- Command execution: Run builds, tests, lint, and more โ read the results and proceed.
- IDE-agnostic: Works anywhere thereโs a terminal: VS Code, Vim, over SSH, etc.
- Skills / MCP support: Add the capabilities and external tools you need.
- Non-interactive execution: Run via CI, cron, or scripts with
copilot -p "...".
CLI vs VS Code Chat
| Copilot CLI | VS Code Chat | |
|---|---|---|
| UI | Very lightweight. Terminal-centric, so thereโs a learning curve for commands and a minimal editor UI. On the other hand, since the CLI opens instantly, itโs easy to work with local computer resources like folders, PowerPoint, and Excel files. | Easier to handle options, settings, file navigation, inline diffs, and the debugger on screen. |
| Speed of new features | New experiments like /chronicle, /fleet, /share, and Rubber Duck tend to land here first. | More stability-oriented. Often adopts good ideas that matured in the CLI. |
| Sub-agents | Has many built-in agents โ Explore, Task, Rubber Duck, Code Review โ and can launch them natively. | Currently limited, but gradually catching up. |
| Session management | Fine-grained session control with /context, /compact, /session, etc. | Improving, but not as granular as the CLI right now. |
| Third-party agents | Copilot CLI runs within Copilotโs harness. Codex / Claude harnesses are not available โ you can use their models, but not their native harnesses. | Inside VS Code, itโs easy to switch between Copilot, Codex, Claude, and other agents / extensions. |
| Index | Primarily uses terminal/search tools like grep, rg, and workspace commands. | Can use richer editor-side indexes like Blackbird. |
Powerful Built-in Agents
Copilot CLI includes standard agents for common tasks.
| Agent | Description |
|---|---|
| Explore | Quickly analyzes the codebase and lets you ask questions about it, without adding it to the main context. |
| Task | Runs commands like tests and builds, returning a short summary on success or the full output on failure. |
| General purpose | Handles complex multi-step tasks that require all tools and advanced reasoning, in a separate context from the main conversation. |
| Code review | Reviews code changes focusing solely on issues that genuinely matter, minimizing noise. |
| Research | Conducts deep research across the codebase, related repositories, and the web, producing detailed reports with citations. |
| Rubber duck | Returns constructive critical feedback for complex tasks. Used automatically by Copilot CLI. |
Rubber Duck โ Cross-model Review
๐ฆ Experimental: A different model family from the main model provides a โsecond opinionโ as a constructive critic, independently reviewing each phase of planning, implementation, and testing.
flowchart LR
User([๐ค Developer])
Main["๐ง Main Model<br/>e.g. Claude"]
Out["๐ Plan / Implementation / Test"]
Duck["๐ฆ Rubber Duck<br/>e.g. GPT-5.4"]
Final([โ
Verified output])
User --> Main
Main --> Out
Out -->|"Independent review"| Duck
Duck -->|"Blind spots / wrong assumptions"| Main
Main --> Final
classDef user fill:#0a1a14,stroke:#9bbc0f,color:#9bbc0f,stroke-width:2px
classDef main fill:#0a0e27,stroke:#00f0ff,color:#00f0ff,stroke-width:2px
classDef duck fill:#1a1500,stroke:#ffb000,color:#ffb000,stroke-width:2px
classDef out fill:#1a0a2e,stroke:#ff2e88,color:#ff2e88,stroke-width:2px
class User,Final user
class Main main
class Duck duck
class Out out
Why does it work? โโ When the same model checks its own output, it gets caught by the same assumptions and the same blind spots. A model from a different family has different training data and different values, so it can catch logic errors that were invisible to the first model.
Other Useful Commands
The CLI lets you instantly check models, sharing, experimental features, and environment info via slash commands.
| Command | When to use |
|---|---|
/help | Check available commands and shortcuts. |
/model | Check or switch the model in use. |
/ide | Connect to an IDE such as VS Code. |
/share | Share the current session. |
/experimental | Check and enable experimental features. |
/chronicle | Review the session history and work log. |
/task | Check agents and tasks running in the background. |
/ask | Consult Copilot as a question before proceeding. |
/env | Check the environment information visible to the CLI. |
Non-interactive Mode (Programmatic Execution) โ
Copilot CLI can be run with a single command without opening an interactive session. Pass a prompt with copilot -p "..." and it executes one turn and exits.
Since it can be called from shell scripts, cron, batch files, and GitHub Actions, you can delegate routine work โ PR auto-review and similar tasks that don't need a human โ to Copilot.
๐ฏ If you find yourself asking the same thing in the interactive UI every day, thatโs a signal to script it. Put it on
cronwith-pand let it run while you sleep.
Basic Usage
# Pass the prompt directly
copilot -p "Explain this file: ./complex.ts"
# Pipe it in
echo "Explain this file: ./complex.ts" | copilot
| Common flags | What they do |
|---|---|
-p "..." / --prompt "..." | Pass a prompt and exit after one turn |
-s (silent) | Suppress metadata and output response text only to stdout (ideal for variable assignment or piping) |
--no-ask-user | Skip clarifying questions; make decisions autonomously when uncertain |
--allow-tool='shell(npm:*), write' | Allow only the necessary tools (this is the default rule; --allow-all is for sandboxes only) |
--allow-url=... | Restrict which URLs are allowed to be fetched |
--model gpt-5.5 | Pin the model to reduce variance in results |
--share='./report.md' | Save the entire session as Markdown |
--share-gist | Upload the session to a Gist (not available for EMU / data residency orgs) |
๐ Minimize permissions. When running in CI, always use
--allow-toolwith a whitelist. Never use--allow-all. ๐ฐ 1 call = 1 Copilot premium request consumed. When making hundreds of batch calls, keep an eye on consumption via Copilot Metrics โ.
Practical Automation Examples
| Use case | Command |
|---|---|
| ๐ Commit message generation | copilot -p 'Write a commit message for the staged changes' -s --allow-tool='shell(git:*)' |
| ๐ Bulk README / JSDoc generation | copilot -p 'Generate JSDoc for all exported fns in src/api/' --allow-tool=write |
| ๐ Bulk lint error fixes | copilot -p 'Fix all ESLint errors' --allow-tool='write, shell(npm:*), shell(npx:*)' |
| ๐งช Write tests for untested modules | copilot -p 'Write unit tests for src/utils/validators.ts' --allow-tool='write, shell(npm:*)' |
| ๐ AI PR review | copilot -p '/review changes vs main. Focus on bugs & security' -s --allow-tool='shell(git:*)' |
| ๐ Dependency vulnerability audit | copilot -p "Audit this project's deps for vulnerabilities" --allow-tool='shell(npm:*)' --share='./audit.md' |
| ๐ฐ Release note generation | copilot -p 'Summarize commits since v1.2.0 as release notes' -s --allow-tool='shell(git:*)' |
| ๐ Document translation | for f in docs/en/*.md; do copilot -p "Translate $f to Japanese, preserve markdown" -s > "docs/ja/$(basename $f)"; done |
Common Shell Script Patterns
Capture into a variable
node_version=$(copilot -p 'What Node.js version does this project require? Number only.' -s)
echo "Required: $node_version"
Use in a conditional
if copilot -p 'Does this project have TypeScript errors? Reply only YES or NO.' -s | grep -qi "no"; then
echo "โ
Clean"
else
echo "โ Type errors detected" && exit 1
fi
Process multiple files sequentially
for file in src/api/*.ts; do
echo "--- Reviewing $file ---" | tee -a review.md
copilot -p "Review $file for error handling issues" -s \
--allow-tool='shell(git:*)' | tee -a review.md
done
Using with GitHub Actions
- name: Generate test coverage report
env:
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_PAT }}
run: |
copilot -p "Run the test suite and produce a coverage summary" \
-s --allow-tool='shell(npm:*), write' --no-ask-user
- ๐ Pass authentication via environment variable. Priority order:
COPILOT_GITHUB_TOKENโGH_TOKENโGITHUB_TOKEN - ๐งพ Use fine-grained PAT (v2) with the โCopilot Requestsโ permission (old
ghp_format is not supported) - ๐ฆ Can be called from cron / Jenkins / GitLab CI the same way (just pass auth via environment variables)
Design Tips
- ๐ฏ Be specific with prompts โ Spell out file names, function names, and expected output format. Specifying the output format (e.g., โNumber only.โ or โReply YES or NO.โ) makes downstream parsing easier.
- ๐ก๏ธ Allow only necessary tools โ Narrow the scope with
--allow-tool='shell(git:*), write' - ๐ Think about idempotency โ When running in Actions, limit to operations that are safe to run multiple times with the same input (have a human review commits/pushes)
- ๐ Keep logs โ Save the entire session with
--share='./session.md'so you can trace the reasoning behind results later - ๐งฉ Build in interactive mode, then port to
-pโ The fastest path is to iterate in interactive mode until the prompt is solid, then script it with-p
๐ Details: