Your First Slash Commands: /explain, /fix, /tests, /doc
Use the four most useful slash commands and understand what each produces.
What You Will Learn
- Invoke /explain, /fix, /tests, /doc, /new.
- Understand the pre-baked prompt each command runs.
- Choose the right command for the task.
- Combine slash commands with @workspace for repo-wide scope.
- Extend commands with custom instructions.
Why This Matters
Slash commands are pre-baked prompts that save typing and standardize output. Mastering the four core commands (/explain, /fix, /tests, /doc) covers 70% of daily Copilot Chat use.
Concept Explained
A slash command is a shortcut for a structured prompt. When you type /explain, Copilot doesn't just 'explain' — it runs a specific prompt template designed to produce structured explanations. Each command has a target output shape.
How It Works
Typing / in the chat box opens a command picker. Selecting a command inserts its template into the chat. The template includes your current selection or attached file as the target. You can append additional instructions before sending.
Step-by-Step Tutorial
1. Use /explain
Highlight a function in your editor. Type /explain in Chat. Copilot produces purpose, parameters, return value, side effects, edge cases.2. Use /fix
Highlight buggy code. Type /fix. Copilot proposes a fix with explanation.3. Use /tests
Highlight a function. Type /tests. Copilot generates a starter test suite in the file's test framework.4. Use /doc
Highlight a function. Type /doc. Copilot generates a docstring/JSDoc.5. Use /new
Type /new to scaffold a new file from a natural-language description.Real-World Example
A developer was asked to add tests to a legacy module with zero coverage. They opened each function, ran /tests, reviewed the generated tests, extended them for edge cases, and shipped 40 passing tests in 2 hours. Without Copilot, the same task would have taken a full day.
Example Prompts / Commands / Code
Purpose: What this function does
Parameters: Name, type, meaning
Returns: Type and meaning
Side effects: Mutations, I/O, exceptions
Edge cases: Empty inputs, null, overflow
Notes: Anything else relevant
# Highlight a function in your editor, then in Chat:
/tests
# Optional: add constraints
/tests Use vitest. Cover edge cases: empty input, null, very large numbers.
Common Mistakes
- Running /tests without reviewing — generated tests can have wrong assertions.
- Using /fix without understanding the bug — Copilot may paper over a deeper issue.
- Forgetting that /doc uses your project's doc convention only if detected — verify format.
- Expecting /explain to know about code in other files — attach them first.
Best Practices
- Always review slash-command output like any AI output.
- Combine with attachments — /tests on an attached file works better than on a snippet.
- Add custom constraints after the slash command ('/tests use vitest').
- Use /new for scaffolding boilerplate (config files, Dockerfiles, GitHub Actions).
Troubleshooting
| Problem | How to Fix |
|---|---|
| Slash command not found | Verify your Copilot Chat extension is current. New commands ship in updates. |
| /tests uses wrong framework | Add a hint: '/tests use vitest'. Or set the default in copilot-instructions.md. |
| /doc format wrong | Specify: '/doc use JSDoc with @param and @returns'. |
Practical Exercise
Your Turn
Pick a function you wrote recently. Run /explain, then /tests, then /doc on it. Compare the three outputs. Did /explain surface anything you didn't realize about your own code?
Key Takeaways
- Slash commands are pre-baked structured prompts.
- Four core commands: /explain, /fix, /tests, /doc.
- Add custom constraints after the command.
- Always review output before using.
- /new scaffolds new files from natural language.
Frequently Asked Questions
Can I create custom slash commands?
Are slash commands available in the CLI?
Does /tests support all test frameworks?
Further Reading
Official References
Related lessons: BE-08, BE-10, IN-39
SEO Metadata
SEO title: Your First Slash Commands: /explain, /fix, /tests, /doc
Meta description: Use the four most useful slash commands and understand what each produces.
Primary keyword: your first slash commands
Secondary keywords: your first slash commands: /explain, /fix, /tests, /doc
Search intent: Informational
URL slug: /github-copilot-slash-commands-explain-fix-tests-doc
Categories: AI Tools, GitHub Copilot
Tags: GitHub Copilot, Beginner, Slash Commands, IMCSEIAN, Tutorial, IMCSEIAN
Featured image concept: IMCSEIAN lesson card for Your First Slash Commands: /explain, /fix, /tests, /doc
Comments
Comments
Post a Comment