Sub topic 8
Slash commands for controlling a session
This chapter assumes you can start an interactive session in a project (see the earlier chapters on installing and working interactively) and that you know what the context window is. Slash commands let you steer the session itself instead of sending a prompt to the model.
What slash commands are
A slash command is a line you type at the prompt that starts with /. The tool handles it directly. It does not send the line to the model as a task. Commands change session state: they clear history, switch models, show usage, or change permissions.
Typing / alone usually opens a list of the commands available in your version. /help prints the same list with descriptions.
Common commands
Names and behavior differ between tools and change between releases. The table shows typical examples.
| Purpose | Claude Code | Codex CLI | Copilot CLI |
|---|---|---|---|
| List commands | `/help` | `/` menu | `/help` |
| Start fresh history | `/clear` | `/new` | `/clear` |
| Shrink history by summarizing | `/compact` | `/compact` | check `/help` |
| Switch model | `/model` | `/model` | `/model` |
| Create an instruction file | `/init` | `/init` | check `/help` |
| Change approvals | `/permissions` | `/approvals` | check `/help` |
| Review changes | `/review` | `/diff`, `/review` | check `/help` |
Treat the table as a starting point and confirm each command in your installed version with /help.
Commands that manage context
Two commands matter most for long sessions.
/clear(or/newin Codex CLI) discards the conversation history. Use it when you switch to an unrelated task, so old files and decisions do not distract the model./compactreplaces the history with a summary. Use it when the task is still going but the context window is filling up. Details from early in the session can be lost, so restate anything critical afterward.
Commands that manage risk
Permission commands change what the agent may do without asking. A typical use is to start in a strict mode while the agent explores, then allow test runs once you trust the plan. Lower the permissions again after the risky step. The settings files in the configuration chapter store the same choices permanently. A slash command changes them only for the current session.
A short session
> /init
> Add input validation to the signup form. Plan first, do not edit yet.
> /permissions
> /compact
> /diffHere /init drafts an instruction file, /permissions lets you adjust access, /compact frees context, and /diff (Codex CLI) shows what changed. Claude Code users can run git diff in a shell instead.
Custom commands
Claude Code and some other tools let you add your own slash commands, usually as Markdown files in a project folder. A later chapter covers them. Built-in commands always come first, so avoid reusing their names.
Exercise
You have finished a bug fix and want to start an unrelated refactor in the same terminal. Which command fits best, and why not /compact?
Show answer
Use /clear (or /new in Codex CLI). The refactor does not need the bug-fix history, so discarding it keeps the context focused. /compact keeps a summary of the old task, which still takes up space and may mislead the model.