Custom Slash Commands in VS Code
Define reusable commands via .github/copilot-instructions.md and prompt files.
What You Will Learn
- Create custom slash commands.
- Use .github/copilot-instructions.md.
- Use prompt files.
- Share commands with team.
- Iterate commands over time.
Why This Matters
Built-in slash commands are useful but generic. Custom commands encode your team's conventions and reusable prompts. This is the foundation of team-wide Copilot consistency.
Concept Explained
Custom slash commands are defined via .github/copilot-instructions.md (repo-level) or prompt files (workspace). They appear in the slash command picker like built-ins.
How It Works
Create .github/copilot-instructions.md with system-style instructions. Or create .github/prompts/*.md files for custom commands. Copilot reads them and offers in the picker.
Step-by-Step Tutorial
1. Create instructions file
.github/copilot-instructions.md — repo-level system prompt.2. Add conventions
Coding style, common patterns, 'don'ts'.3. Create prompt files
.github/prompts/review.md, generate-tests.md, etc.4. Use in Chat
Type / + tab to see custom commands.5. Iterate
Refine based on output quality. Commit changes.Real-World Example
A team added .github/copilot-instructions.md with: 'Use TypeScript strict mode. Prefer functional style. No classes. Use early returns.' All Copilot Chat in the repo followed these conventions. Code review consistency improved dramatically.
Example Prompts / Commands / Code
# .github/copilot-instructions.md
You are an engineer at Acme Corp. Follow these conventions:
## Code style
- TypeScript strict mode.
- Prefer functional style; avoid classes.
- Use early returns; max 3 nesting levels.
- All async functions must have explicit return types.
- All public functions must have JSDoc.
## Don'ts
- Don't use lodash (use native methods).
- Don't use try/catch (use Result type from neverthrow).
- Don't use classes (use functions and closures).
- Don't use any (use unknown and narrow).
## Patterns
- Repository pattern for data access.
- Result type for error handling.
- Zod for runtime validation.
Apply these to all code suggestions.
# .github/prompts/security-review.md
Act as a security reviewer.
Check for:
- Input validation
- Authentication/authorization
- Secrets in code
- Unsafe deserialization
- SQL injection
- XSS
Output as numbered list with severity (high/med/low), issue, fix.
Code to review:
$selection
Common Mistakes
- Instructions too long — eats context budget.
- Not committing instructions — team doesn't benefit.
- Not iterating — first version rarely best.
- Confusing instructions (system) with prompt files (commands).
Best Practices
- Keep copilot-instructions.md concise (<500 tokens).
- Commit to repo so team benefits.
- Use prompt files for custom commands.
- Iterate based on output quality.
- Document the layering: instructions (persistent) + prompt files (commands).
Troubleshooting
| Problem | How to Fix |
|---|---|
| Custom command not appearing | Verify file path. Restart VS Code. |
| Instructions not respected | Rephrase. Or move to prompt file for explicit invocation. |
Practical Exercise
Your Turn
Create .github/copilot-instructions.md for your repo with 5 conventions. Create a custom slash command for security review. Use both in real work.
Professional Challenge
Build a library of 5 custom slash commands for your team's common tasks. Commit to a shared repo. Document usage.
Key Takeaways
- Custom slash commands via .github/copilot-instructions.md and prompt files.
- Instructions = repo-level system prompt.
- Prompt files = custom commands.
- Commit to repo for team benefit.
- Keep instructions concise (<500 tokens).
Frequently Asked Questions
Do instructions apply to inline completions?
Can I have per-project instructions?
Further Reading
Official References
SEO Metadata
SEO title: Custom Slash Commands in VS Code
Meta description: Define reusable commands via .github/copilot-instructions.md and prompt files.
Primary keyword: custom slash commands in vs code
Secondary keywords: custom slash commands in vs code
Search intent: Informational
URL slug: /custom-slash-commands-vscode-copilot-instructions
Categories: AI Tools, GitHub Copilot
Tags: GitHub Copilot, Intermediate, Custom Commands, copilot-instructions.md, Tooling, IMCSEIAN, Tutorial, IMCSEIAN
Featured image concept: IMCSEIAN lesson card for Custom Slash Commands in VS Code
Comments
Comments
Post a Comment