claude-code-api-compaction

Implements gateway tolerance for Claude Code context-management fields in Anthropic API requests.

4|1|Updated Apr 29, 2026
One-click install
npx skills add https://github.com/ZipperCode/lingma2api --skill claude-code-api-compaction-zippercode
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: claude-code-api-compaction
Source: https://github.com/ZipperCode/lingma2api/tree/main/.claude/skills/claude-code-api-compaction
Command: npx skills add https://github.com/ZipperCode/lingma2api --skill claude-code-api-compaction-zippercode

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Claude Code clients send context-management fields (context_management, cache_edits, cache_reference, cache_control) that cause Anthropic-compatible gateways to reject /v1/messages requests with 400 errors when the gateway does not recognize these extension fields. ## Core Features & Use Cases - Field Tolerance Rules: Defines minimum handling for context_management edits, cache_edits blocks, cache_reference in tool_result, cache_control markers, and context-management-* betas so they can be ignored or forwarded without failing requests. - Wire Format Reference: Documents the exact JSON shapes of clear_tool_uses_20250919, clear_thinking_20251015, cache_control, cache_reference, and cache_edits payloads. - Compact Request Handling: Treats non-streaming compaction summary requests (stream:false, no tools, small models) as ordinary /v1/messages calls. - Use Case: When building an OpenAI-to-Anthropic proxy, apply this Skill so Claude Code sessions with prompt caching and context compaction continue working even though the upstream does not implement real prompt caching. ## Quick Start Use this skill to make my Anthropic gateway tolerate Claude Code context_management and cache fields without returning 400 errors.

Frequently Asked Questions about claude-code-api-compaction

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle Claude Code context_management fields in an Anthropic gateway?

Accept the context_management object and its edits array (clear_tool_uses_20250919, clear_thinking_20251015) by ignoring or forwarding them. Do not return a 400 error even if your upstream does not implement these clearing strategies.

What is the cache_edits block in Claude Code requests?

cache_edits is a content block in user messages containing edit operations like deleting a cache_reference. Gateways without real prompt caching should ignore this block and continue processing the text or tool_result content in the same message.

Does my proxy need real prompt caching to support Claude Code?

No. Cache fields are performance optimizations and must not block compatibility. You can ignore cache_control and cache_reference, and return usage with cache_read_input_tokens and cache_creation_input_tokens set to 0.

Why does /v1/messages return 400 errors with Claude Code clients?

The gateway likely rejects unknown extension fields such as context_management, cache_edits, or context-management-* betas. Fix this by tolerating these fields instead of strict-validating the request schema.

How should compaction requests from Claude Code be processed?

Treat them as ordinary non-streaming /v1/messages requests. They typically use stream:false, no tools, and a small model like Haiku, so no special handling is required beyond normal request forwarding.