How do you compact the context in Claude Code?

Claude Code · Built-in Slash Commands · updated 2026-08-23

/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 / SyntaxWhat it doesNotes
/add-dir <path>Add a working directory for file access during the current sessionType 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|offEnable or disable the advisor tool, which consults a second model for guidance at key moments during a taskAccepts fable, opus, sonnet, or a full model ID. fable requires Fable 5 access.
/agentsAs 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 automaticallyPass 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 promptSpawn a Claude Code on the web session that watches the current branch's PR and pushes fixes when CI fails or reviewers leave commentsDetects 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 promptDetach the current session to run as a background agent and free this terminalPass 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 parallelResearches 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 nameCreate a branch of the current conversation at this point, so you can try a different direction without losing the conversation as it standsSwitches 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 questionAsk a side question about the current session without adding to the conversationIf 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 reportReport a bug or share your conversationYou 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 cacheType 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...
/chromeConfigure Claude in Chrome settingsType the command in the Claude Code prompt.
/claude-api migrate|managed-agents-onboard|prompt-auditSkill. Load Claude API and Managed Agents reference material for your project's languageAlso 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 nameStart a new conversation with empty contextPass 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|pathSkill. Review the current diff, or a PR number, branch, or path you pass, for correctness bugs and cleanup opportunitiesPass --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|defaultSet the prompt bar color for the current sessionAvailable colors: red, blue, green, yellow, purple, orange, pink, cyan. Use default to reset, or run with no argument to pick a random color.
/compact instructionsFree up context by summarizing the conversation so farOptionally 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 preferencesFrom 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 allVisualize current context usage as a colored gridShows 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 NCopy the last assistant response to clipboardPass 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.
/costAlias for /usageType the command in the Claude Code prompt.
/dataviz requestSkill. Design guidance for charts, graphs, and dashboardsClaude 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 descriptionSkill. Enable debug logging for the current session and troubleshoot issues by reading the session debug logDebug 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 reportType the command in the Claude Code prompt.
/design-loginAuthorize design-system access for /design-sync with your claude.ai accountType the command in the Claude Code prompt.

From the Claude Code reference (111 entries) · all how-to answers