--- title: Using GitHub Copilot CLI shortTitle: Overview intro: Learn how to use {% data variables.product.prodname_copilot %} from the command line. product: '{% data reusables.gated-features.copilot-cli %}' redirect_from: - /copilot/how-tos/use-copilot-cli - /copilot/how-tos/use-copilot-agents/use-copilot-cli versions: feature: copilot contentType: how-tos category: - Author and optimize with Copilot - Build with Copilot CLI docsTeamMetrics: - copilot-cli --- The command-line interface (CLI) for {% data variables.product.prodname_copilot %} allows you to use {% data variables.product.prodname_copilot_short %} directly from your terminal. For more information, see [AUTOTITLE](/copilot/concepts/copilot-surfaces/copilot-cli). ## Prerequisite Install {% data variables.copilot.copilot_cli_short %}. See [AUTOTITLE](/copilot/how-tos/copilot-cli/set-up-copilot-cli/install-copilot-cli). ## Using {% data variables.copilot.copilot_cli_short %} 1. In your terminal, navigate to a folder that contains code you want to work with. 1. Enter `copilot` to start {% data variables.copilot.copilot_cli_short %}. {% data variables.product.prodname_copilot_short %} will ask you to confirm that you trust the files in this folder. > [!IMPORTANT] > During this {% data variables.copilot.copilot_cli %} session, {% data variables.product.prodname_copilot_short %} may attempt to read, modify, and execute files in and below this folder. You should only proceed if you trust the files in this location. For more information about trusted directories, see [AUTOTITLE](/copilot/concepts/copilot-surfaces/copilot-cli#trusted-directories). 1. Choose one of the options: **1. Yes**: {% data variables.product.prodname_copilot_short %} can work with the files in this location for this session only. **2. Yes, and remember this folder for future sessions**: You trust the files in this folder for this and future sessions. You won't be asked again when you start {% data variables.copilot.copilot_cli_short %} from this folder. Only choose this option if you are sure that it will always be safe for {% data variables.product.prodname_copilot_short %} to work with files in this location. **3. No (Esc)**: End your {% data variables.copilot.copilot_cli_short %} session. 1. If you are not currently logged in to {% data variables.product.github %}, you'll be prompted to use the `/login` slash command. Enter this command and follow the on-screen instructions to authenticate. 1. Enter a prompt in the CLI. This can be a simple chat question, or a request for {% data variables.product.prodname_copilot_short %} to perform a specific task, such as fixing a bug, adding a feature to an existing application, or creating a new application. As an alternative to typing, you can speak your prompt. See [AUTOTITLE](/copilot/how-tos/copilot-cli/use-copilot-cli/voice-input). For some examples of prompts, see [AUTOTITLE](/copilot/concepts/copilot-surfaces/copilot-cli). 1. Review any permission prompts that {% data variables.product.prodname_copilot_short %} displays. Tools that modify or execute files—{% data reusables.cli.tools-needing-approval %}—can require approval, depending on your existing permissions and permission mode. Choose one of the options: **1. Yes**: Allow {% data variables.product.prodname_copilot_short %} to use this tool. The next time {% data variables.product.prodname_copilot_short %} wants to use this tool, it will ask you to approve it again. **2. Allow the tool for this location or session**: The wording and scope depend on the request. An option that says "don't ask again" in this repository or directory saves the approval for that location, including future sessions. An option that says "for the rest of the running session" applies only to the current session. Saving an approval is useful for many tools—such as `chmod`—as it avoids you having to approve similar commands repeatedly. However, be aware of the security implications of this option. For example, saving an approval for the command `rm` would allow {% data variables.product.prodname_copilot_short %} to delete any file in the current directory or its subdirectories without asking for your approval. **3. No, and tell Copilot what to do differently (Esc)**: {% data variables.product.prodname_copilot_short %} will not run the command. Instead, it ends the current operation and awaits your next prompt. You can tell {% data variables.product.prodname_copilot_short %} to continue the task but using a different approach. For example, if you ask {% data variables.product.prodname_copilot_short %} to create a bash script but you do not want to use the script {% data variables.product.prodname_copilot_short %} suggests, you can stop the current operation and enter a new prompt, such as: `Continue the previous task but include usage instructions in the script`. When you reject a tool permission request, you can also give {% data variables.product.prodname_copilot_short %} inline feedback about the rejection so it can adapt its approach without stopping entirely. ## Tips Optimize your experience with {% data variables.copilot.copilot_cli_short %} with the following tips. ### Stop a currently running operation If you enter a prompt and then decide you want to stop {% data variables.product.prodname_copilot_short %} from completing the task while it is still "Thinking," press Esc twice within half a second. ### Use plan mode Plan mode lets you collaborate with {% data variables.product.prodname_copilot_short %} on an implementation plan before any code is written. Press Shift+Tab to cycle in and out of plan mode. ### Include a specific file in your prompt To add a specific file to your prompt, use `@` followed by the relative path to the file. For example: `Explain @config/ci/ci-required-checks.yml` or `Fix the bug in @src/app.js`. This adds the contents of the file to your prompt as context for {% data variables.product.prodname_copilot_short %}. When you start typing a file path, the matching paths are displayed below the prompt box. Use the arrow keys to select a path and press Tab to complete the path in your prompt. ### Attach images and PDFs You can attach images and PDFs to your prompts when using a model that supports image input. {% data reusables.copilot.supported-attachment-file-types %} {% data reusables.copilot.image-pdf-attachment-handling %} You can attach a file in the following ways during an interactive session: * Reference the file in your prompt using `@` followed by the path to the file. * Drag and drop a file into the interactive session. * Copy an image to your clipboard, then paste it as an attachment. ### Work with files in a different location To complete a task, {% data variables.product.prodname_copilot_short %} may need to work with files that are outside the current working directory. If a prompt you have entered in an interactive session requires {% data variables.product.prodname_copilot_short %} to modify a file outside the current location, it will ask you to approve access to the file's directory. You can also add a trusted directory manually at any time by using the slash command: ```shell /add-dir /path/to/directory ``` If all of the files you want to work with are in a different location, you can switch the current working directory without starting a new {% data variables.copilot.copilot_cli_short %} session by using either the `/cwd` or `/cd` slash commands: ```shell /cwd /path/to/directory ``` ### Run shell commands You can prepend your input with `!` to directly run shell commands, without making a call to the model. ```shell !git clone https://github.com/github/copilot-cli ``` ### Schedule prompts to run later You can schedule prompts to run in the future using the `/every` and `/after` slash commands. The `/every` command schedules a prompt to run repeatedly, while the `/after` command schedules a one-shot prompt to run once after a specified delay. For example: ```shell /every 1h Run frontend tests and report any failures ``` For more information, see [AUTOTITLE](/copilot/how-tos/copilot-cli/automate-copilot-cli/schedule-prompts). ### Resume an interactive session You can use the `--resume` command-line option or the `/resume` slash command to select and resume an interactive CLI session, allowing you to pick up right where you left off, with the saved context. You can kick off a {% data variables.copilot.copilot_cloud_agent %} session on {% data variables.product.github %}, and then use {% data variables.copilot.copilot_cli %} to bring that session to your local environment. > [!TIP] > To quickly resume your most recent local session, preferring one from the current repository or directory, enter this in your terminal: > > ```shell > copilot --continue > ``` ### Use custom instructions You can enhance {% data variables.product.prodname_copilot_short %}’s performance, by adding custom instructions to the repository you are working in. Custom instructions are natural language descriptions saved in Markdown files in the repository. They are automatically included in prompts you enter while working in that repository. This helps {% data variables.product.prodname_copilot_short %} to better understand the context of your project and how to respond to your prompts. {% data variables.copilot.copilot_cli_short %} supports: * Repository-wide instructions in the `.github/copilot-instructions.md` file. * Path-specific instructions files: `.github/instructions/**/*.instructions.md`. * Agent files such as `AGENTS.md`. For more information, see [AUTOTITLE](/copilot/how-tos/copilot-cli/customize-copilot/add-custom-instructions). ### Use {% data variables.copilot.custom_agents_short %} A {% data variables.copilot.copilot_custom_agent_short %} is a specialized version of {% data variables.product.prodname_copilot_short %}. {% data variables.copilot.custom_agents_caps_short %} help {% data variables.product.prodname_copilot_short %} handle unique workflows, particular coding conventions, and specialist use cases. {% data variables.copilot.copilot_cli_short %} includes a default group of {% data variables.copilot.custom_agents_short %} for common tasks:
Agent Description
Explore Performs quick codebase analysis, allowing you to ask questions about your code without adding to your main context.
Task Executes commands such as tests and builds, providing brief summaries on success and full output on failure.
General purpose Handles complex, multi-step tasks that require the full toolset and high-quality reasoning, running in a separate context to keep your main conversation clearly focused.
Code review Reviews changes with a focus on surfacing only genuine issues, minimizing noise.
Research Performs deep research across your codebase, relevant repositories, and the web, producing a detailed report with citations.
Rubber duck Acts as a constructive critic to provide feedback on some non-trivial tasks. Used automatically by {% data variables.copilot.copilot_cli_short %}.
The AI model being used by the CLI can choose to delegate a task to a subsidiary subagent process, that operates using a {% data variables.copilot.copilot_custom_agent_short %} with specific expertise, if it judges that this would result in the work being completed more effectively. The model may equally choose to handle the work directly in the main agent. Some built-in {% data variables.copilot.custom_agents_short %}, such as the rubber duck agent, are consulted automatically by {% data variables.product.prodname_copilot_short %} on your behalf rather than invoked by you directly. You won't see them as separate options when you run `/agent`, but you may see {% data variables.product.prodname_copilot_short %} mention them as it works through a task. You can define your own {% data variables.copilot.custom_agents_short %} using Markdown files, called {% data variables.copilot.agent_profiles %}, that specify what expertise the agent should have, what tools it can use, and any specific instructions for how it should respond. You can define {% data variables.copilot.custom_agents_short %} at the user, repository, or organization/enterprise level: | Type | Location | Scope | | --- | --- | --- | | User-level {% data variables.copilot.copilot_custom_agent_short %} | local `~/.copilot/agents` directory | All projects | | Repository-level {% data variables.copilot.copilot_custom_agent_short %} | `.github/agents` directory in your local and remote repositories | Current project | | Organization and Enterprise-level {% data variables.copilot.copilot_custom_agent_short %} | `/agents` directory in the `.github-private` repository in an organization or enterprise | All projects under your organization and enterprise account | In the case of naming conflicts, a system-level agent overrides a repository-level agent, and the repository-level agent would override an organization-level agent. {% data variables.copilot.custom_agents_caps_short %} can be used in three ways: * Using the slash command in the CLI's interactive interface to select from the list of available {% data variables.copilot.custom_agents_short %}: ```shell /agent ``` * Calling out to {% data variables.copilot.copilot_custom_agent_short %} directly in a prompt: ```shell Use the refactoring agent to refactor this code block ``` {% data variables.product.prodname_copilot_short %} will automatically infer the agent you want to use. * Specifying the {% data variables.copilot.copilot_custom_agent_short %} you want to use with the command-line option. For example: ```shell copilot --agent=refactor-agent --prompt "Refactor this code block" ``` For more information, see [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/create-custom-agents). ### Use skills You can create skills to enhance the ability of {% data variables.product.prodname_copilot_short %} to perform specialized tasks with instructions, scripts, and resources. For more information, see [AUTOTITLE](/copilot/how-tos/copilot-cli/customize-copilot/add-skills). ### Use hooks You can use hooks to extend and customize the behavior of {% data variables.copilot.copilot_cli_short %}. Hooks allow you to run custom shell commands automatically at key points during a CLI session. For more information, see [AUTOTITLE](/copilot/how-tos/copilot-cli/customize-copilot/use-hooks). ### Add an MCP server {% data variables.copilot.copilot_cli_short %} comes with the {% data variables.product.github %} MCP server already configured. This MCP server allows you to interact with resources on {% data variables.product.prodname_dotcom_the_website %}—for example, allowing you to merge pull requests from the CLI. To extend the functionality available to you in {% data variables.copilot.copilot_cli_short %}, you can add more MCP servers. To add a remote HTTP server directly from your terminal without starting an interactive session, use: ```shell copy copilot mcp add --transport http SERVER-NAME URL ``` For example: ```shell copy copilot mcp add --transport http sentry https://mcp.sentry.dev/mcp ``` For local servers and additional options, see [AUTOTITLE](/copilot/how-tos/copilot-cli/customize-copilot/add-mcp-servers#using-the-copilot-mcp-add-subcommand). Alternatively, add a server from an interactive session: 1. Use the following slash command: ```shell /mcp add ``` 1. Fill in the details for the MCP server you want to add, using the Tab key to move between fields. 1. Press Ctrl+S to save the details. Details of your configured MCP servers are stored in the `mcp-config.json` file, which is located, by default, in the `~/.copilot` directory. This location can be changed by setting the `COPILOT_HOME` environment variable. For information about the JSON structure of a server definition, see [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/configure-mcp-servers#writing-a-json-configuration-for-mcp-servers). ### Context management {% data variables.copilot.copilot_cli_short %} provides several slash commands to help you monitor and manage your context window: * `/usage`: Lets you view your session statistics, including: * The amount of {% data variables.product.prodname_ai_credits %} used in the current session * The session duration * The total lines of code edited * A breakdown of token usage per model * `/context`: Provides a visual overview of your current token usage * `/compact`: Manually compresses your conversation history to free up context space {% data variables.copilot.copilot_cli %} automatically starts compressing your history in the background when your conversation approaches 80% of the token limit. This starting point is dynamic: when static context—your system messages and tool definitions—already uses a large share of the limit (roughly 75% or more), {% data variables.product.prodname_copilot_short %} waits until usage is closer to 90% before compacting, because compressing the conversation reclaims less space in that situation. If usage reaches approximately 95% before background compaction has finished, the CLI waits for it to complete before continuing. ### Enable {% data variables.copilot.assisted_permissions %} {% data variables.copilot.assisted_permissions_caps %} reduces approval prompts without granting blanket permissions. A large language model assesses eligible permission requests and automatically approves those it judges to be safe. Existing permissions and enterprise rules still apply, and requests that still need your approval are put to you. To turn it on during an interactive session, enter `/permissions assisted`. For more information, see [AUTOTITLE](/copilot/concepts/customizations/allowing-safe-commands). > [!NOTE] > To grant broad permissions without a model safety review, use the `--allow-all` or `--yolo` command line options (or the `/permissions allow-all` or `/yolo` slash commands within an interactive session). These options can allow destructive commands to run without individual approval, so only use them in a sandboxed or otherwise isolated environment. Deny rules and enterprise restrictions still apply. ### Use sandboxing You can use sandboxing to restrict what {% data variables.product.prodname_copilot_short %} can access. Local sandboxing does not run the CLI itself in a sandbox; instead, the commands and tools that {% data variables.copilot.copilot_cli_short %} runs on your behalf are restricted, limiting their access to your filesystem, network, and system capabilities. To enable local sandboxing, enter `/sandbox enable` inside a session. Alternatively, you can run the entire {% data variables.copilot.copilot_cli_short %} session in a cloud sandbox. To start a {% data variables.copilot.copilot_cli_short %} session in a cloud sandbox, run `copilot --cloud`. For more information, see [AUTOTITLE](/copilot/concepts/security-governance-and-network-settings/about-cloud-sandboxes). ### Toggle model thinking visibility Press Ctrl+T to show or hide the model's thoughts as it works on a task. This expands/collapses text in the model output in the conversation in your interactive session. This setting persists across sessions, allowing you to observe how {% data variables.product.prodname_copilot_short %} works through complex problems. ### Configure settings You can view and change your personal {% data variables.copilot.copilot_cli_short %} settings using the `/settings` slash command. * Run `/settings` to open an interactive settings editor, where you can search for a setting by name and edit it. To restore a setting to its default value, highlight it in the list of settings and press Ctrl+R. * Run `/settings KEY VALUE` to change a setting directly in the CLI's prompt box. KEY is the name of the setting and VALUE is the value you want to set. This also works in scripts and in programmatic sessions started with `-p`. * Run `/settings show KEY` to display a setting's current value as text, without opening the editor. Most settings changes take effect immediately, without needing to restart {% data variables.copilot.copilot_cli_short %}. For more information, see [AUTOTITLE](/copilot/how-tos/copilot-cli/customize-copilot/change-settings). For the full list of available settings, see [AUTOTITLE](/copilot/reference/copilot-cli-reference/cli-config-dir-reference#configuration-file-settings). ## Find out more For a complete list of the command line options and slash commands that you can use with {% data variables.copilot.copilot_cli_short %}, do one of the following: * Enter `?` in the prompt box in an interactive session. * Enter `copilot help` in your terminal. For additional information, use one of the following `copilot help` subcommands in your terminal: * **Configuration settings**: `copilot help config` * **Environment variables** that affect {% data variables.copilot.copilot_cli_short %}: `copilot help environment` * **Available logging levels**: `copilot help logging` * **Permissions** for allowing or denying tool use: `copilot help permissions` {% data reusables.cli.feedback %} ## Next steps {% data variables.copilot.copilot_cli_short %} can operate as a conversational assistant, answering questions and helping you write code interactively. Beyond chat, {% data variables.copilot.copilot_cli_short %} supports a range of agentic modes that allow you to delegate tasks with greater autonomy. You can work with agents in {% data variables.copilot.copilot_cli_short %} to support a full task lifecycle, from delegating work to reviewing results: * **Delegate tasks autonomously**: Run {% data variables.copilot.copilot_cli_short %} in autopilot mode to complete multi-step tasks without requiring approval at each step. See [AUTOTITLE](/copilot/how-tos/copilot-cli/use-copilot-cli/delegate-tasks-to-cca). * **Invoke custom agents**: Invoke specialized agents tailored to specific tasks, such as code review, documentation, or security audits. See [AUTOTITLE](/copilot/how-tos/copilot-cli/use-copilot-cli/invoke-custom-agents). * **Steer agents**: Guide and refine agent behavior during task execution to keep work on track. See [AUTOTITLE](/copilot/how-tos/copilot-cli/use-copilot-cli/steer-agents). * **Request a code review**: Use {% data variables.copilot.copilot_cli_short %} to get an AI-powered review of your code changes. See [AUTOTITLE](/copilot/how-tos/copilot-cli/use-copilot-cli/agentic-code-review). ## Further reading * [AUTOTITLE](/copilot/how-tos/copilot-cli/cli-best-practices) * [AUTOTITLE](/copilot/reference/copilot-cli-reference/cli-command-reference) * [AUTOTITLE](/copilot/reference/copilot-cli-reference/cli-config-dir-reference) * [AUTOTITLE](/copilot/reference/copilot-cli-reference/acp-server)