GitHub Copilot CLI is a terminal coding agent you start with copilot in a Python project folder. It reads project context from .github/copilot-instructions.md or AGENTS.md, plans changes, edits files, runs commands, and shows you diffs for review. This guide shows a practical workflow for Python using venv, pyproject.toml, pytest, ruff, and mypy. For the agent basics, see the GitHub Copilot CLI overview (GitHub Copilot CLI).
Python workflows that play to Copilot CLI’s strengths
Python projects benefit when the agent works inside the same terminal as your existing toolchain. Copilot CLI can inspect a pyproject.toml, activate the right virtual environment, interpret tracebacks from pytest, and apply fixes from ruff without losing project context. It understands modern Python idioms such as pathlib, dataclasses, tomllib, PEP 604 unions, and type narrowing. Because you review each diff before it is applied, you keep control over API design and dependency choices. This makes it useful for focused tasks like adding a typed function, refactoring an import path, or writing parametrized tests while keeping mypy and ruff green.
Preparing a Python repo for Copilot CLI
Create a project instruction file before starting heavy work. GitHub Copilot CLI reads .github/copilot-instructions.md or AGENTS.md from the repository root. The file should be short, command-focused, and opinionated about your Python conventions. Include exact commands so the agent does not guess between python -m pytest and pytest, or between ruff check and ruff check ..
A realistic example for a project using src layout and pyproject.toml:
# Project instructions for Copilot
## Commands
- Create and activate a virtual environment: python -m venv .venv && source .venv/bin/activate
- Install the project and dev tools: pip install -e '.[dev]'
- Run tests: pytest -q
- Lint: ruff check .
- Format check: ruff format --check .
- Type check: mypy src
## Layout
- Source code lives in src/myapp/, tests in tests/.
- Keep public imports in src/myapp/__init__.py.
## Python rules
- Use PEP 604 unions (`int | None`) and `from __future__ import annotations`.
- Prefer dataclasses over dicts for structured data.
- Every new function needs a test unless it is a trivial wrapper.
## Agent workflow
- Do not edit pyproject.toml without asking first.
- After any change in src/, run pytest -q, ruff check ., and mypy src.
- Show the diff before applying changes.
Keep the file under 60 lines; long prose instructions get ignored or diluted. For a full agent walkthrough, see How to use GitHub Copilot CLI: a step-by-step guide (How to use GitHub Copilot CLI: a step-by-step guide).
A repeatable workflow for Python changes
Treat Copilot CLI like a junior engineer who needs a clear specification and frequent verification. A good loop is:
- Plan with the agent in a short paragraph.
- Let it implement one small change.
- Run the test, lint, and type-check commands yourself or ask the agent to run them.
- Review the diff before accepting.
- Repeat.
Example prompts for typical Python tasks:
- ‘Add a
load_configfunction tosrc/myapp/config.pythat reads TOML withtomlliband returns a frozen dataclass. Include tests for missing keys and invalid TOML.’ - ‘Refactor
src/myapp/utils.py:parse_inputto acceptpathlib.Pathinstead ofstr. Preserve behavior, update callers, and run pytest and mypy.’ - ‘Fix all
ruff check .errors in the current branch without changing behavior. Show the diff first and then run the full test suite.’ - ‘Add type hints to all public functions in
src/myapp/models.py. Runmypy srcand resolve any errors while keeping runtime behavior identical.’
If the agent does not know where code lives, ask it to map the codebase first or point it to the right files. A codebase map can help the agent find code without grep (Codebase map for AI agents: find code without grep).
Where Copilot CLI shines on Python, and where it needs review
The agent handles common Python work well: adding typed functions, writing tests, converting string paths to pathlib, replacing dicts with dataclasses, updating imports after a rename, and applying ruff or mypy fixes. It is also useful for boring but error-prone tasks like changing all call sites of a function signature.
Watch it closely in these Python-specific areas:
| Task | Watch out for |
|---|---|
| Virtual environments | The agent may run python instead of .venv/bin/python and hit the wrong interpreter. Put venv activation in instructions and ask it to confirm the interpreter. |
| Imports and src layout | Editable installs can hide missing __init__.py files. If tests fail with ModuleNotFoundError, check pip install -e .[dev] and sys.path, not just the code. |
| Type hints | Copilot may add Any or overly broad dict instead of precise generics. Ask for mypy in strict mode and review type-only changes carefully. |
| Test quality | It may write tests that pass but do not assert behavior. Require each test to have an explicit assertion and cover both success and failure paths. |
| Packaging | It can edit pyproject.toml incorrectly, adding missing dependencies or changing build backends. Block direct edits and review every packaging change. |
The biggest pitfall is accepting a diff that makes tests green but introduces a hidden behavior change, such as weakening an exception type or changing a default argument.
Running pytest, ruff, and mypy through the agent
Make verification explicit in every turn. Before accepting changes, ask the agent to run the full command set and paste the output:
pytest -q
ruff check .
ruff format --check .
mypy src
If any command fails, ask the agent to fix the failure and rerun all commands, not just the one that failed. For a bug fix, require a regression test that fails on the old code first. For a refactor, require the existing test suite to pass without modification unless the change intentionally alters behavior. Ask for pytest -q --disable-warnings if warnings add noise, but do not let the agent suppress errors. Finally, review the diff yourself: check that imports point to the intended modules, no broad except Exception appeared, and no type ignores were added.
Parallel Python agents with AgentVera
When a Python project has many independent parts, running several agents in parallel can speed up work but risks file conflicts and inconsistent venv usage. AgentVera runs real CLI agents such as GitHub Copilot CLI in separate terminal panels, each in its own git worktree, so parallel Python changes do not overwrite each other. Automatic code review by a second model links findings to file:line, useful for catching type errors and import mistakes. Checkpoints let you undo a bad turn without losing the rest of the day. Token budgets prevent one agent from burning through your plan while you are away. These controls matter for Python because a bad refactor across many call sites can be subtle and expensive.
Wrap-up
GitHub Copilot CLI works best on Python when you give it a short project instruction file, work in small verified steps, and keep pytest, ruff, and mypy as the gatekeepers. Treat it as a fast pair programmer that still needs your review on API design, type correctness, and test quality. Start with focused prompts, inspect every diff, and let the tool handle the mechanical repetition.