← Previous: Install and Modes | Next: GitHub Integration and Workflows →
🎯 Learning Goals
- Understand how tool approval protects you from unintended changes
- Use
--allow-tool,--deny-tool, and--allow-all-toolsto configure automatic approval - Use programmatic mode with
-pfor scripted and headless workflows - Manage conversation context with
/compact,/context, and auto-compaction
Every time Copilot wants to modify a file or execute a shell command it asks for your approval. This keeps you in control — but for trusted, repetitive tasks you can pre-approve specific tools.
-
Launch a new session and ask Copilot to run the project's tests:
copilot
Run all the tests in the project and show me a summary of the results.When Copilot asks permission to run
pytest, notice the three options presented:1. Yes 2. Yes, and approve pytest for the rest of this session 3. No, and tell Copilot what to do differently (Esc)Choose 2 to approve
pytestfor the rest of the session. -
Use the
--allow-toolflag to pre-approve specific commands at launch. This is useful for CI scripts or trusted tasks:copilot --allow-tool 'shell(pytest)' --allow-tool 'write'
shell(COMMAND)— approves a specific shell command. Omit the command name to allow all shell commands.write— approves all file modifications without individual prompts.
-
Use
--deny-toolto block specific commands even when--allow-all-toolsis set. For example, to allow everything exceptrmandgit push:copilot --allow-all-tools --deny-tool 'shell(rm)' --deny-tool 'shell(git push)'
--deny-toolalways takes precedence over--allow-tooland--allow-all-tools.
For headless use in scripts and CI pipelines, pass a prompt directly with -p instead of opening an interactive session:
-
Run a single task non-interactively:
copilot -p "Show me this week's commits and summarize them" --allow-tool 'shell(git)'
Copilot completes the task and exits. You can also pipe options from a script:
echo "Run pytest and report any failures" | copilot --allow-tool 'shell(pytest)'
For long sessions working on large codebases, the conversation history can approach the model's token limit. The CLI manages this automatically and gives you manual control.
-
Check how much of your context window is in use at any time:
/contextThis shows a token usage breakdown split by system prompt, conversation history, and available remaining tokens.
-
When you want to free up context without ending the session, run:
/compactCopilot compresses the conversation history while retaining key facts about the tasks completed so far. Press
Escapeto cancel if you change your mind. -
Auto-compaction kicks in automatically when the session approaches 95% of the token limit, compressing history in the background without interrupting your workflow. This enables virtually unlimited session length — you can work on a feature from start to finish without restarting.
In the above exercises we achieved the following:
- ✅ Understood per-action tool approval prompts
- ✅ Pre-approved tools with
--allow-tooland blocked tools with--deny-tool - ✅ Used programmatic mode for headless CLI invocations
- ✅ Monitored and managed conversation context with
/contextand/compact
← Previous: Install and Modes | Next: GitHub Integration and Workflows →