DEV Community

Cover image for GitHub Copilot CLI Commands: A Practical Terminal Guide
Mikael Krief
Mikael Krief

Posted on

GitHub Copilot CLI Commands: A Practical Terminal Guide

GitHub Copilot CLI brings an AI coding agent directly into the terminal, so you can explore repositories, generate code, run tests, review changes, and automate repeatable tasks without leaving the command line. GitHub introduced Copilot CLI in public preview in September 2025 and continues to ship updates rapidly, so use copilot --help and copilot help <topic> as the final source of truth for your installed version.

1. Before You Start

Copilot CLI is a terminal-native AI assistant. It can answer questions about a project, generate full features, debug failures, create tests, and review code from the command line.

Prerequisites

You need:

  • A GitHub account
  • Access to GitHub Copilot
  • A terminal on macOS, Linux, Windows, or WSL
  • Basic familiarity with navigating folders and running Git commands

Verify Your Installation

After installation, verify that the binary is available:

copilot --version
Enter fullscreen mode Exit fullscreen mode

Then inspect the commands supported by your installed version:

copilot --help
copilot help commands
copilot help permissions
Enter fullscreen mode Exit fullscreen mode

This habit matters because Copilot CLI evolves quickly and published tutorials can become outdated.


2. Launching Copilot CLI

The basic command starts an interactive Copilot session in the current folder:

copilot
Enter fullscreen mode Exit fullscreen mode

In interactive mode, Copilot can inspect the repository and will ask for approval before actions such as writing files or executing commands, depending on your permission configuration.

Start in a Specific Folder

Use -C to choose the working directory before Copilot starts:

copilot -C ./my-project
Enter fullscreen mode Exit fullscreen mode

This is useful when you launch Copilot from a parent folder or a terminal shortcut.

Start With a Prompt

Use -i to begin an interactive conversation with an initial task:

copilot -i "Explain the structure of this repository"
Enter fullscreen mode Exit fullscreen mode

Use -p when you want one prompt, one response, and then exit:

copilot -p "Summarize the changes in the latest commit"
Enter fullscreen mode Exit fullscreen mode

The distinction is essential: -i is for people who want to continue the conversation, while -p is for scripts and one-shot automation.

Continue a Previous Session

Resume the most recent session:

copilot --continue
Enter fullscreen mode Exit fullscreen mode

Or resume a specific session:

copilot --resume <session-id>
Enter fullscreen mode Exit fullscreen mode

Sessions preserve the conversation, the working directory, approved tools, and the agent’s accumulated understanding of the codebase.


3. Essential Slash Commands

Once you are inside an interactive session, type / to access slash commands. The following commands provide the most value in daily work.

Command What it does When to use it
/help Displays available commands When you need a quick reminder
/plan Creates an implementation plan before coding Before multi-file changes
/model Lists and switches between available AI models When you need to select a model for a task
/diff Shows changes made in the current directory Before accepting or committing work
/review Runs a code-review agent on changes Before opening a pull request
/security-review Reviews staged and unstaged changes for vulnerabilities Before merging sensitive code
/rewind Reverts file changes from the last turn When the last action was not what you intended
/context Shows context-window usage When Copilot starts losing earlier constraints
/compact Summarizes conversation history to reclaim context During long sessions
/env Shows instructions, agents, MCP servers, skills, hooks, and extensions in effect When behavior is unexpected
/instructions Shows and toggles active instruction files When a rule seems to come from nowhere
/usage Displays session usage metrics To track consumption
/exit Exits Copilot CLI When you are done

The safest workflow is simple: plan, select the right model, implement, inspect the diff, review, then commit manually.

The Six Commands to Memorize

If you only remember six commands, make them these:

/plan
/model
/diff
/review
/rewind
/context
Enter fullscreen mode Exit fullscreen mode

/plan helps you validate the approach before files change. /model lets you select an available model for the task. /diff and /review help you validate the output. /rewind is the fast recovery option for the previous turn, while /context helps diagnose why the agent may have forgotten earlier instructions.


4. Modes: Interactive, Plan, and Autopilot

