Sub topic 8
Slash commands for controlling a session
This chapter assumes you can start an interactive session in Claude Code, Codex CLI, or Copilot CLI. It also assumes you know what the context window is and have seen the permission prompts. Slash commands are how you manage a session while it runs.
What a slash command is
A slash command is a line you type at the prompt that starts with /. The tool handles it itself and does not send it to the model as a task. /clear wipes the conversation, and the model never gets a chance to "decide" to do that.
This makes slash commands different from prompts in three ways:
- They are deterministic. The same command does the same thing every time.
- They change the session, not the repository. They switch models, shrink history, show status, or change permissions.
- They cost little or nothing. Most make no model call. The exceptions, such as
/compact,/init, and/review, do call the model.
Commands that exist in all three tools
The three tools share a core set of commands. Exact names and availability change between releases, so treat the table as a map and confirm with /help in your installed version.
| Purpose | Claude Code | Codex CLI | Copilot CLI |
|---|---|---|---|
| List commands | `/help` | `/` opens a command popup | `/help` |
| Start fresh | `/clear` | `/new` | `/clear` |
| Shrink history | `/compact` | `/compact` | `/compact` |
| Switch model | `/model` | `/model` | `/model` |
| Create an instruction file | `/init` | `/init` | `/init` |
| Show session state | `/status`, `/cost`, `/context` | `/status` | `/usage`, `/context` |
| Manage MCP servers | `/mcp` | `/mcp` | `/mcp` |
| Leave | `/exit` | `/quit`, `/exit` | `/exit` |
Three groups of commands matter most in daily work.
Context control
/clear discards the whole conversation. Use it between unrelated tasks. Old messages stay in the context window and can mislead the model on the next task.
/compact replaces the history with a summary and keeps going. Claude Code accepts optional text after the command that steers the summary:
/compact Keep the failing test names and the decision to use a retry wrapperCompaction is lossy. Exact error messages, file contents, and small decisions can disappear. If a detail must survive, write it into the instruction file or a notes file in the repository.
/context (in Claude Code and Copilot CLI) shows what is using the window. Run it when answers get vaguer or slower, before you decide to compact.
Model and mode control
/model lists the models your account can use and switches to one. A common pattern is a stronger model for planning and a faster one for mechanical edits. Switching mid-session keeps the history but changes who reads it, so quality can shift.
Permission commands change what the agent may do without asking. Claude Code has /permissions for viewing and editing allow and deny rules. Codex CLI has an approvals command to change the approval policy. Newer releases may rename it, so check /help. Raising permissions mid-session is convenient, but it lasts only as long as the session unless you also save it in a settings file. The chapter on permissions covers which rules to choose.
Inspection and recovery
/status shows the active model, the working directory, and the permission setting. Check it when behavior surprises you. /diff in Codex CLI shows the current git changes. /review asks the agent to review changes. Claude Code also has /rewind, which can roll the conversation, and in some cases file edits, back to an earlier point. Treat it as a convenience and keep git as your real safety net.
Custom slash commands
You can add your own commands. In Claude Code, each Markdown file in .claude/commands/ becomes a command named after the file. Files in ~/.claude/commands/ work in every project. The file body is the prompt. The placeholder $ARGUMENTS receives whatever you type after the command name.
Fix GitHub issue number $ARGUMENTS.
1. Read the issue with `gh issue view $ARGUMENTS`.
2. Find the code responsible and explain your plan before editing.
3. Add a failing test, then make it pass.
4. Run `npm test` and `npm run lint` and report the results.Save that as .claude/commands/fix-issue.md. Then /fix-issue 214 expands to the full prompt with 214 substituted. Because the file lives in the repository, it can be committed and shared with your team.
Codex CLI and Copilot CLI have their own mechanisms for reusable prompts. Their file locations and formats differ and have changed between releases, so check each tool's documentation. The next-but-one chapters on extensibility cover hooks and subagents, which go further than saved prompts.
Common errors
- Typing a command with extra text where none is accepted.
/clear nowmay fail or be ignored. Commands take arguments only when documented. - Assuming a command exists everywhere. A habit from one tool can produce "unknown command" in another. Use
/helpfirst. - Relying on
/compactinstead of starting over. After a task ends,/clearis cleaner than a summary of work you no longer need. - Raising permissions and forgetting. A permission change made through a command persists for the session. Check
/statusor/permissionsbefore you leave a long task running. - Pasting a slash command inside a longer message. The tool recognizes a command only at the start of the input.
- Treating a custom command as trusted code. It is a prompt file. If you copy one from the internet, read it. It can tell the agent to run shell commands.
A short session example
This sequence shows how commands support one task from start to finish:
/status
/model
Plan how to fix the date parsing bug. Do not edit files yet.
...review the plan...
/compact Keep the agreed plan and the list of files to change
Implement step 1 of the plan.
/diff
/clearYou check the setup, pick a model, plan, trim history before the implementation phase, inspect the result, and reset for the next task. Only some lines are prompts. The rest control the session.
Exercise
Your session has run for two hours across three unrelated bugs, and the agent has begun mixing details from the first bug into the third. Which command do you use before starting a fourth, unrelated bug, and why not /compact?
Show answer
Use /clear (or /new in Codex CLI). The tasks are unrelated, so no history is worth keeping, and a /compact summary would still carry irrelevant details from the earlier bugs into the new task. Reserve /compact for a single long task where you need to keep the plan and key decisions.
Exercise
You want a reusable command that runs the test suite and summarizes failures. In Claude Code, where do you put the file, and how do you pass a test file name to it?
Show answer
Create a Markdown file such as .claude/commands/test-summary.md in the project (or ~/.claude/commands/ for all projects). Write the prompt in the body and include $ARGUMENTS where the file name should go. Then run /test-summary tests/date.test.ts.