Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
beginner GitHub Copilot IMCSEIAN Slash Commands Tutorial

Your First Slash Commands: /explain, /fix, /tests, /doc

Reviewed & accurate
AI Summary
IMCSEIAN · GitHub Copilot Master Course

Your First Slash Commands: /explain, /fix, /tests, /doc

Use the four most useful slash commands and understand what each produces.

Phase 1 — Beginner Lesson BE-09 Difficulty: Beginner 7 min read
Course: GitHub Copilot Phase 1 — Beginner 7 min read Last verified: 2026-08-30

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

/explain output structureimcseian
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
/tests invocationimcseian
# 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

ProblemHow to Fix
Slash command not foundVerify your Copilot Chat extension is current. New commands ship in updates.
/tests uses wrong frameworkAdd a hint: '/tests use vitest'. Or set the default in copilot-instructions.md.
/doc format wrongSpecify: '/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?
Yes — via .github/copilot-instructions.md and prompt files. Covered in IN-39.
Are slash commands available in the CLI?
Yes — the new copilot CLI has equivalent slash commands. Covered in IN-42.
Does /tests support all test frameworks?
Most major ones (jest, vitest, pytest, junit, xunit, go test). Detection is automatic from project files.

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

Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments