Operating Modes & Commands
Prerequisites
- Copilot CLI installed and authenticated (Module 1)
- A project directory to work in
Learning Objectives
- Understand the difference between interactive and programmatic modes
- Discover and use slash commands (
/command) for CLI control - Use
/plan,/review, and/difffor structured workflows - Use the delegate (
/delegate) command to hand off to cloud agents - Control tool approval during interactions
- Choose the right mode for different scenarios
Concepts
Interactive Mode
Interactive mode starts a conversational session where you chat with Copilot in real-time. It's ideal for:
- Exploratory coding and debugging
- Multi-step tasks requiring iteration
- Learning a new codebase
- Tasks where you want to review each step
# Start interactive mode
copilot
Programmatic Mode
Programmatic mode executes a single prompt and exits. Perfect for:
- CI/CD pipelines
- Scripting and automation
- Batch processing
- Single-shot tasks
# Execute a single prompt
copilot -p "summarize the README.md file"
Delegate Mode
The /delegate command hands off work to GitHub's cloud-based Copilot coding agent. Use it for:
- Long-running tasks
- Compute-intensive operations
- Parallel work (you continue locally while agent works)
- Tasks that benefit from full repository context
/delegate implement the user authentication feature based on the spec
Slash Commands
Slash commands are prefixed with / and provide quick access to CLI features without leaving the conversation. They are the primary way to control Copilot CLI behavior during an interactive session.
For the full command reference, keyboard shortcuts, and tool approval guide, see Command Reference.
Discovering Commands
- Type
/helpto see the full list of available commands - Press
ctrl+xthen/to run a command via keyboard shortcut - Commands are tab-completable: start typing
/followed by the first letters
Hands-On Exercises
Authentication Required: You must authenticate before running these exercises. Complete Module 1 (authentication setup) or set one of these environment variables: GITHUB_TOKEN, GH_TOKEN, or COPILOT_GITHUB_TOKEN.
Exercise 1: Discovering Slash Commands
Goal: Learn to discover and use slash commands inside an interactive session.
Steps:
-
Start Copilot CLI:
copilot -
View all available commands:
/help -
Review the output: you'll see commands grouped with descriptions.
-
Try the
/themecommand to see available themes:/theme list -
Set a theme (optional):
/theme set <theme-id> -
Check your current working directory:
/cwd -
View session usage metrics:
/usage -
Exit with
/exit.
Expected Outcome:
You can discover and navigate the full set of slash commands using /help.
Exercise 2: Planning and Reviewing with Commands
Goal: Use /plan, /review, and /diff for structured development workflows.
Steps:
-
Navigate to a project directory and start Copilot:
mkdir -p ~/copilot-commands-lab && cd ~/copilot-commands-lab
git init
copilot -
Use
/planto create an implementation plan before coding:/plan Build a simple REST API with Express.js that has CRUD endpoints for a todo list -
Copilot creates a structured plan. Review it before proceeding.
-
Ask Copilot to implement the plan:
Go ahead and implement the plan -
After files are created, review all changes made:
/diff -
Run a code review on the changes:
/review Check for security issues and missing error handling -
Exit with
/exit.
Expected Outcome:
You can use /plan for structured implementation, /diff to review changes, and /review for code analysis.
Exercise 3: Repository Initialization and Session Management Commands
Goal: Use /init to bootstrap Copilot configuration and /rename to organize sessions.
Steps:
-
Create a new project directory:
mkdir -p ~/copilot-init-lab && cd ~/copilot-init-lab
git init
copilot -
Initialize Copilot configuration for this repository:
/init -
This creates starter files like
AGENTS.mdand.github/copilot-instructions.md. -
Rename this session for easy identification:
/rename init-lab-session -
Check session details:
/session -
View background tasks (if any):
/tasks -
Configure terminal for multiline input:
/terminal-setup -
Exit with
/exit.
Expected Outcome:
You can bootstrap Copilot configuration with /init, rename sessions, and configure terminal features.
Exercise 4: Interactive Mode Basics
Goal: Start an interactive session and perform basic operations.
Steps:
-
Navigate to a project directory:
mkdir -p ~/copilot-workshop && cd ~/copilot-workshop
git init -
Start Copilot CLI:
copilot -
Ask Copilot to create a file:
Create a Python script named `hello.py` that prints "Hello, Copilot!"tipSpecifying the exact filename in prompts ensures consistent results across workshop participants. Without it, Copilot may generate different filenames each time (e.g.,
hello_copilot.py,hello_python.py). -
When prompted to approve the file write, select Yes.
-
Ask a follow-up question:
Now modify it to accept a name as a command-line argument -
Continue the conversation:
Add error handling if no argument is provided -
Exit with
/exitorCtrl+C.
Expected Outcome: A Python script evolves through multiple iterations with your guidance.
Exercise 5: Tool Approval Workflow
Goal: Understand how to approve, deny, and manage tool permissions.
Steps:
-
Start a new session:
copilot -
Ask Copilot to run a command:
List all files in the current directory with details -
Copilot will request to use the
shelltool. You'll see three options:- Yes - Allow this time only
- Yes, and approve TOOL for the rest of the session - Session-wide approval
- No, and tell Copilot what to do differently - Deny and redirect
-
Select Yes (first option) to allow once.
-
Now ask:
Display the contents of hello.py using the cat commandtipAvoid prompts that reference a specific number of lines (e.g., "first 10 lines") for short files. Copilot may reason about the file length instead of running the expected command.
-
Copilot asks for shell permission again (since you only approved once).
-
This time select Yes, and approve shell for the rest of the session.
-
Ask another command:
Count the lines in hello.py -
Notice Copilot doesn't ask for permission this time.
Expected Outcome: You understand the difference between one-time and session-wide tool approval.
Exercise 6: Programmatic Mode
Goal: Execute single commands without entering interactive mode.
Steps:
-
Create a test file:
echo "# My Project" > README.md
echo "This is a test project for learning Copilot CLI." >> README.md -
Run Copilot in programmatic mode:
copilot -p "What does the README.md contain?" -
Try with tool permissions:
copilot -p "Add a 'Getting Started' section to README.md" --allow-tool 'write' -
Combine multiple tool permissions:
copilot -p "Run git status and explain what it means" --allow-tool 'shell(git)' -
Pipe file content as context:
cat README.md | copilot -p "Explain what this file contains"tipWhen piping content to Copilot, use prompts that reference "this content" or "this file" rather than "this output" to avoid Copilot responding with "I don't see any output to explain."
Expected Outcome: Commands execute and exit without entering interactive mode.
Exercise 7: Chaining Prompts
Goal: Use programmatic mode in shell scripts.
Steps:
-
Create a script
analyze.sh:#!/bin/bash
echo "=== Project Analysis ==="
# Get file count
copilot -p "Count all .py files recursively and report" --allow-tool 'shell'
echo ""
echo "=== Code Quality Check ==="
# Check for issues
copilot -p "Look for any TODO comments in Python files" --allow-tool 'shell' -
Make it executable:
chmod +x analyze.sh -
Run the script:
./analyze.sh
Expected Outcome: Multiple Copilot operations run sequentially in a script.
Exercise 8: Delegate to Cloud Agent
Goal: Hand off a task to the cloud-based Copilot coding agent.
Steps:
-
Ensure you have a GitHub repository (local work pushed to GitHub).
-
Start interactive mode:
copilot -
Build some context by exploring:
What files are in this project? -
Use delegate to hand off a task:
/delegate create comprehensive unit tests for all Python files in this project -
Copilot will:
- Ask you to commit any unstaged changes
- Create a new branch
- Open a draft pull request
- Start working asynchronously
-
You'll receive a link to track progress.
-
Continue working locally while the agent works in the cloud.
Expected Outcome: A draft PR is created and the cloud agent begins working asynchronously.
Exercise 9: Comparing Modes
Goal: Understand when to use each mode.
Steps:
-
Interactive exploration start a session and explore:
copilot
> Explain the structure of this codebase
> What does the main function do?
> How would I add a new feature?
> /exit -
Programmatic for automation single focused tasks:
# Good for CI/CD
copilot -p "Run all tests and report failures" --allow-tool 'shell'
# Good for git workflows
copilot -p "Summarize changes since last tag" --allow-tool 'shell(git)' -
Delegate for heavy lifting long-running tasks:
/delegate refactor the authentication module to use JWT tokens
Decision Guide:
| Scenario | Recommended Mode |
|---|---|
| Learning a new codebase | Interactive |
| Debugging an issue | Interactive |
| CI/CD pipeline task | Programmatic |
| Generate release notes | Programmatic |
| Major refactoring | Delegate |
| Implement new feature | Delegate |
| Quick code review | Interactive |
Expected Outcome: You can choose the appropriate mode for any task.
Summary
- Interactive mode conversational, multi-step, exploratory
- Programmatic mode single prompt, scriptable, CI/CD friendly
- Delegate mode hands off to cloud agent for heavy tasks
- Slash commands
/plan,/review,/diff,/init, and 25+ others for CLI control - Tool approval has one-time and session-wide options
Next Steps
Continue to Session Management