MCPcopy
hub / github.com/claude-code-best/claude-code / call

Function call

src/commands/compact/compact.ts:41–138  ·  view source on GitHub ↗
(args, context)

Source from the content-addressed store, hash-verified

39/* eslint-enable @typescript-eslint/no-require-imports */
40
41export const call: LocalCommandCall = async (args, context) => {
42 const { abortController } = context
43 let { messages } = context
44
45 // REPL keeps snipped messages for UI scrollback — project so the compact
46 // model doesn't summarize content that was intentionally removed.
47 messages = getMessagesAfterCompactBoundary(messages)
48
49 if (messages.length === 0) {
50 throw new Error('No messages to compact')
51 }
52
53 const customInstructions = args.trim()
54
55 try {
56 // Try session memory compaction first if no custom instructions
57 // (session memory compaction doesn't support custom instructions)
58 if (!customInstructions) {
59 const sessionMemoryResult = await trySessionMemoryCompaction(
60 messages,
61 context.agentId,
62 )
63 if (sessionMemoryResult) {
64 getUserContext.cache.clear?.()
65 runPostCompactCleanup()
66 // Reset cache read baseline so the post-compact drop isn't flagged
67 // as a break. compactConversation does this internally; SM-compact doesn't.
68 if (feature('PROMPT_CACHE_BREAK_DETECTION')) {
69 notifyCompaction(
70 context.options.querySource ?? 'compact',
71 context.agentId,
72 )
73 }
74 markPostCompaction()
75 // Suppress warning immediately after successful compaction
76 suppressCompactWarning()
77
78 return {
79 type: 'compact',
80 compactionResult: sessionMemoryResult,
81 displayText: buildDisplayText(context),
82 }
83 }
84 }
85
86 // Reactive-only mode: route /compact through the reactive path.
87 // Checked after session-memory (that path is cheap and orthogonal).
88 if (reactiveCompact?.isReactiveOnlyMode()) {
89 return await compactViaReactive(
90 messages,
91 context,
92 customInstructions,
93 reactiveCompact,
94 )
95 }
96
97 // Fall back to traditional compaction
98 // Run microcompact first to reduce tokens before summarization

Callers

nothing calls this directly

Calls 15

runPostCompactCleanupFunction · 0.85
notifyCompactionFunction · 0.85
markPostCompactionFunction · 0.85
suppressCompactWarningFunction · 0.85
buildDisplayTextFunction · 0.85
compactViaReactiveFunction · 0.85
microcompactMessagesFunction · 0.85
compactConversationFunction · 0.85
getCacheSharingParamsFunction · 0.85

Tested by

no test coverage detected