
flatten-mcp
@shayaShav
flatten-mcp について
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"
]
}
}
}ツール
6Move bulky tool results into a sidecar, leaving `[FLATTENED …]` markers. Crash-safe and reversible. Supports `dry_run`, `min_size`, `force`, and `include_tool_use_result`.
Fetch one original block back by its id — returns the original text, or re-renders a flattened screenshot as a real image.
Reverse a flatten completely: re-inline every block from the sidecar, restoring each flattened result to its exact original value.
Reclaim disk by deleting leftover `.bak` / `.tmp` files (and, opt-in, sidecars). Defaults to a safe dry run.
List a project's sessions with branch, message count, size, and first prompt.
Keyword / branch / date search across past sessions — scans prose, tool I/O, **and** flatten sidecars so nothing goes dark after flattening.
概要
What is flatten-mcp?
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.
How to use flatten-mcp?
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.
Key features of flatten-mcp
- Lossless and reversible – unflatten restores every block to its exact original value
- Idempotent – re‑running skips already‑flattened blocks
- Crash‑safe – originals are persisted to sidecar before removal, with atomic file writes
- Reports both disk bytes saved and context tokens saved
- Provides compact
[FLATTENED …]markers with retrieval instructions - Includes tools for preview, retrieval, unflatten, and artifact cleanup
Use cases of flatten-mcp
- Reclaim context window space in token‑heavy sessions (around 200k–300k tokens)
- Preserve verbatim conversation history without lossy compaction
- Retrieve original block content on demand via
retrieve_flattened - Run a dedicated inexpensive model window as a flatten‑only station
FAQ from flatten-mcp
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.
Is flatten reversible?
Yes. unflatten_session re‑inlines every block from the sidecar, restoring each flattened result to its exact original value.
What are the system requirements?
Node.js ≥ 18 and Claude Code. The server is installed from npm and registered as a Claude Code MCP server.
Does flatten work with agents other than Claude Code?
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.
How does the server handle interruptions or crashes?
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.
「AI とエージェント」の他のコンテンツ
Solon Ai
opensolonJava AI application development framework (supports LLM-tool,skill; RAG; MCP; Agent-ReAct,Team-Agent). Compatible with java8 ~ java25. It can also be embedded in SpringBoot, jFinal, Vert.x, Quarkus, and other frameworks.
Hass-MCP
voskaControl and query Home Assistant from Claude and other LLMs — a Model Context Protocol (MCP) server.
LinkedIn MCP Server
stickerdanielOpen-source MCP server for LinkedIn. Give Claude and any MCP-compatible AI agent access to profiles, companies, jobs, and messages.
Sequential Thinking Multi-Agent System (MAS)
FradSerAn advanced sequential thinking process using a Multi-Agent System (MAS) built with the Agno framework and served via MCP.
MCP Server - Remote MacOs Use
baryhuangThe only general AI agent that does NOT requires extra API key, giving you full control on your local and remote MacOs from Claude Desktop App
コメント