# Claude Code compact commands

> Use Claude Code compact commands, then keep instructions and memory in the right place.

Source: https://fullbytedeveloper.com/blog/claude-code-compact
Keyword: CONTEXT
Published here: 2026-11-25, updated 2026-12-03

Claude Code `/compact` summarizes the current chat so you can keep working in the same session without wiping decisions. `/clear` starts empty context for a new task. Rules that must survive either command belong in `CLAUDE.md`, not in chat history alone. [1][2]

Related reading: [Claude Code Mode on Bedrock, Foundry, Agent Platform](/blog/claude-code-mode-bedrock-foundry).

## When to compact versus clear

The commands doc separates mid-task controls from between-session ones. During work, `/context` shows what fills the window and `/compact` summarizes history to free space. Between tasks, `/clear` resets the conversation while project memory files still load next time. [1]

| Goal | Command | What changes |
| --- | --- | --- |
| Same task, less history noise | `/compact` optional focus text | Older turns become a summary; session continues [1] |
| New task, same repo | `/clear` | Empty chat; `CLAUDE.md` still applies [1][2] |
| See what is eating tokens | `/context` or `/context all` | Grid of usage plus suggestions [1] |

Optional focus after `/compact` tells the summarizer what to preserve, per the commands reference. [1]

A concrete branch-debug pattern: you spent twenty turns finding that `npm test` fails on one assertion in `auth.test.ts`. Context is nearly full. Run `/compact keep the npm test command, the failing assertion, and the file path`. The next turn still knows the repro. `/clear` at that moment throws away the paid investigation and makes you re-paste the same failing output. [1]

## Compact and context in the terminal

Documented slash commands:

```text
/compact
/compact keep the npm test command and the failing assertion
/context
/clear
```

Run `/context` before a large paste. The commands doc says the view warns when you exceed the window and points at commands that free space. [1] `/context all` adds which memory files loaded, which helps when a nested `CLAUDE.md` you forgot about is eating budget. [1][2]

If `/context` shows tool results and old diffs dominating the grid, compact with a focus line that names the decision you still need. If the grid shows mostly system and memory files, compaction will not invent room; trim `CLAUDE.md` or move path-scoped rules into nested files instead. [1][2]

## Why compaction can save a decision

ALGO ARCADE models a 16-token pipe (a teaching size, not a live Claude window). The same chat twice: without compaction the oldest message drops and the model cannot answer; with compaction old turns become one summary that still holds the name.

```bash
curl -fsSL -o context_window.py https://raw.githubusercontent.com/kamilikamil/algo-arcade/main/world2/context_window.py
python3 context_window.py
```

Captured output:

```text
== plain: a pipe of 16 tokens
[####............]   4/16  ADD       "my name is sam" (4 tokens)
...
[###############.]  15/16  DROP      "my name is sam" (4 tokens)
[###############.]  15/16  ANSWER    ?

== compact: a pipe of 16 tokens
...
[##########......]  10/16  COMPACT   "summary: my name is sam" (6 tokens)
[##########......]  10/16  ANSWER    SAM

Round 1 lost the name: it was the oldest message. Round 2 compacted the old messages and kept it.
```

That mirrors why `/compact` exists: replace evicted detail with a shorter summary instead of silently losing it. Real Claude Code uses model-written summaries, not this script. [1][6]

<figure>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 280" role="img" aria-label="When context is full: dropping oldest turns loses facts; compact replaces history with a summary; CLAUDE.md survives clear">
  <defs>
    <marker id="arrowClaudeCompact" markerWidth="10" markerHeight="10" refX="8" refY="3" orient="auto">
      <path d="M0,0 L8,3 L0,6 Z" fill="#14b8a6"/>
    </marker>
  </defs>
  <rect x="0" y="0" width="720" height="280" rx="12" fill="#0b1f3a"/>
  <text x="24" y="36" fill="#f8fafc" font-family="ui-sans-serif, system-ui, sans-serif" font-size="16" font-weight="700">Context pipe full</text>
  <rect x="24" y="56" width="312" height="72" rx="8" fill="#123052" stroke="#64748b" stroke-width="2"/>
  <text x="36" y="84" fill="#f8fafc" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">No /compact</text>
  <text x="36" y="108" fill="#cbd5e1" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">oldest turn drops</text>
  <rect x="384" y="56" width="312" height="72" rx="8" fill="#123052" stroke="#14b8a6" stroke-width="2"/>
  <text x="396" y="84" fill="#f8fafc" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">/compact</text>
  <text x="396" y="108" fill="#f59e0b" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">history becomes summary</text>
  <path d="M360 92 H384" stroke="#14b8a6" stroke-width="3" fill="none" marker-end="url(#arrowClaudeCompact)"/>
  <path d="M360 148 V176" stroke="#14b8a6" stroke-width="3" fill="none" marker-end="url(#arrowClaudeCompact)"/>
  <rect x="120" y="184" width="480" height="48" rx="8" fill="#123052" stroke="#f59e0b" stroke-width="2"/>
  <text x="132" y="214" fill="#f8fafc" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">Pin durable rules in CLAUDE.md (reloads every session)</text>
  <path d="M360 232 V252" stroke="#14b8a6" stroke-width="3" fill="none" marker-end="url(#arrowClaudeCompact)"/>
  <rect x="48" y="252" width="624" height="20" rx="4" fill="#123052"/>
  <text x="60" y="266" fill="#cbd5e1" font-family="ui-monospace, monospace" font-size="14">/clear = empty chat; CLAUDE.md + auto memory still load [1][2]</text>
