All docs

Expand Tool

The expand tool is the mechanism that makes Squeezr's compression lossless. When content is compressed, the model receives a summary plus an ID. If the model needs the full original content, it calls the squeezr_expand tool with that ID.

How it works

The expand mechanism follows five steps:

  1. Compression — When Squeezr compresses a tool result, it stores the full original content in the expand store (in-memory, keyed by a 6-character ID).
  2. Marker insertion — The compressed output includes a marker like [squeezr:a3f2b1 -65%] that tells the model the content was compressed and provides the ID.
  3. Tool injection — Squeezr injects a squeezr_expand tool definition into the API request so the model knows it can retrieve full content.
  4. Model calls expand — If the model determines it needs the full content (e.g., to find a specific line in a file read), it calls squeezr_expand with the ID.
  5. Proxy intercepts — Squeezr intercepts the expand tool call in the model's response, looks up the ID in the expand store, and returns the full original content as the tool result in the next request.

Compressed format

When content is compressed, it follows this format:

[squeezr:ID -SAVINGS%] SUMMARY

Example:
[squeezr:a3f2b1 -65%] Git diff: 3 files changed.
- src/auth.ts: Added JWT validation in login handler (lines 45-67)
- src/middleware.ts: Added auth middleware check
- tests/auth.test.ts: 2 new test cases for JWT flow

ERRORS:
- Line 52: Missing return type annotation

The summary preserves all actionable information: errors, warnings, file paths, line numbers, and key changes. Only boilerplate and repetition are removed.

Tool definition (Anthropic format)

For Anthropic API requests, Squeezr injects this tool definition:

{
  "name": "squeezr_expand",
  "description": "Retrieve the full original content of a Squeezr-compressed tool result. Use this when you need more detail than the compressed summary provides.",
  "input_schema": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string",
        "description": "The 6-char ID from [squeezr:ID] in the compressed content"
      }
    },
    "required": ["id"]
  }
}

Tool definition (OpenAI format)

For OpenAI-compatible requests, the tool is injected in function calling format:

{
  "type": "function",
  "function": {
    "name": "squeezr_expand",
    "description": "Retrieve the full original content of a Squeezr-compressed tool result. Use this when you need more detail than the compressed summary provides.",
    "parameters": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "The 6-char ID from [squeezr:ID] in the compressed content"
        }
      },
      "required": ["id"]
    }
  }
}

Behavior

When does the model call expand?

In practice, models call expand rarely — typically less than 5% of compressed blocks are expanded. This is because the compression summaries are designed to include all actionable information. The model only needs to expand when:

  • It needs to reference a specific line number in a file.
  • It needs the exact syntax of code that was summarized.
  • The compression was too aggressive for the specific task.

What happens if the ID is expired?

Expand IDs are scoped to the proxy session. If the proxy restarts, all IDs from the previous session become invalid. If the model tries to expand an expired ID, it receives a message:

{
  "error": "Content not found. The ID may have expired or the proxy may have restarted. Ask the user to re-read the file or re-run the command."
}

Performance

Expand calls are served from memory and are extremely fast (typically under 5ms). They do not count against API rate limits since they are handled entirely by the proxy.

Streaming compatibility

The expand tool works with streaming responses. When the model generates an expand tool call during streaming, Squeezr detects it in the stream, resolves the ID, and includes the full content in the next request from the coding tool.