GitHub Copilot is one of the most widely-used AI coding tools. This guide covers setup, the features most developers miss, and how to get better suggestions.
Installation
- Install the GitHub Copilot extension in VS Code (search:
GitHub.copilot) - Also install GitHub Copilot Chat for the chat interface
- Sign in with your GitHub account
- Start a free trial or subscribe ($10/month individual, $19/month business)
You’ll know it’s working when you see the Copilot icon in the status bar (bottom right).
Core Feature: Inline Completions
Copilot suggests code as you type. These appear as greyed-out text.
Accepting suggestions:
Tab— Accept full suggestionCtrl+Right Arrow(Windows/Linux) /Cmd+Right Arrow(Mac) — Accept word by wordEsc— Dismiss
Cycling through alternatives:
Alt+]/Option+]— Next suggestionAlt+[/Option+[— Previous suggestionCtrl+Enter— Open all 10 suggestions in a panel (useful when you want to see options)
Copilot Chat
Ctrl+Shift+I opens the chat panel. This is a full conversational interface aware of your workspace.
Context Commands
Use # to add specific context:
#file:App.tsx— Reference a specific file#selection— Reference currently selected code#codebase— Search across your whole project#terminal— Reference recent terminal output
Example:
@workspace #file:auth.ts Why might this authentication be insecure?
Check specifically for session handling issues.
Slash Commands
Type / in the chat to see available commands:
/explain— Explain selected code/fix— Fix bugs in selection/tests— Generate tests for selection/doc— Add documentation to code/simplify— Simplify complex code/new— Create a new file or project
Inline Chat
Ctrl+I (Windows/Linux) / Cmd+I (Mac) opens inline chat directly in the editor.
This is faster than the panel when you want to make a targeted change:
- Select code
- Press
Cmd+I - Type your request: “Refactor this to use async/await”
- Accept or reject the suggestion
Inline chat shows a diff view so you can see exactly what changed before accepting.
Getting Better Completions
Write a Descriptive Comment First
# Calculate the Levenshtein distance between two strings using dynamic programming
def levenshtein_distance(s1: str, s2: str) -> int:
Copilot will suggest a complete implementation based on the comment.
Keep Context Files Open
Copilot uses open editor tabs as context. If you’re writing code that uses types defined in another file, keep that file open in another tab.
Add Type Annotations
// Without types — Copilot guesses
function processUser(user) {
// With types — Copilot knows what you need
function processUser(user: User): ProcessedUser {
Use Descriptive Variable and Function Names
# Copilot will suggest random implementation
def x(a, b):
# Copilot understands the intent
def calculate_compound_interest(principal: float, rate: float, years: int) -> float:
Copilot for Tests
Select a function and use /tests or ask explicitly:
Write comprehensive tests for the selected function using Jest.
Cover: happy path, edge cases (empty input, null, boundary values), error cases.
Use describe/it blocks with descriptive names.
Workspace Features
@workspace Agent
@workspace How is authentication implemented in this project?
Copilot searches your entire codebase and synthesizes an answer. Useful for:
- Understanding unfamiliar codebases
- Finding where something is implemented
- Understanding patterns before adding code
Creating New Files
/new Create a TypeScript utility class for handling rate limiting with:
- Token bucket algorithm
- Redis backend
- Per-user and global limits
- Async interface
Copilot creates a complete new file.
Customizing Copilot Behavior
.github/copilot-instructions.md
Create this file in your repo to give Copilot project-specific context:
# Project Context
## Tech Stack
- Backend: Node.js with Express
- Database: PostgreSQL with Knex.js (NOT Prisma)
- Auth: JWT tokens, stored in httpOnly cookies
- Testing: Jest with supertest
## Code Style
- Use async/await, not callbacks or .then()
- All database queries go through the repository layer (src/repositories/)
- Never use raw SQL strings — always use Knex query builder
- Error handling: always throw typed errors (src/errors/)
## Naming Conventions
- Files: kebab-case
- Functions: camelCase
- Types/Classes: PascalCase
- Database columns: snake_case
## What NOT to do
- Don't use `var`, only `const` and `let`
- Don't use `any` type in TypeScript
- Don't add console.log statements
VS Code Settings for Copilot
In settings.json:
{
"github.copilot.editor.enableAutoCompletions": true,
"github.copilot.chat.localeOverride": "en",
"github.copilot.enable": {
"*": true,
"markdown": false,
"plaintext": false
}
}
Code Review with Copilot
Select a pull request diff or paste code and use the chat:
Review this code for:
1. Security vulnerabilities (especially input validation, SQL injection, XSS)
2. Performance issues
3. Error handling gaps
4. Code style inconsistencies
Prioritize issues by severity.
Debugging with Copilot
When you hit an error:
- Copy the full stack trace
- Open Copilot Chat
- Paste: “I’m getting this error: [paste error]. Here’s the code: [paste code]. What’s the cause?”
Or paste terminal output using #terminal to automatically include recent terminal output.
Common Mistakes
Accepting without reading: Copilot suggestions can be subtly wrong. Always read what you accept before running.
Not providing context: Vague requests get vague responses. The more specific your comment or question, the better the suggestion.
Missing the Ctrl+Enter panel: When the first suggestion isn’t right, Ctrl+Enter shows 10 alternatives — one is usually better.
Ignoring suggestions for documentation: Copilot is excellent at writing JSDoc/TSDoc comments. Let it document your functions — it’s faster than writing manually.
Not using the chat for debugging: The inline completions are 50% of Copilot’s value. Copilot Chat for debugging and code review is the other 50%.