Copilot CLI supports three main ways of working: interactive, plan, and autopilot.

Interactive Mode

Interactive mode is the default:

copilot
Enter fullscreen mode Exit fullscreen mode

Copilot proposes actions and you remain involved in approvals. This is the best default for normal development work, unfamiliar repositories, or code that affects users.

Plan Mode

Plan mode asks Copilot to produce a step-by-step approach before writing code:

copilot --plan "Add role-based access control to the API"
Enter fullscreen mode Exit fullscreen mode

Or, inside a session:

/plan Add role-based access control to the API
Enter fullscreen mode Exit fullscreen mode

Use this for changes that affect several files, data models, authentication, infrastructure, or public APIs. Reviewing a plan is usually faster and safer than reviewing a large implementation you did not want.

Autopilot Mode

Autopilot lets Copilot proceed without stopping for approval:

copilot --autopilot "Fix all failing tests"
Enter fullscreen mode Exit fullscreen mode

You can also toggle it during an interactive session:

/autopilot
Enter fullscreen mode Exit fullscreen mode

Autopilot can modify files and execute shell commands, so use it only in a controlled environment such as a throwaway branch, a container, or a disposable workspace. You can limit its automatic continuation loop:

copilot --autopilot --max-autopilot-continues 5 "Fix the failing tests"
Enter fullscreen mode Exit fullscreen mode

Autopilot is powerful, but it should not be your default mode in a production repository.


5. Permissions: The Most Important Safety Feature

Permissions determine what Copilot can do to your machine, repository, and network. This matters more than any prompt-writing trick.

There are two independent concepts:

  • Visibility: which tools the model can see
  • Approval: which visible tools can run without asking you

Allow and Deny Specific Tools

Grant a narrow capability:

copilot --allow-tool='shell(git:*)' -i "Explain recent Git history"
Enter fullscreen mode Exit fullscreen mode

Block a dangerous capability:

copilot --deny-tool='shell(git push:*)' -i "Fix the failing tests"
Enter fullscreen mode Exit fullscreen mode

A deny rule wins, even if broader permissions are also enabled. This makes --deny-tool='shell(git push:*)' a useful safeguard when you want Copilot to inspect, test, or commit locally but never publish remotely.

Restrict File Changes and Network Access

Read a repository without allowing writes or web access:

copilot \
  --deny-tool='write' \
  --deny-tool='url' \
  -i "Explain how this project is structured"
Enter fullscreen mode Exit fullscreen mode

Protect environment files:

copilot --deny-tool='write(.env)' -i "Review the configuration setup"
Enter fullscreen mode Exit fullscreen mode

Be precise with paths. A relative rule such as write(.env) matches .env files in any directory, which is ideal for protecting secrets. For an allow rule that targets only one location, use an absolute path.

Avoid Broad Permission Flags

These flags should be treated with caution:

--allow-all-tools
--allow-all-paths
--allow-all-urls
--allow-all
--yolo
Enter fullscreen mode Exit fullscreen mode

--allow-all and --yolo remove confirmation barriers for tools, paths, and URLs. GitHub’s own CLI material warns that broadly granting permissions is not appropriate for a real environment unless it is isolated, such as a container.


6. Useful Command-Line Flags

Choose and Switch Models

Copilot CLI can use the automatically selected default model or an available model you choose explicitly. Use the /model slash command inside an interactive session to view the available options and change your current selection.

/model
Enter fullscreen mode Exit fullscreen mode

In the model picker, select a model appropriate for the task. For example, you may prefer a faster model for quick repository exploration and a more capable model for a complicated refactor, deep debugging session, or security review.

You can also start a session with a model explicitly selected:

copilot --model <model-name> -i "Review this module for reliability and missing tests"
Enter fullscreen mode Exit fullscreen mode

Pinning a model can make output more consistent in automation, while the automatic option lets Copilot choose among models available to your account. Use copilot --help or /model rather than copying model names from a tutorial, because available models depend on your plan, organization policy, and the version of the CLI.

Work With Directories

Give Copilot access to one extra directory instead of your whole file system:

copilot --add-dir ../shared-library -i "Compare our API client with the shared library"
Enter fullscreen mode Exit fullscreen mode

This is a safer alternative to --allow-all-paths.

Control Output for Scripts

Print only the answer:

copilot -s -p "List every TODO comment"
Enter fullscreen mode Exit fullscreen mode

Return structured output for programs:

copilot -p "List every TODO comment with file and line" \
  --output-format json \
  -s
Enter fullscreen mode Exit fullscreen mode

The -s or --silent flag removes session statistics from standard output, while --output-format json provides JSONL output for automation.

Limit Cost and Agent Loops

Set an AI-credit limit for a session:

copilot --max-ai-credits 20 -i "Refactor this module"
Enter fullscreen mode Exit fullscreen mode

Limit autopilot continuation messages:

copilot --max-autopilot-continues 3 --autopilot "Fix the test suite"
Enter fullscreen mode Exit fullscreen mode

These limits are useful guardrails for long agentic sessions, although you should consult copilot help billing and copilot help limits for current behavior in your installed version.


7. Agents, Reviews, and Delegation

Select a Custom Agent

List the available agents:

/agent
Enter fullscreen mode Exit fullscreen mode

You can choose a specialized agent for a task such as planning, Python code review, accessibility validation, or testing. GitHub’s beginner material documents built-in workflows such as /plan, /review, and /init, as well as custom agents stored in .github/agents/ or ~/.copilot/agents/.

Start directly with a named agent:

copilot --agent python-reviewer
Enter fullscreen mode Exit fullscreen mode

Then ask it to review a file or change set:

Review @src/service.py for correctness, readability, and missing tests.
Enter fullscreen mode Exit fullscreen mode

Initialize Repository Instructions

Create repository-level instructions:

/init
Enter fullscreen mode Exit fullscreen mode

Or use the subcommand:

copilot init
Enter fullscreen mode Exit fullscreen mode

This can generate .github/copilot-instructions.md, where you can define code style, test expectations, architectural rules, and security requirements.

Review Code and Security

Run a general review:

/review
Enter fullscreen mode Exit fullscreen mode

Run a security-focused review:

/security-review
Enter fullscreen mode Exit fullscreen mode

Treat both as an additional reviewer, not as a replacement for human judgment. You remain responsible for correctness, security, tests, and the final diff.

Delegate Work to GitHub

Use /delegate to hand a task to a GitHub coding agent in the background:

/delegate Finish fixing issue #1 and add tests to verify the solution
Enter fullscreen mode Exit fullscreen mode

The delegated workflow can create a pull request for the work it performs. This is useful when you have already investigated locally and want to offload a well-scoped remaining task.


8. Sessions and Context Management

A Copilot session contains your conversation history, allowed tools, working directory, and project understanding. Long sessions can be valuable, but they also consume context.

Check Context Usage

/context
Enter fullscreen mode Exit fullscreen mode

If Copilot begins ignoring an earlier constraint, do not immediately assume it is being careless. The context window may be full.

Compact a Long Conversation

/compact
Enter fullscreen mode Exit fullscreen mode

This summarizes earlier conversation history to free context. If you use it, state what must be preserved:

/compact Preserve the API contract, authentication constraints, and test requirements.
Enter fullscreen mode Exit fullscreen mode

Undo the Last Turn

/rewind
Enter fullscreen mode Exit fullscreen mode

/rewind reverts file changes from the last turn. It cannot undo external effects such as a successful push, a deployment, or data written to an external system, so inspect changes before approving high-impact actions.

Inspect the Environment

/env
Enter fullscreen mode Exit fullscreen mode

Use /env when Copilot behaves unexpectedly. It reveals active instructions, agents, MCP servers, skills, hooks, plugins, language servers, and extensions.


9. Automation and Headless Usage

Headless operation lets you use Copilot CLI in scripts or workflows. GitHub provides the -p flag for a non-interactive prompt-and-exit workflow.

A Safe Automation Pattern

copilot -p "Summarize the changes in the latest commit" \
  --allow-tool='shell(git:*)' \
  --no-ask-user \
  -s
Enter fullscreen mode Exit fullscreen mode

