Slash Commands in the Terminal
Use CLI slash commands productively — /run, /explain, /test.
What You Will Learn
- Use /run, /explain, /test in CLI.
- Combine with natural language.
- Recognize CLI-specific commands.
- Build CLI workflows.
- Compare to editor slash commands.
Why This Matters
CLI slash commands mirror editor ones but with terminal-specific capabilities: /run executes commands, /explain reads files, /test generates and runs tests. Knowing them multiplies CLI value.
Concept Explained
CLI slash commands are pre-baked prompts for terminal workflows: /run (execute), /explain (read file), /test (generate tests), /fix (debug), /doc (add docs).
How It Works
In a copilot session, type / + command. Some take arguments: /explain src/parser.ts. Some are interactive.
Step-by-Step Tutorial
1. Start session
copilot — interactive session.2. /run
/run 'npm test' — executes and analyzes output.3. /explain
/explain src/parser.ts — explains the file.4. /test
/test src/utils.ts — generates and runs tests.5. /fix
/fix 'the build is failing' — reads recent output, proposes fix.Real-World Example
A developer ran /run 'npm test' in the CLI. Tests failed. Ran /fix. Copilot read the failure output, proposed a one-line fix, applied it. Re-ran /run 'npm test'. Green. Total time: 90 seconds.
Example Prompts / Commands / Code
/run <cmd> Execute a command, analyze output
/explain <file> Explain a file's contents
/test <file> Generate and run tests for a file
/fix <desc> Diagnose and fix an issue
/doc <file> Add docstrings to a file
/new <desc> Scaffold a new file
/help Show all commands
$ copilot
> /run 'npm test'
[tests fail with TypeError]
> /fix 'TypeError in user.test.ts'
[Copilot reads output, proposes fix]
[Apply? y/n]: y
> /run 'npm test'
[all tests pass]
> /doc src/user.ts
[Copilot adds JSDoc]
Common Mistakes
- Not using /run — manually pasting output instead.
- Forgetting /fix exists — debugging manually.
- Treating CLI like Chat — CLI can run commands; Chat can't.
- Not combining slash commands into workflows.
Best Practices
- Use /run to execute and analyze in one step.
- Use /fix for debugging — it reads recent output.
- Combine commands into workflows (/run → /fix → /run).
- Use /test for terminal-native test generation.
- Compare to editor slash commands; pick the right surface.
Troubleshooting
| Problem | How to Fix |
|---|---|
| Command not found | Update the CLI. New commands ship in updates. |
| /run fails | Verify the command you're trying to run is valid. |
Practical Exercise
Your Turn
Start a copilot session. Run /run 'npm test' (or equivalent). If tests fail, run /fix. Document the workflow.
Professional Challenge
Build a CLI workflow: /run tests → /fix failures → /run tests → /doc on the fixed file. Measure end-to-end time.
Key Takeaways
- CLI slash commands: /run, /explain, /test, /fix, /doc.
- Combine into workflows: /run → /fix → /run.
- CLI can run commands; Chat can't.
- Use /run to execute and analyze.
- Use /fix for debugging.
Frequently Asked Questions
Are CLI slash commands the same as editor?
Can I create custom CLI slash commands?
Further Reading
Official References
SEO Metadata
SEO title: Slash Commands in the Terminal
Meta description: Use CLI slash commands productively — /run, /explain, /test.
Primary keyword: slash commands in the terminal
Secondary keywords: slash commands in the terminal
Search intent: Informational
URL slug: /copilot-cli-slash-commands-terminal
Categories: AI Tools, GitHub Copilot
Tags: GitHub Copilot, Intermediate, CLI, Slash Commands, Terminal, IMCSEIAN, Tutorial, IMCSEIAN
Featured image concept: IMCSEIAN lesson card for Slash Commands in the Terminal
Comments
Comments
Post a Comment