[DOCS] SDK /compact slash command output
Status Fixed / completed
Maintainer reply None cached
Activity 5 comments · opened Sep 16, 2025 · closed Sep 29, 2025
Documentation Type
Incorrect/outdated documentation
Documentation Location
https://docs.anthropic.com/en/docs/claude-code/sdk/sdk-slash-commands#common-slash-commands
Section/Topic
SDK Slash Commands /compact
Current Documentation
The /compact command reduces the size of your conversation history by summarizing older messages while preserving important context:
import { query } from "@anthropic-ai/claude-code";
for await (const message of query({
prompt: "/compact",
options: { maxTurns: 1 }
})) {
if (message.type === "system" && message.subtype === "compact_boundary") {
console.log("Compaction completed");
console.log("Pre-compaction tokens:", message.compact_metadata.pre_tokens);
console.log("Trigger:", message.compact_metadata.trigger);
}
}
What's Wrong or Missing?
What actually gets returned from the SDK is a message type of "user" with the following content:
<local-command-stdout>Compacted </local-command-stdout>
Suggested Improvement
Either update the documentation or the code to match the expected behavior.
Impact
High - Prevents users from using a feature
Additional Context
_No response_
5 Comments
also, it doesn't create a new jsonl file with the new summary
also,
Based on the GitHub code for the Claude Code Python SDK (v0.21), it appears that internally, it still uses the Claude Code CLI to forward prompts.
In Claude Code (v1.0.117), the CLI does not yet support built-in slash commands, though custom slash commands appear to be supported.
Indeed, both the CLI and SDK support custom slash commands, but built-in slash commands like
/compactdo not function.looks like it's fixed in v1.0.128
I am seeing this event now, and also seeing the full user message of what the compact message is. will close for now
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.