</svg>
</figure>

*Compaction trades verbatim turns for a shorter summary; files and CLAUDE.md hold what must not drift.*

## Put non-negotiable rules in CLAUDE.md

Claude Code memory docs say each session starts fresh while `CLAUDE.md` and auto memory carry knowledge across sessions. Project instructions live in `./CLAUDE.md` or `./.claude/CLAUDE.md`, and Claude can read `AGENTS.md` where the repo uses that file instead. Target under 200 lines per file so instructions stay followable. [2]

Example project snippet:

```md title="CLAUDE.md"
Run npm test before changing a dependency.
Never commit secrets; stop if .env would be staged.
```

Run `/init` once if the repo has no instruction file yet; the memory guide documents that flow. [2]

Nested directories can carry their own instruction files that load when you work in that path. Keep each file focused: root for repo-wide gates, nested for package-local commands. Stuffing every preference into one global file is how `/context` starts looking full before you paste a single log. [2]

## ChatGPT and Claude app parallels

ChatGPT Custom Instructions apply across chats; Memory can reuse preferences from older conversations. [3][4] Claude app Projects hold project chats, knowledge, and instructions in one workspace. [5]

Those features resemble `CLAUDE.md` plus project files more than they resemble `/compact`. When you outgrow a long ChatGPT thread, copying a short summary into a new chat is a manual version of compaction. Claude Code documents the built-in `/compact` and `/clear` pair instead. [1]

Suggested paste prompt when you manually move chats (workflow tip, not a vendor command):

```text
Summarize this chat in five lines. Keep every decision, file path, and command we agreed on.
```

Closing the terminal without `/clear` is not the same as compacting. A new session still reloads `CLAUDE.md` and auto memory, but the previous chat's summary is gone unless you wrote decisions into a file first. [1][2] Keep a `NOTES.md` in the branch for the failing command and assertion when you know you will restart the agent overnight.

## Auto memory versus things you write

Auto memory holds notes Claude writes from corrections; `CLAUDE.md` holds instructions you author. The memory doc compares them: you edit CLAUDE files directly, while auto memory loads from `MEMORY.md` with size limits when enabled. [2]

Use auto memory for preferences that emerge over time. Use `CLAUDE.md` for commands that must never drift, such as test gates or secret-handling rules. After a productive compact, if a decision must survive the next `/clear`, promote it into `CLAUDE.md` or a ticket file in the repo before you reset. [2]

## Mistakes with compact and context

Compacting then treating the summary as a verbatim transcript. Summaries shorten text. Exact wording that still matters belongs in a file Claude can read again or in `CLAUDE.md`. [1][2]

Using `/clear` while the feature branch debug is unfinished. `/clear` wipes conversational context. Prefer `/compact` with a focus phrase when the same branch is still active. [1]

Skipping `/context` before a huge paste. Check the grid first; free space with compact or by trimming memory files before dumping multi-thousand-line logs. [1]

Stuffing everything into one global `CLAUDE.md`. Nested rules and path-scoped files load on demand; the memory guide recommends keeping each file focused. [2]

Expecting compaction to reload skills you removed. Compaction summarizes conversation; installed skills and memory files follow their own load rules. [1][2]

Treating ALGO ARCADE output as token-accurate. The script uses a 4-character-per-token estimate for teaching. Real models use their own tokenizers. [6]

Compare with [an agent tool allow list](/blog/claude-code-deny-rules) and [a 429 retry](/blog/retry-after-header-python), or browse the [Cost and context topic](https://fullbytedeveloper.com/blog/topic/cost-and-context).

When the feature branch is still active, `/compact keep the repro steps` beats `/clear` and losing the thread you already paid for in tokens.

Treat compact as a checkpoint, not a brain wipe. Before you compact a long debug thread, paste the failing command and the last error into project notes so the summary cannot drop the one fact you still need.

Send this to the friend who ran /clear on a branch debug session instead of /compact keep.

Image: A long context ribbon entering a compressing press and emerging as a smaller glowing memory capsule, while a separate instruction slab and a durable memory crystal stay outside the press untouched, rendered as unmarked geometric solids with no typography or logos.
https://fullbytedeveloper.com/media/claude-code-compact/claude-code-compact-venice.webp
Compact to shrink the live context. Keep standing instructions and memory in the right place.

## Sources

1. [Claude Code commands](https://code.claude.com/docs/en/commands)
2. [Claude Code memory](https://code.claude.com/docs/en/memory)
3. [ChatGPT custom instructions](https://help.openai.com/en/articles/8096356-custom-instructions-for-chatgpt)
4. [ChatGPT memory](https://help.openai.com/en/articles/8590148-memory-faq)
5. [Claude app projects](https://support.anthropic.com/en/articles/9517075-what-are-projects)
6. [ALGO ARCADE context-window level](https://github.com/kamilikamil/algo-arcade/blob/main/world2/context_window.py)
