Wiping your entire terminal context just because you hit /clear instead of /compact midway through a massive refactor destroys hours of progress. Mastering Claude Code requires knowing exactly which tool prevents context collapse while you stay deep in the zone.

  • Environment: Claude Code CLI (terminal-based)
  • Primary cost constraint: token limits per session
  • Core context workflow: /compact, then /plan, then /diff
  • Emergency rollback: /rewind (restores previous state)
  • Background tasks: /btw (executes without breaking current context)

Managing Context: /compact vs /clear vs /rewind

When you prefer to work continuously and knock out every task before taking a break, managing your token window becomes critical. Let the context bloat, and the AI starts hallucinating; clear it too early, and you lose your ongoing logic.

When to use /compact

The /compact command compresses the conversation history while retaining the core logic and file references. Use this when the prompt window gets heavy but the task is only half done. Run it plain (/compact) or point it at what matters with /compact keep the auth refactor context, drop the earlier debugging. Either way it frees up token space without forcing you to re-explain the entire architecture.

Why /rewind is safer than /clear

The /clear command is the nuclear option. It completely wipes the slate clean, dropping all memory of your current workspace.

The /rewind command simply steps back one or more turns. If a generated component goes entirely off the rails, rewind undoes the mistake without forcing you to re-establish the baseline rules for the rest of your session. You keep the good parts and discard the immediate error. Type /rewind alone to get a picker of recent checkpoints, code and conversation, so you can choose exactly how far back to go instead of guessing.

Branching out with /branch

Use /branch to fork the current conversation into a new, independent session at this exact point. Both copies share everything up to now, then diverge, so it's built for isolating risky experiments. Test a wild architectural idea in the branch, and if it doesn't pan out, your original session is untouched; just switch back.

The Refactoring Combo: /plan, /diff, and /review

Firing off vague requests leads to messy codebases and wasted API calls. Structuring the sequence guarantees precision.

Advertisement

Structuring complex changes with /plan

Start every major feature with /plan. This forces the AI to outline the file modifications, imports, and logic steps before writing a single line of actual code. You get to course-correct the architecture before spending tokens on execution.

Catching errors with /diff before committing

Once the code generates, run /diff. Reviewing the exact line changes prevents broken logic or rogue console logs from slipping into your production branch. When a teammate needs to sign off on the change, a clean verified diff makes the review frictionless: they see exactly what moved instead of re-reading the whole file.

Handling Mid-Task Interruptions Without Losing Progress

Deep focus requires zero context switching. Nothing ruins momentum faster than abandoning a complex API route to fix a minor CSS typo in a different folder.

How the /btw command saves your context

Instead of stopping your primary task, type /btw fix the typo in utils.js. The AI handles the side quest without touching your main flow. Your current conversational context remains completely untouched, letting you execute small parallel fixes instantly.

Automating the Boring Stuff: /loop and /schedule

Manual intervention slows down routine debugging. /loop 5m reruns a task on an interval you set, useful for babysitting a build or a test suite while you're still at the keyboard; it dies the moment you close the session. /schedule is the unattended version: it creates a task that fires on a cron schedule whether or not your machine is even on. Reach for /loop when you're watching something happen right now; reach for /schedule when the task needs to run without you.

Hidden Claude Code Commands You Actually Need

Beyond the standard file manipulation, a few undocumented or lesser-known commands drastically change how the CLI behaves.

Unlocking deep reasoning with ULTRATHINK

Sometimes standard generation falls short on complex logic algorithms. Typing ULTRATHINK anywhere in your prompt forces the model into its maximum reasoning mode, exposing more of its step-by-step logic before it commits to an answer. It slows down the output but drastically reduces logic errors in math-heavy or highly concurrent code. Save it for the one gnarly function, not your entire session: the extra reasoning costs tokens too.

Advertisement

Using /advisor and skill-creator

/advisor doesn't itself solve anything, it sets which model gets consulted when your main model hits an ambiguous call: an unclear failure, a tradeoff between two valid designs, or right before it declares a task finished. Run /advisor once to pick the model, and the escalation happens automatically at those moments from then on, not on every response. It's an Anthropic API feature, so it won't show up if you're running Claude Code through Bedrock or another cloud provider.

skill-creator is the meta-skill for building your own skills. Install it, then point it at a repetitive workflow (your git routine, a recurring bash sequence) and it walks you through turning that into a permanent, reusable skill instead of re-explaining the same steps every session.

I started using /branch after losing an entire working session to a /clear I fired off by muscle memory during a monorepo migration. Now anything experimental gets its own branch before I touch it, and /clear is reserved for when a conversation is genuinely done, not as a reset button for a task that just feels stuck.

If you are also running Claude Dispatch to trigger sessions from your phone, /schedule is what turns that into a real unattended pipeline instead of something you still have to babysit from bed.