Feature request: a setting/env to choose the model used for context compaction (`compactModel` / `CLAUDE_CODE_COMPACT_MODEL`)
Version
Claude Code 2.1.260, Linux (also observed on 2.1.258). No compaction-model setting appears in the CHANGELOG through 2.1.280.
Problem
The context-compaction summary (auto-compact and /compact) is generated with the session model. For sessions running on Opus- or Fable-class models this is the most expensive possible call at the moment the context is largest, and there is no way to route it to a cheaper model:
- The model configuration docs (
/docs/en/model-config) listANTHROPIC_DEFAULT_{OPUS,SONNET,HAIKU,FABLE}_MODEL,ANTHROPIC_MODEL,ANTHROPIC_DEFAULT_MODEL,CLAUDE_CODE_SUBAGENT_MODEL(_FORCE),CLAUDE_CODE_AUTO_COMPACT_WINDOWandCLAUDE_CODE_MAX_CONTEXT_TOKENS— none selects the compaction model. ANTHROPIC_SMALL_FAST_MODELis deprecated in favor ofANTHROPIC_DEFAULT_HAIKU_MODEL("haiku alias or background functionality"). Even if compaction were routed there, organizations that disallow Haiku for policy reasons cannot use it.- A
/modelswitch queued from the composer applies to the next turn, i.e. after an auto-compact has already run, so a PreCompact hook cannot redirect the call either (its output carries custom instructions, not a model).
Ask
- A
compactModelsetting insettings.jsonand aCLAUDE_CODE_COMPACT_MODELenv var, honored by both auto-compact and/compact, accepting the same aliases/IDs as--model. - (Optional) allow a PreCompact hook's JSON output to set
"model"for that one compaction. - Document which model compaction uses today.
Why it matters
Long-running agent sessions on large models compact many times a day; letting the summary run on a mid-tier model (e.g. Sonnet) cuts a large, predictable cost without changing the working model.
Related
Earlier requests for the same setting were closed by the inactivity bot without being implemented and are now locked: #12660, #16065, #49816.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