Skip to content

Instantly share code, notes, and snippets.

@cynthiateeters
Last active March 5, 2026 00:14
Show Gist options
  • Select an option

  • Save cynthiateeters/1336a4cea9e1eff7ff9e49a8b1e53daa to your computer and use it in GitHub Desktop.

Select an option

Save cynthiateeters/1336a4cea9e1eff7ff9e49a8b1e53daa to your computer and use it in GitHub Desktop.
Claude Code: /compact with targeted instructions

Claude Code: Faster /compact with Targeted Instructions

The bare /compact command compresses your conversation but reads everything first—tool output, file contents, web fetches, search results. That takes minutes and often loses important context.

The fix: tell it what to keep

Create ~/.claude/commands/compact-guide.md with one line:

/compact Focus on: current task, file paths modified, decisions made, user preferences stated. Drop: tool output, search results, web content, file contents already acted on.

Now /compact-guide expands to the full instruction automatically.

Why not compact.md? Claude Code has a built-in /compact command that triggers actual context compression. A custom compact.md overrides it—your instructions expand but compression never happens. Use a different name like compact-guide.md so both work.

Why it's faster

A typical session context breakdown:

Content type Share of tokens
Tool output (bash, file reads) ~50–60%
Web fetches, search results ~15–20%
Actual conversation + decisions ~15–20%
File contents already acted on ~10%

Without instructions, /compact reads all of it before writing the summary. With instructions, it skips 70–80% of the tokens entirely—only extracting the small slice that matters going forward.

Result: seconds instead of minutes, and a leaner summary with more headroom.

Customize for your workflow

Adjust the keep/drop lists to match what you need:

/compact Focus on: current task, file paths modified, decisions made, user preferences stated, open questions. Drop: tool output, search results, web content, file contents already acted on, error messages that were resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment