VCode home

Compact the context automatically

Agents: claude, codex, opencode · On: phone, desktop

When a turn ends with the context over a token mark, VCode runs a compaction turn of its own before the next message goes in. You can set the mark for every tab in the settings sheet, or for one tab with /autocompact.

Why you would use it

A long thread gets slower and dearer with every turn, and eventually the agent runs out of window mid-answer. Compacting on a mark you choose keeps that from happening while you are not watching, and because it runs between turns it never lands in the middle of work.

How to use it

For every tab:

  1. Tap the cog (#settings-open) and find the Auto compact group (#settings-autocompact).
  2. Switch Enabled (#ac-enabled) on or off.
  3. Set Context tokens limit (#ac-tokens), a number with a tokens unit beside it.
  4. Optionally write a Custom prompt (#ac-prompt) saying what to keep.

The Auto compact group in the settings sheet: the Enabled switch on, the context tokens limit at 150000 tokens, and the custom prompt box.

Each field saves the moment it changes; there is no Save button. The status at the right of the group title (#settings-hint) reads Saving…, then a green check and Saved. A refused value shows in red there, for example a whole number of tokens, at least 10000.

The group's help reads Compacts tabs past the token limit., and the limit's row adds /autocompact overrides it per tab.

For one tab, type in the composer:

What you see

A system card opens in the transcript before the compaction: auto-compacting: context at 168k, over the 150k mark, with a timer counting up beside it. The activity line says COMPACTING. When it is done the same card closes with the final duration; the 30-second heartbeats the CLI sends collapse into that one card rather than adding more. Codex reports its own contextCompaction system item, which renders as compacting context… and then context compacted.

A system card in the transcript reading "context compacted — 48.2k tokens summarised into 9.1k", with its duration on the right.

If the compaction fails, the same card becomes a warning: auto-compact failed: <reason>.

The ctx segment in the status bar drops once it is done. Tapping that segment says context 168000 tokens · auto compact 150k tokens, or context 168000 tokens · auto compact default on a tab that follows the sheet.

/autocompact toasts its result, for example auto compact: 120k tokens, auto compact: off, auto compact: default.

Options and settings

Option Default What it changes
Enabled (#ac-enabled) on Whether any tab compacts on its own
Context tokens limit (#ac-tokens) 150000 The mark, in tokens. At least 10000
Custom prompt (#ac-prompt) empty Instructions for the summary. Claude only — codex and opencode take no compaction instructions. At most 4000 characters
/autocompact <n>k|off|default default This tab's own mark. off beats settings that are on; a mark beats settings that are off
VCODE_AUTO_COMPACT 150000 Seeds the mark on a state root with no settings.json yet. 0 seeds it off; anything else must be at least 10000 or the boot fails

Limits and known gaps