LV.1
EXP 0/1000
โ—€ Playbook index
NO.14

๐Ÿ’ป Copilot CLI

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 CLIVS Code Chat
UIVery 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 featuresNew 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-agentsHas many built-in agents โ€” Explore, Task, Rubber Duck, Code Review โ€” and can launch them natively.Currently limited, but gradually catching up.
Session managementFine-grained session control with /context, /compact, /session, etc.Improving, but not as granular as the CLI right now.
Third-party agentsCopilot 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.
IndexPrimarily 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.

AgentDescription
ExploreQuickly analyzes the codebase and lets you ask questions about it, without adding it to the main context.
TaskRuns commands like tests and builds, returning a short summary on success or the full output on failure.
General purposeHandles complex multi-step tasks that require all tools and advanced reasoning, in a separate context from the main conversation.
Code reviewReviews code changes focusing solely on issues that genuinely matter, minimizing noise.
ResearchConducts deep research across the codebase, related repositories, and the web, producing detailed reports with citations.
Rubber duckReturns 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.

CommandWhen to use
/helpCheck available commands and shortcuts.
/modelCheck or switch the model in use.
/ideConnect to an IDE such as VS Code.
/shareShare the current session.
/experimentalCheck and enable experimental features.
/chronicleReview the session history and work log.
/taskCheck agents and tasks running in the background.
/askConsult Copilot as a question before proceeding.
/envCheck 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 cron with -p and 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 flagsWhat 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-userSkip 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.5Pin the model to reduce variance in results
--share='./report.md'Save the entire session as Markdown
--share-gistUpload the session to a Gist (not available for EMU / data residency orgs)

๐Ÿ”’ Minimize permissions. When running in CI, always use --allow-tool with 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 caseCommand
๐Ÿ“ Commit message generationcopilot -p 'Write a commit message for the staged changes' -s --allow-tool='shell(git:*)'
๐Ÿ“š Bulk README / JSDoc generationcopilot -p 'Generate JSDoc for all exported fns in src/api/' --allow-tool=write
๐Ÿ› Bulk lint error fixescopilot -p 'Fix all ESLint errors' --allow-tool='write, shell(npm:*), shell(npx:*)'
๐Ÿงช Write tests for untested modulescopilot -p 'Write unit tests for src/utils/validators.ts' --allow-tool='write, shell(npm:*)'
๐Ÿ” AI PR reviewcopilot -p '/review changes vs main. Focus on bugs & security' -s --allow-tool='shell(git:*)'
๐Ÿ” Dependency vulnerability auditcopilot -p "Audit this project's deps for vulnerabilities" --allow-tool='shell(npm:*)' --share='./audit.md'
๐Ÿ“ฐ Release note generationcopilot -p 'Summarize commits since v1.2.0 as release notes' -s --allow-tool='shell(git:*)'
๐ŸŒ Document translationfor 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: