GitHub Copilot CLI Commands Cheat Sheet
Every command and flag on this page was read out of a real installation rather
than transcribed from documentation. copilot --version reported
1.0.80 on 2026-08-23, installed via
npm, and the tables below come from
copilot --help, copilot help <topic> and copilot <subcommand> --help on that
build.
Key takeaways
--allow-tool/--deny-toolcontrol approval.--available-tools/--excluded-toolscontrol visibility. A tool hidden by the second pair cannot be granted by the first.- Denial always wins, including against
--allow-all-tools. - Permission patterns are
kind(argument):shell(git:*),write(.env),url(https://*.github.com),ServerName(tool_name). --yoloand--allow-allare the same flag under two names: all tools, all paths, all URLs.-pexits after one prompt;-istarts an interactive session that begins with one. Only the first is suitable for automation, and it needs explicit permissions because nobody is there to approve.- Run
copilot help permissionson your own install. It is fresher than any article, this one included.
Find a command by what you are trying to do
Reference pages are organised by structure; work is organised by intent. This index maps the second onto the first.
I want to understand a repository I did not write. Start read-only. Deny
write and url, then ask. The explore agent exists for precisely this and
cannot modify anything.
I want the agent to fix something. Allow the test runner and local git, leave
write on prompt so every file change surfaces, deny shell(git push:*).
I want to script this. -p for one prompt and exit, -s for clean output,
--no-ask-user so it cannot stall, and an explicit --allow-tool list.
I want to know why it did that. /diagnose for the session log, /env for
what actually loaded, /context for whether it had room to remember.
I want to undo something. /rewind for the last turn’s file changes; git for
anything older or anything that left the machine.
I want it to stop doing so much. /plan before implementation, or a
mid-session correction naming a specific path boundary.
I want to spend less. /usage to see where it went, --max-ai-credits and
--max-autopilot-continues to bound the next run.
I want to hand this off. /delegate sends the session to GitHub and produces
a pull request.
Launching
| Command | Purpose | Mode | Risk (editorial guidance, not a GitHub classification) |
|---|---|---|---|
copilotRead only | Start an interactive session in the current directory.Reading and writing still require approval at the point the agent asks for it. | interactive | Low |
copilot -p "<prompt>"Read only | Run one prompt non-interactively and exit.Long form is --prompt. Takes precedence over piped stdin. | programmatic | Medium |
copilot -i "<prompt>" | Start interactive mode and run this prompt immediately. | interactive | Low |
copilot -C <directory> | Change working directory before doing anything else. | both | Low |
copilot --continue | Resume the most recent session. | both | Low |
copilot -r, --resume[=value] | Resume a previous session by ID, task ID, ID prefix or name. | both | Low |
copilot --versionRead only | Show the installed version. | both | Low |
The pairing to remember is -p versus -i. -p is non-interactive: one prompt,
one answer, exit. -i opens a normal interactive session that happens to start
with your prompt. Scripts want -p; humans in a hurry want -i.
Permissions
This is the section worth reading properly. Everything else in the CLI is convenience; this is the part that decides what can happen to your machine.
Two independent systems
Visibility decides what the model can see:
--available-tools— a whitelist. Everything not listed is disabled.--excluded-tools— a blacklist. Only the listed tools are disabled.
Approval decides what happens when a visible tool is called:
--allow-tool— run without prompting.--deny-tool— refuse, without prompting.--allow-all-tools— approve everything automatically.
| Command | Purpose | Mode | Risk (editorial guidance, not a GitHub classification) |
|---|---|---|---|
--allow-tool[=tools...]Can modify filesCan execute shell | Permit named tools without prompting for approval.Takes a pattern of the form kind(argument). | both | Medium |
--deny-tool[=tools...] | Refuse named tools outright, with no prompt.Denial always beats allow, including --allow-all-tools. | both | Low |
--available-tools[=tools...] | Make only these tools visible to the model at all.A visibility filter, not an approval rule. Disables everything else. | both | Low |
--excluded-tools[=tools...] | Hide the named tools from the model. | both | Low |
--allow-all-toolsCan modify filesCan execute shell | Approve every tool automatically. Required for non-interactive runs.Environment variable equivalent: COPILOT_ALLOW_ALL. | programmatic | High |
--allow-all-pathsCan modify files | Disable path verification; allow file access anywhere on the filesystem. | both | High |
--allow-url[=urls...] / --deny-url[=urls...]Network access | Permit or refuse specific URLs or domain patterns.Protocol-aware: approving https://example.com does not allow http://. | both | Medium |
--allow-all-urlsNetwork access | Allow network access to any URL without confirmation. | both | High |
--allow-allCan modify filesCan execute shellNetwork access | Enable all tool, path and URL permissions at once.Equivalent to --allow-all-tools --allow-all-paths --allow-all-urls. | both | High |
--yoloCan modify filesCan execute shellNetwork access | Identical to --allow-all. Removes every confirmation prompt.The name is GitHub's, and it is an accurate description of the risk. | both | High |
--add-dir <directory> | Add one directory to the allowed list for file access.The narrow alternative to --allow-all-paths. Repeatable. | both | Medium |
--disallow-temp-dir | Prevent automatic access to the system temporary directory. | both | Low |
--no-ask-user | Disable the ask_user tool so the agent never pauses for a question. | programmatic | Medium |
--secret-env-vars[=vars...] | Strip named environment variables from shell and MCP environments, and redact them from output. | both | Low |
The pattern grammar
Permissions take the form kind(argument), with the argument optional. Four
kinds are documented:
shell(command:*?)
Matches a shell command. Omit the command to allow all shell commands. Use the :* suffix to match a prefix, which is how git and gh subcommands are approved — shell(git:*) matches git push but not gitea.
Example: --allow-tool='shell(git:*)'
write(path?)
Matches tools that create or modify files, excluding shell invocations. A relative path matches by trailing path components, so write(.env) matches a file of that name in any directory; use an absolute path to scope it to one location.
Example: --deny-tool='write(.env)'
<mcp-server-name>(tool-name?)
Matches one tool from a named MCP server, or every tool from that server when the tool name is omitted.
Example: --allow-tool='MyMCP(my_tool)'
url(domain-or-url?)
Matches URL access by the shell and web-fetch tools. Patterns are protocol-aware and default to https:// when no protocol is given.
Example: --allow-tool='url(https://*.github.com)'
Three details in that grammar cause real mistakes:
:* matches on the command stem. shell(git:*) matches git push and does
not match gitea. Approval for git and gh happens per first-level
subcommand, which is what makes shell(git status) expressible separately from
shell(git push).
Relative paths in write() match trailing components. write(.env) matches
a file called .env in any directory, not just the working one. That is
usually what you want for a deny rule and rarely what you want for an allow rule.
Use an absolute path — write(/srv/app/config.yml) — to pin a rule to one place.
URL patterns are protocol-aware. url(https://example.com) does not permit
http://example.com. A pattern with no protocol defaults to https://.
Worked policies
| Pattern | Decision | Why |
|---|---|---|
shell(git log:*) | Allowed | History is read-only. |
shell(git diff:*) | Allowed | As is inspecting changes. |
shell(rg:*) | Allowed | Search across the tree. |
write | Denied | Nothing in this session should modify a file. |
url | Denied | No network. Nothing can be exfiltrated or fetched. |
Written for this lesson to illustrate least privilege. Not a GitHub default and not a security guarantee — read every rule before using it.
| Pattern | Decision | Why |
|---|---|---|
shell(pytest:*) | Allowed | Running tests is the loop. |
shell(git:*) | Allowed | Local git inspection and staging. |
write | Asks first | Each file modification surfaces before it lands. |
shell(git push:*) | Denied | Publishing stays a human action. |
write(.env) | Denied | Secrets file, in any directory. |
Written for this lesson to illustrate least privilege. Not a GitHub default and not a security guarantee — read every rule before using it.
Interactive slash commands
Available inside a running session. The capability badges say what each one can do; the risk column is this curriculum’s judgement, not GitHub’s.
| Command | Purpose | Risk (editorial guidance, not a GitHub classification) |
|---|---|---|
/initCan modify files | Generate .github/copilot-instructions.md for this repository. | Medium |
/agent | Browse and select agents. Accepts a name: /agent [name]. | Low |
/skills | Manage skills. | Low |
/mcp | Manage MCP server configuration. | Medium |
/plugin | Manage plugins and plugin marketplaces. | Medium |
/model | Select the model for this session; 'auto' lets Copilot choose. | Low |
/planRead only | Create an implementation plan before coding. | Low |
/autopilotCan modify filesCan execute shell | Toggle autopilot mode. | High |
/delegate | Send the session to GitHub; Copilot creates a pull request. | Medium |
/fleet | Enable fleet mode for parallel subagent execution. | High |
/tasks | View and manage tasks — subagents and shell commands. | Low |
/diffRead only | Review changes made in the current directory. | Low |
/reviewRead only | Run the code review agent over your changes. | Low |
/security-reviewRead only | Analyse staged and unstaged changes for security vulnerabilities. | Low |
/rubber-duckRead only | Get an independent critique of the current work from the rubber duck agent. | Low |
/pr | Operate on pull requests for the current branch. | Medium |
/permissions | Switch between permission modes. | Medium |
/allow-allCan modify filesCan execute shellNetwork access | Enable all tool, path and URL permissions for the session. | High |
/add-dir | Add a directory to the allowed list for file access. | Medium |
/list-dirsRead only | Display every directory currently allowed for file access. | Low |
/reset-allowed-tools | Clear the list of tools already approved this session. | Low |
/cwd | Change or display the working directory. | Low |
/instructionsRead only | View and toggle the custom instruction files in effect. | Low |
/envRead only | Show loaded instructions, MCP servers, skills, agents, hooks, plugins, LSPs and extensions. | Low |
/contextRead only | Show context window token usage. | Low |
/compact | Summarise conversation history to reclaim context window. | Low |
/rewind | Rewind the last turn and revert its file changes. | Low |
/resume | Switch to a different session by ID, task ID or name. | Low |
/fork | Fork the current session into a new one. | Low |
/new | Start a new conversation. | Low |
/clear | Abandon this session and start fresh. | Low |
/usageRead only | Display session usage metrics. | Low |
/limits | View or edit session limits. The AI credit limit is a soft cap. | Low |
/login | Authenticate with Copilot. | Low |
/logout | Log out of an OAuth login session. | Low |
/session | View and manage sessions. | Low |
/shareNetwork access | Share a session to Markdown, HTML, a gist or a GitHub link. | Medium |
/researchNetwork access | Run a deep research investigation using GitHub search and web sources. | Low |
/ask | Ask a side question without adding it to conversation history. | Low |
/exit | Exit the CLI. | Low |
The five worth memorising
Out of that list, five carry most of the day-to-day value:
/env shows what the session actually loaded — instructions, MCP servers,
skills, agents, hooks, plugins, LSPs, extensions. When behaviour is inexplicable,
this is the first command to run, because the cause is usually a configuration
file you forgot existed.
/instructions narrows that to instruction files specifically, and lets you
toggle them. Useful when a rule is being applied that you did not write.
/context shows token usage. An agent that has started ignoring earlier
constraints is often simply out of room.
/rewind reverts the last turn and its file changes. Narrow, but exactly
right for “that was not what I meant”, and worth reaching for before you start
manually undoing edits.
/review runs the code review agent over your changes. Covered properly in
the code review lesson.
Subcommands
| Command | Purpose | Risk (editorial guidance, not a GitHub classification) |
|---|---|---|
copilot initCan modify files | Analyse the codebase with read-only tools and write .github/copilot-instructions.md. | Medium |
copilot login | Authenticate via OAuth browser flow, or device code on headless hosts. | Low |
copilot mcp | Manage MCP servers. Subcommands include add and get. | Medium |
copilot plugin | Manage plugins and plugin marketplaces. | Medium |
copilot skill | Add, list and remove skills. | Medium |
copilot update [channel] | Download the latest release. Channels: stable, prerelease. | Low |
copilot completion <shell> | Generate a shell completion script. | Low |
copilot help [topic]Read only | Display help. Topics include permissions, sandbox, config, environment, limits, billing, providers, logging, monitoring, commands. | Low |
copilot help <topic> is the most valuable of these and the least used. The
topics are permissions, sandbox, config, environment, limits, billing,
providers, logging, monitoring and commands. They describe the binary you
have installed, which — given how fast this tool ships — is frequently ahead of
published documentation.
Scripting and automation flags
| Command | Purpose | Mode | Risk (editorial guidance, not a GitHub classification) |
|---|---|---|---|
-s, --silent | Print only the agent response, with no session statistics. | programmatic | Low |
--output-format <format> | Output as text (default) or json — JSONL, one object per line. | programmatic | Low |
--model <model> | Pin the model, or 'auto' to let Copilot choose. | both | Low |
--agent <agent> | Run with a named custom agent. | both | Low |
--mode <mode> | Set the initial agent mode: interactive, plan or autopilot. | both | Medium |
--plan | Start in plan mode. Combined with --mode autopilot it auto-approves the plan. | both | Medium |
--autopilotCan modify filesCan execute shell | Start in autopilot mode. | both | High |
--max-autopilot-continues <count> | Cap continuation messages in autopilot mode. Default 5. | both | Low |
--max-ai-credits <credits> | Set a maximum AI credit spend for the session. | both | Low |
--share[=path]Can modify files | Write the session to a Markdown file after a non-interactive run. | programmatic | Low |
--share-gistNetwork access | Publish the session to a secret GitHub gist after a non-interactive run. | programmatic | Medium |
--log-level <level> | Set log verbosity: none, error, warning, info, debug, all, default. | both | Low |
--log-dir <directory> | Set the log file directory. Defaults to ~/.copilot/logs/. | both | Low |
--context <tier> | Set the context window tier: default or long_context. | both | Low |
--no-custom-instructions | Stop loading custom instructions from AGENTS.md and related files. | both | Low |
--no-auto-update | Do not download updates automatically. Already the default in CI. | both | Low |
--experimental | Enable experimental features, including the /sandbox command. | both | Medium |
A non-interactive invocation that behaves predictably usually needs three things beyond the prompt:
copilot -p "Summarise the changes in the last commit" \
--allow-tool='shell(git:*)' \
--no-ask-user \
-s--allow-tool grants exactly what the task requires. --no-ask-user disables the
tool the agent uses to ask a clarifying question — without it, a run can stall
waiting for an answer nobody will give. -s suppresses session statistics so
stdout is just the response.
Add --output-format json when a program rather than a person reads the output;
it emits JSONL, one object per line.
Modes
Three modes, selectable with --mode or toggled in session:
Interactive is the default. The agent proposes; you approve.
Plan (--plan, /plan) produces an implementation plan before writing code.
For anything spanning several files, reading a plan is cheaper than reviewing an
implementation you disagree with.
Autopilot (--autopilot, /autopilot) proceeds without stopping for
approval. --max-autopilot-continues bounds how many times it continues on its
own, defaulting to 5.
Combining them is documented: --plan --mode autopilot auto-approves the plan and
implements it autonomously. That is a genuinely useful combination in a
throwaway environment and a poor one on a working checkout.
Sandboxing
Sandboxing runs shell commands inside an OS-level sandbox with restricted
filesystem and network access. It is experimental and disabled by default,
and the /sandbox command only exists when experimental features are enabled —
otherwise it returns “Unknown command”.
Enable experimental features with --experimental. Host support: macOS via
Seatbelt (sandbox-exec), Linux via bubblewrap (needs bwrap 0.5.0+ on PATH),
Windows via a process container targeting Windows 11.
Reading the capability badges
Each row in the tables above carries capability labels rather than a colour code, because the distinction they draw is the one that decides whether a command can hurt you.
Read only means the command inspects and reports. /diff, /list-dirs,
/context and /usage sit here. They are safe to approve without much thought,
and pre-approving them is how you buy back attention for the commands that need
it.
Can modify files means the command creates or changes something on disk.
/init writes .github/copilot-instructions.md; --share writes a transcript.
Neither is dangerous, but both put a file somewhere you will later have to
explain in a diff.
Can execute shell is the label that matters. A command with this capability
can run anything your account can run, because — with sandboxing off, which is the
default — there is no reduced privilege set. /autopilot carries it because it
proceeds without asking.
Network access covers commands that reach outside the machine. /share,
/research and the URL-permitting flags sit here. These are the effects
/rewind cannot reverse.
A command with no badge is one whose effect depends entirely on what you ask it to do, which is most of the interesting ones.
Sessions, context and history
A session is the unit that holds your conversation, the tools you have already approved, the working directory, and whatever the agent has worked out about your repository. Rebuilding that costs time, so the session commands matter more than their placement in a help listing suggests.
--continue picks up the most recent session. -r or --resume accepts a
session ID, a task ID, an ID prefix, or a name — name matching is exact and
case-insensitive, which is an argument for naming sessions with -n at launch or
/rename once a conversation has found its shape. /session lists what exists
and manages it.
/fork splits the current session in two. The value is not obvious until the
first time you have spent twenty turns establishing context and want to try two
approaches from it: forking preserves that investment for both attempts instead
of forcing you to choose.
/compact summarises conversation history to reclaim context window, and takes
focus instructions so you can say what the summary must preserve. /context
shows current usage, and --context selects a tier at launch — default or
long_context.
The practical sequence is worth stating: when an agent begins ignoring an
instruction it previously followed, check /context first. Context exhaustion
looks exactly like disobedience, and rewriting the instruction does not fix it.
/rewind reverts the last turn and the file changes it made. It is the right
reflex when the agent has just done something unintended, and it is narrow —
it does not reach back many turns, and it cannot undo an effect that left your
machine. A push that succeeded stays pushed.
Talking to GitHub
Because the CLI holds a GitHub session, several commands reach past your working directory.
/pr operates on pull requests for the current branch. /delegate hands the
session to GitHub, where the coding agent continues and opens a pull request;
--base selects the target branch. That combination — start locally where you can
steer, delegate once the remaining work is mechanical — is one of the genuinely
new workflows this tool enables.
/share exports a session to a Markdown file, an HTML file, a gist, or a
shareable GitHub link. In non-interactive runs the same job is done by
--share[=path] and --share-gist.
A GitHub MCP server is built in, with a default subset of tools enabled.
--add-github-mcp-tool and --add-github-mcp-toolset extend that selectively;
--enable-all-github-mcp-tools opens the full set and overrides the narrower
flags. --disable-builtin-mcps turns the built-in servers off entirely.
Cost and limits
Agentic sessions consume AI credits, and an autonomous run consumes them while you are not watching. Four controls exist.
/usage reports session metrics and statistics. /limits opens the limits
dialog, or sets one directly — /limits set max-ai-credits <credits>.
--max-ai-credits does the same at launch. --max-autopilot-continues caps how
many continuation messages autopilot will send itself, defaulting to 5.
GitHub describes the AI credit limit as a soft cap. Read that word carefully:
it is a guardrail against a loop that has gone wrong, not a billing guarantee.
Session limits apply across the current conversation, and /clear or /new
resets used credits while keeping the configured limit until you unset it.
copilot help billing and copilot help limits carry the current detail.
Logging and diagnosis
Logs land in ~/.copilot/logs/ unless --log-dir says otherwise. --log-level
takes none, error, warning, info, debug, all or default.
/diagnose analyses the current session log and accepts a custom prompt, which
makes it the quickest answer to “why did it decide to do that”. For fleet-scale or
long-running use, copilot help monitoring documents OpenTelemetry support.
Recipes
A handful of invocations that cover most real use.
Read a repository without any risk of changing it. The strongest version of this is denial rather than restraint, because a denied tool cannot be approved by a tired human:
copilot --deny-tool='write' --deny-tool='url' -i "Explain how this project is structured"Run the test suite and fix what fails, without publishing.
copilot --allow-tool='shell(pytest:*)' --allow-tool='shell(git:*)' --deny-tool='shell(git push:*)' -i "Find and fix the failing tests"Get a machine-readable answer for a script.
copilot -p "List every TODO comment with its file and line" --allow-tool='shell(rg:*)' --no-ask-user -s --output-format jsonGive the agent one extra directory rather than the whole filesystem.
copilot --add-dir ../shared-library -i "Compare our API client with the shared one"Pin behaviour for a run you intend to repeat. Auto-update means today’s invocation may not behave like tomorrow’s, so a repeatable job should pin the model and decline updates:
copilot --no-auto-update --model <model> -p "..." --allow-tool='shell(git:*)' -sWhere configuration comes from
The CLI discovers configuration from several locations. Knowing which is which saves a lot of confusion when behaviour does not match the file you just edited.
| Kind | Locations |
|---|---|
| Repository instructions | .github/copilot-instructions.md |
| Path-specific instructions | .github/instructions/NAME.instructions.md |
| Agent instructions | AGENTS.md (nearest in tree wins), CLAUDE.md, GEMINI.md |
| Custom agents | .github/agents/NAME.agent.md, ~/.copilot/agents/ |
| Skills | .github/skills/, .agents/skills/, .claude/skills/, ~/.copilot/skills/, ~/.agents/skills/ |
| MCP servers | ~/.copilot/mcp-config.json, .mcp.json, .github/mcp.json |
| Hooks | .github/hooks/*.json, plus hooks in config or settings |
| Logs | ~/.copilot/logs/ |
--no-custom-instructions disables instruction loading entirely.
disableAllHooks disables every hook, repository and user level alike.
Instruction precedence, per GitHub’s documentation: personal instructions rank highest, then repository, then organisation — but all relevant sets are provided to Copilot rather than one replacing another. The custom instructions lesson works through what that means in practice.
Flags that look similar and are not
Four pairs account for most of the mistakes people make with this surface.
--allow-tool and --allow-all-tools. One grants named tools; the other
grants everything. They are eleven characters apart and a world apart in effect.
Shell completion helps here more than care does.
--allow-tool and --available-tools. Approval versus visibility. A tool
excluded from --available-tools cannot be re-granted with --allow-tool,
because the model never sees it. If a permission rule appears to be ignored, this
is the first thing to check.
-p and -i. Both take a prompt. -p runs it and exits; -i starts an
interactive session with it. A script written with -i will hang waiting for a
human.
--plan and --mode plan. Equivalent for starting in plan mode, but --mode
also accepts autopilot, and the documented combination --plan --mode autopilot
auto-approves the plan and implements it. Reading that as “plan mode, therefore
safe” is a mistake — the combination is the least supervised configuration
available.
Environment variables
Several behaviours are configurable from the environment, which matters most in CI where flags are awkward to thread through.
COPILOT_GITHUB_TOKEN, GH_TOKEN and GITHUB_TOKEN supply authentication, in
that order of precedence. COPILOT_ALLOW_ALL is the environment equivalent of
--allow-all-tools. COPILOT_DISABLE_TERMINAL_TITLE suppresses the terminal
title updates.
copilot help environment documents the full set on your installation, and is
worth reading once — the environment surface is easier to miss than the flag
surface and is what most CI configuration actually uses.
A note on keeping this current
Copilot CLI ships frequently, and a cheat sheet is exactly the kind of page that rots quietly. Two habits make it survivable.
Record the version any instructions were written against — this page names
1.0.80 at the top for that reason. And when something does not
match, check copilot --version and /changelog before assuming the
documentation is wrong; /changelog summarize produces an AI summary of what
moved between versions.
Printing this
This page is set up for printing, and a printed cheat sheet beside a keyboard is a reasonable way to learn a large flag surface.
If you do print it, write the version at the top by hand. This page names 1.0.80 because a reference that does not say what it describes is a reference that will quietly mislead someone in six months — and a printed copy has no way of telling you it has gone stale.
Next
The beginner tutorial puts these commands into a working sequence. The pillar explains the model the permission flags implement. For applying them to real work, the DevOps lesson builds least-privilege policies for infrastructure tools, and the GitHub Actions lesson does the same for CI.
Sources
Every version-sensitive claim on this page was checked against first-party documentation. Only sources actually used are listed.
Your progress
Saved in this browser only. No account, no server, and nothing leaves your device. Clearing site data resets it.Sync across devices if you want it everywhere.
Saved in this browser and synced to your account, so it follows you between devices. Manage or delete it.
Was this lesson helpful?
We record which lesson you rated and whether it helped. Nothing identifies you — no account, no cookie, no session.