What if AI could see your entire codebase, not just one file at a time?
In this chapter, you’ll unlock the real power of GitHub Copilot CLI: context. You’ll learn to use the @ syntax to reference files and directories, giving Copilot CLI deep understanding of your codebase. You’ll discover how to maintain conversations across sessions, resume work days later exactly where you left off, and see how cross-file analysis catches bugs that single-file reviews miss entirely.
💡 How do I find a session ID? You don’t need to memorize them. Running copilot --resume without an ID shows an interactive list of your previous sessions, their names, IDs, and when they were last active. Just pick the one you want.
What about multiple terminals? Each terminal window is its own session with its own context. If you have Copilot CLI open in three terminals, that’s three separate sessions. Running --resume from any terminal lets you browse all of them. The --continue flag grabs whichever session was closed most recently, no matter which terminal it was in.
Can I switch sessions without restarting? Yes. Use the /resume slash command from inside an active session:
As you add files and conversation, Copilot CLI’s context window fills up. Two commands help you stay in control:
Terminal window
copilot
> /context
Contextusage:45,000/128,000tokens (35%)
> /clear
# Wipes context and starts fresh. Use when switching topics
💡 When to use /clear: If you’ve been reviewing books.py and want to switch to discussing utils.py, run /clear first. Otherwise stale context from the old topic may confuse responses.
Sessions auto-save when you exit. Resume days later with full context: files, issues, and progress all remembered.
Imagine this workflow across multiple days:
Terminal window
# Monday: Start book app review
copilot
> /rename book-app-review
> @samples/book-app-project/books.py
> Review and number all code quality issues
QualityIssuesFound:
1.Duplicatedisplayfunctions (book_app.py & utils.py) - MEDIUM
2.Noinputvalidationforemptystrings-MEDIUM
3.Yearcanbe0ornegative-LOW
4.Notypehintsonallfunctions-LOW
5.Missingerrorlogging-LOW
> Fix issue #1 (duplicate functions)
# Work on the fix...
> /exit
Terminal window
# Wednesday: Resume exactly where you left off
copilot--continue
> What issues remain unfixed from our book app review?
Remainingissuesfromourbook-app-reviewsession:
2.Noinputvalidationforemptystrings-MEDIUM
3.Yearcanbe0ornegative-LOW
4.Notypehintsonallfunctions-LOW
5.Missingerrorlogging-LOW
Issue#1 (duplicate functions) was fixed on Monday.
> Let's tackle issue #2 next
What makes this powerful: Days later, Copilot CLI remembers:
The exact file you were working on
The numbered list of issues
Which ones you’ve already addressed
The context of your conversation
No re-explaining. No re-reading files. Just continue working.
🎉 You now know the essentials! The @ syntax, session management (--continue/--resume//rename), and context commands (/context//clear) are enough to be highly productive. Everything below is optional. Return to it when you’re ready.
You can include images in your conversations using the @ syntax, or simply paste from your clipboard (Cmd+V / Ctrl+V). Copilot CLI can analyze screenshots, mockups, and diagrams to help with UI debugging, design implementation, and error analysis.
Terminal window
copilot
> @images/screenshot.png What is happening in this image?
> @images/mockup.png Write the HTML and CSS to match this design. Place it in a new file called index.html and put the CSS in styles.css.
📖 Learn more: See Additional Context Features for supported formats, practical use cases, and tips for combining images with code.
The course includes sample files you can review directly. Start copilot and run the prompt shown next:
Terminal window
copilot
> @samples/book-app-project/ Give me a code quality review of this project
# Copilot CLI will identify issues like:
# - Duplicate display functions
# - Missing input validation
# - Inconsistent error handling
💡 Want to try with your own files? Create a small Python project (mkdir -p my-project/src), add some .py files, then use @my-project/src/ to review them. You can ask copilot to create sample code for you if you’d like!
> What's the relationship between these files? Are there any code smells?
Session Challenge: Start a session, name it with /rename my-first-session, work on something, exit with /exit, then run copilot --continue. Does it remember what you were doing?
Context Challenge: Run /context mid-session. How many tokens are you using? Try /compact and check again. (See Understanding Context Windows in Going Deeper for more on /compact.)
Self-Check: You understand context when you can explain why @folder/ is more powerful than opening each file individually.
The hands-on examples focused on code quality reviews and input validation. Now practice the same context skills on a different task, tracing how data moves through the app:
Start an interactive session: copilot
Reference books.py and book_app.py together:
@samples/book-app-project/books.py @samples/book-app-project/book_app.py Trace how a book goes from user input to being saved in data.json. What functions are involved at each step?
Bring in the data file for additional context:
@samples/book-app-project/data.json What happens if this JSON file is missing or corrupted? Which functions would fail?
Ask for a cross-file improvement:
@samples/book-app-project/books.py @samples/book-app-project/utils.py Suggest a consistent error-handling strategy that works across both files.
Rename the session: /rename data-flow-analysis
Exit with /exit, then resume with copilot --continue and ask a follow-up question about the data flow
Success criteria: You can trace data across multiple files, resume a named session, and get cross-file suggestions.
💡 Hints (click to expand)
Getting started:
Terminal window
cd/path/to/copilot-cli-for-beginners
copilot
> @samples/book-app-project/books.py @samples/book-app-project/book_app.py Trace how a book goes from user input to being saved in data.json.
> @samples/book-app-project/data.json What happens ifthisfileismissingorcorrupted?
> /rename data-flow-analysis
> /exit
Then resume with: copilot --continue
Useful commands:
@file.py - Reference a single file
@folder/ - Reference all files in a folder (note the trailing /)
/context - Check how much context you’re using
/rename <name> - Name your session for easy resuming
Reference all the book app files at once with @samples/book-app-project/
Ask several detailed questions about different files (books.py, utils.py, book_app.py, data.json)
Run /context to see usage. How quickly does it fill up?
Practice using /compact to reclaim space, then continue the conversation
Try being more specific with file references (e.g., @samples/book-app-project/books.py instead of the whole folder) and see how it affects context usage
🔧 Common Mistakes & Troubleshooting (click to expand)
Now that you can give Copilot CLI context, let’s put it to work on real development tasks. The context techniques you just learned (file references, cross-file analysis, and session management) are the foundation for the powerful workflows in the next chapter.