How does flatten differ from compaction?
Compaction rewrites the entire history into a lossy summary. Flatten instead moves only the bulky tool output to a sidecar while keeping every user and assistant message untouched, making it lossless.

@shayaShav
基本信息
An MCP server that flattens Claude Code sessions — keeping every prompt and event verbatim while reclaiming context tokens, so you resume the exact same raw conversation at a lower token count instead of compacting it into a lossy summary. It moves bulky tool output (large file r
使用下面的配置,将此服务器添加到你的 MCP 客户端。
{
"mcpServers": {
"flatten": {
"command": "npx",
"args": [
"-y",
"flatten-mcp@latest"
]
}
}
}Flatten a Claude Code or OpenAI Codex CLI session: move bulky tool results (large text output and, for Claude, base64 image/screenshot blocks) out of the session JSONL into a backup copy, leaving a compact [FLATTENED ...] marker. The conversation reads identically — every prompt and event stays verbatim — but resumes with far fewer context tokens. Crash-safe (atomic rewrite + a single backup holding the complete session) and reversible via unflatten_session. Choose the store with agent ("claude" default, or "codex"). Reports diskBytesSaved and contextTokensSaved out of contextTokensTotal. For claude these are estimated locally, or exact when FLATTEN_COUNT_EXACT=1 and ANTHROPIC_API_KEY are both set; for codex the token savings are ALWAYS a local estimate (Anthropic count_tokens does not measure the GPT-5 tokenizer) and contextTokensTotal comes from Codex's own token_count events. With no session_id, flattens the current live session (claude); under codex "current" falls back to "last" (Codex has no live-session linkage). Also accepts a UUID, "last", "last N", or "current"; under codex a UUID reaches any rollout in the tree, while "last"/"last N"/keyword are scoped to the project dir. After flattening, /resume the session (claude) or codex resume the rollout (codex) to load the lighter copy.
Retrieve original tool result content from a flattened session, read straight from its backup. When you see [FLATTENED id=XXX tool=Read ... | text NNNB/NNL | session=YYY | ...] in the conversation, call this with the value after "id=" as tool_use_id and the value after "session=" as session_id, and set agent to match the session ("claude" default, or "codex"). Returns the original text output, or — for flattened screenshots (claude) — the actual image so you can view it again.
Reverse a flatten: re-inline every flattened tool result back into the session JSONL from the backup, restoring the session to its pre-flatten state, then delete the backup so nothing is left behind. Choose the store with agent ("claude" default, or "codex"). Under codex a UUID reaches any rollout in the tree; "last"/"current" are scoped to the project dir ("current" falls back to "last").
flatten-mcp is a Model Context Protocol server for Claude Code that reduces a session's token footprint by moving bulky tool output (large file reads, command logs, base64 screenshots) into a sidecar file, leaving a lightweight retrievable reference in its place. It preserves the exact chronological flow and all user prompts verbatim.
Requires Node.js ≥ 18 and Claude Code. Install user-wide via claude mcp add flatten -s user -- npx -y flatten-mcp@latest. To flatten a session, exit it with Ctrl‑C, then in a new Claude Code window use the /flatten latest or /flatten <session-id> command, or ask the model directly. Resume the original session afterward. Dry runs and unflatten are supported.
[FLATTENED …] markers with retrieval instructionsretrieve_flattenedCompaction rewrites the entire history into a lossy summary. Flatten instead moves only the bulky tool output to a sidecar while keeping every user and assistant message untouched, making it lossless.
Yes. `unflatten_session` re‑inlines every block from the sidecar, restoring each flattened result to its exact original value.
Node.js ≥ 18 and Claude Code. The server is installed from npm and registered as a Claude Code MCP server.
No. flatten-mcp reads Claude Code’s session store at `~/.claude/projects/*.jsonl` and is tested exclusively with Claude Code. The paths and JSONL schema are specific to it.
The session file is rewritten atomically via temp‑file‑and‑rename, and originals are written to the sidecar before removal from the session. An interrupted run never leaves a half‑written session file.
HeyLead: AI agent for LinkedIn outreach. Finds the right people, writes in your voice, follows up and handles replies, from Claude Code, Cursor, any MCP client or a web dashboard.

The Unstructured Transform MCP Server connects your ADK agent to Unstructured, a document processing platform that turns raw files into structured, AI-ready data. This integration gives your agent the ability to parse PD

MCP server for the Pocket Network agentic marketplace: search our catalog of data services and utilities and call them, paying per request in USDC on Base with x402. No account or API key. Search and describe are free; p

Discover flat-rate DeepSeek plans, model limits, API-key instructions, and coding-client setup
TruVerifAI's Panel Review is the guardian agent for AI's highest-stakes coding decisions: four frontier models argue over an AI coding agent's riskiest designs, diffs, and commits before they execute, with local review g
评论