This pattern has four parts:

  1. -p runs one prompt and exits
  2. --allow-tool grants only the command family needed
  3. --no-ask-user prevents the job from waiting for a human response
  4. -s keeps output clean for logging or downstream processing

Machine-Readable Example

copilot -p "List every TODO comment with its file and line" \
  --allow-tool='shell(rg:*)' \
  --no-ask-user \
  --output-format json \
  -s
Enter fullscreen mode Exit fullscreen mode

Do Not Copy This Into Production

copilot --allow-all-tools -p "Kill the process using port 3000"
Enter fullscreen mode Exit fullscreen mode

GitHub uses this as a demonstration of headless operation, but also explicitly cautions against using broad permissions in a real environment unless it is isolated. Prefer narrow permissions and a controlled execution environment.


10. Practical Recipes

Understand an Unfamiliar Repository Safely

copilot \
  --deny-tool='write' \
  --deny-tool='url' \
  -i "Explain the architecture of this repository, the entry points, and how data flows through it."
Enter fullscreen mode Exit fullscreen mode

This prevents file changes and network access while allowing repository exploration.

Find and Fix Failing Python Tests Without Pushing

copilot \
  --allow-tool='shell(pytest:*)' \
  --allow-tool='shell(git:*)' \
  --deny-tool='shell(git push:*)' \
  -i "Run the test suite, identify the failures, propose fixes, and explain each change before modifying files."
Enter fullscreen mode Exit fullscreen mode

This lets Copilot run tests and inspect local Git state while explicitly blocking publication to a remote.

Generate a Plan Before Refactoring

copilot --plan "Refactor the authentication module to separate token validation from user lookup. Include affected files, risks, migration steps, and tests."
Enter fullscreen mode Exit fullscreen mode

Use this before broad refactors so you can challenge assumptions before implementation begins.

Select a Model for a Specific Task

Start an interactive session and open the model picker:

copilot -i "Review the authentication module"
Enter fullscreen mode Exit fullscreen mode
/model
Enter fullscreen mode Exit fullscreen mode

Choose an available model, then give it a focused task:

Review the authentication flow for input-validation flaws, authorization bypasses, secret exposure, and missing test cases. Do not edit files yet.
Enter fullscreen mode Exit fullscreen mode

For automated work, explicitly pin an available model with --model <model-name> when consistency is more important than automatic model selection.

Review Your Work Before a Pull Request

/review
Enter fullscreen mode Exit fullscreen mode

Then ask a targeted follow-up:

Focus on error handling, input validation, concurrency problems, and missing test cases.
Enter fullscreen mode Exit fullscreen mode

Protect Secrets During a Review

copilot \
  --deny-tool='write(.env)' \
  --deny-tool='url' \
  -i "Review the configuration code for security issues. Do not modify any files."
Enter fullscreen mode Exit fullscreen mode

This keeps secrets files protected and blocks external network access.


11. Common Mistakes

Mistake 1: Using Autopilot Everywhere

Autopilot can modify files and execute shell commands without pausing. Use interactive or plan mode by default, and reserve autopilot for isolated, reversible tasks.

Mistake 2: Granting All Permissions for Convenience

Avoid --allow-all, --yolo, and --allow-all-tools as routine defaults. Use least privilege: give Copilot only the tools, directories, and URLs required for the specific task.

Mistake 3: Copying Model Names From a Tutorial

Available models can change depending on your Copilot plan, organization policy, region, and installed CLI version. Use /model to view what is available in your session, then choose deliberately.

Mistake 4: Confusing -p and -i

-p is non-interactive and exits after a response; -i begins an interactive session. A script built with -i can hang while waiting for a person to answer.

Mistake 5: Skipping /diff and /review

Copilot can generate plausible but incorrect code. Always inspect the diff, run tests, and apply the same review standards you would apply to a human-authored pull request.

Mistake 6: Forgetting Context Limits

If Copilot stops following an instruction from earlier in the conversation, check /context before repeating yourself. Use /compact to preserve essential constraints while freeing room for the rest of the task.

Further Reading

Top comments (0)