How do you compact the context in Claude Code?
/compact instructions — Free up context by summarizing the conversation so far
Type /compact to summarize the conversation so far and free up context. You can pass focus instructions after the command (for example /compact keep the test failures) to steer what the summary preserves. Cursor's equivalent is /summarize and Codex CLI's is /compact.
Related Claude Code shortcuts: Built-in Slash Commands (first 25 of 106)
| Command / Syntax | What it does | Notes |
|---|---|---|
| /add-dir <path> | Add a working directory for file access during the current session | Type a partial path to see matching directory suggestions; press Tab to accept one. Most .claude/ configuration is not discovered from the added directory. |
| /advisor model|off | Enable or disable the advisor tool, which consults a second model for guidance at key moments during a task | Accepts fable, opus, sonnet, or a full model ID. fable requires Fable 5 access. |
| /agents | As of v2.1.198, running /agents prints a reminder to ask Claude to create or manage subagents, or to edit .claude/agents/ or... | On v2.1.197 and earlier, opens an interactive interface for creating and managing subagent configurations |
| /autocompact auto|<tokens> | Set the auto-compact window: how full the context window gets before Claude Code compacts automatically | Pass a size such as 500k, or auto to return to the window tuned for your model. Claude Code saves the value to user settings and applies it to the current session. |
| /autofix-pr prompt | Spawn a Claude Code on the web session that watches the current branch's PR and pushes fixes when CI fails or reviewers leave comments | Detects the open PR from your checked-out branch with gh pr view; to watch a different PR, check out its branch first. By default the cloud session is told to fix every CI failure and review... |
| /background prompt | Detach the current session to run as a background agent and free this terminal | Pass a prompt to send one more instruction before detaching. Monitor the session with claude agents. |
| /batch <instruction> | Skill. Orchestrate large-scale changes across a codebase in parallel | Researches the codebase, decomposes the work into 5 to 30 independent units, and presents a plan. Once approved, spawns one background subagent per unit in an isolated git worktree. |
| /branch name | Create a branch of the current conversation at this point, so you can try a different direction without losing the conversation as it stands | Switches you into the branch and preserves the original, which you can return to with /resume. To run a copy as a separate background session instead of switching into it, use /fork; to hand a... |
| /btw question | Ask a side question about the current session without adding to the conversation | If you run /btw without a question, Claude Code shows your most recent side question so you can browse earlier answers; if you haven't asked one yet, Claude Code prints a usage line. Before... |
| /bug report | Report a bug or share your conversation | You choose how much session history to include and confirm on a consent screen before anything is sent. When you're signed in to Anthropic on a first-party connection, the report goes to... |
| /cd <path> | Move this session to a new working directory, keeping the conversation and its prompt cache | Type a partial path to see matching directory suggestions; press Tab to accept one. Claude Code prompts you to trust the workspace if you haven't worked in it before, and --resume finds the moved... |
| /chrome | Configure Claude in Chrome settings | Type the command in the Claude Code prompt. |
| /claude-api migrate|managed-agents-onboard|prompt-audit | Skill. Load Claude API and Managed Agents reference material for your project's language | Also activates automatically when your code imports anthropic or @anthropic-ai/sdk. Run migrate to upgrade existing Claude API code to a newer model, managed-agents-onboard for a walkthrough that... |
| /clear name | Start a new conversation with empty context | Pass a name to label the previous conversation in the /resume picker. To free up context while continuing the same conversation, use /compact instead. |
| /code-review low|medium|high|xhigh|max|ultra --fix --comment pr#|branch|path | Skill. Review the current diff, or a PR number, branch, or path you pass, for correctness bugs and cleanup opportunities | Pass --fix to apply findings, --comment to post them as inline GitHub PR comments, or ultra to run a deep cloud review. With ultra on a github.com PR target, --post preselects posting the finished... |
| /color color|default | Set the prompt bar color for the current session | Available colors: red, blue, green, yellow, purple, orange, pink, cyan. Use default to reset, or run with no argument to pick a random color. |
| /compact instructions | Free up context by summarizing the conversation so far | Optionally pass focus instructions for the summary. See how compaction handles rules, skills, and memory files |
| /config key=value ... | Open the Settings interface to adjust theme, model, output style, and other preferences | From v2.1.181, pass one or more key=value pairs to set a setting directly without opening the interface, for example /config thinking=false. From v2.1.182, named shorthand keys are also accepted,... |
| /context all | Visualize current context usage as a colored grid | Shows optimization suggestions for context-heavy tools, memory bloat, and capacity warnings. When the conversation exceeds the context window, the output includes a warning showing how far over... |
| /copy N | Copy the last assistant response to clipboard | Pass a number N to copy the Nth-latest response: /copy 2 copies the second-to-last. When code blocks are present, shows an interactive picker to select individual blocks or the full response. |
| /cost | Alias for /usage | Type the command in the Claude Code prompt. |
| /dataviz request | Skill. Design guidance for charts, graphs, and dashboards | Claude picks the chart form for the data, assigns color by role, validates the palette for colorblind safety and contrast with a bundled script, and applies mark, interaction, and accessibility... |
| /debug description | Skill. Enable debug logging for the current session and troubleshoot issues by reading the session debug log | Debug logging is off by default unless you started with claude --debug, so running /debug mid-session starts capturing logs from that point forward. Optionally describe the issue to focus the analysis |
| /deep-research <question> | Workflow. Fan out web searches on a question, fetch and cross-check sources, and synthesize a cited report | Type the command in the Claude Code prompt. |
| /design-login | Authorize design-system access for /design-sync with your claude.ai account | Type the command in the Claude Code prompt. |
From the Claude Code reference (111 entries) · all how-to answers