Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

Back to skills

Claude Code Api Compaction

ASecurity

Use when implementing server-side tolerance for Claude Code context-management fields in an Anthropic gateway, including context_management edits, cache_edits blocks, cache references, prompt cache controls, and non-streaming compact requests.

4 stars
0 votes
0 copies
0 views
Added 9/20/2026
ai-agentsbashapi

Works with

claude codeapi

Security Analysis

A100/100

Scanned 9/20/2026

Install to Claude Code

$npx -y skills add ZipperCode/lingma2api --skill claude-code-api-compaction --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Claude Code Api Compaction?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Claude Code Api Compaction
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/zippercode-claude-code-api-compaction/badge)](https://www.skillsdirectory.com/skills/zippercode-claude-code-api-compaction)

More formats (shields.io, HTML) on the badges page.

Download Zip
Files
SKILL.md
---
name: claude-code-api-compaction
description: Use when implementing server-side tolerance for Claude Code context-management fields in an Anthropic gateway, including context_management edits, cache_edits blocks, cache references, prompt cache controls, and non-streaming compact requests.
---

# Claude Code 网关上下文管理兼容

## 目标

根据本 skill,让大模型请求网关能接受 Claude Code 发来的上下文管理字段。外部网关可以不实现真实 prompt cache 或 API 侧清理,但必须容忍这些字段,避免因为扩展字段导致 `/v1/messages` 失败。

详细字段见 `references/compaction-wire-format.md`。

## 需要容忍的字段

| 位置 | 字段 | 最小处理 |
|---|---|---|
| request body | `context_management` | 可忽略或转发 |
| user content | `cache_edits` | 可忽略 |
| tool_result | `cache_reference` | 可忽略 |
| text/system/tool | `cache_control` | 可忽略 |
| request body | `betas` 包含 `context-management-*` | 可记录/透传 |

## context_management

Claude Code 可能发送:

```json
{
  "context_management": {
    "edits": [
      { "type": "clear_thinking_20251015", "keep": "all" },
      {
        "type": "clear_tool_uses_20250919",
        "trigger": { "type": "input_tokens", "value": 180000 },
        "clear_at_least": { "type": "input_tokens", "value": 140000 },
        "clear_tool_inputs": ["Bash", "Glob", "Grep", "FileRead"]
      }
    ]
  }
}
```

如果你的上游不支持这些策略,忽略即可;不要 400。

## cache_edits

Claude Code 可能在 user message content 中插入:

```json
{
  "type": "cache_edits",
  "edits": [{ "type": "delete", "cache_reference": "toolu_1" }]
}
```

不支持缓存删除时忽略该 block,并继续处理同一 user message 中的 `text` 或 `tool_result`。

## Compact 请求

压缩摘要通常走 `stream:false`,工具为空,模型可能是 Haiku/小模型。网关只需要把它当普通非流式 `/v1/messages` 请求处理。

## 实现建议

- cache 字段属于性能优化,不应成为兼容阻断点。
- 如果实现真实缓存,cache key 至少应考虑 system、messages、tools、model、betas。
- 如果不实现真实缓存,仍应返回正常 usage;cache token 字段可为 0。

Attribution

ZipperCodeZipperCode
View sourceMore from ZipperCode →
SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Related Skills

Caveman

Ultra-compressed communication mode. Cuts token usage ~75% by speaking like caveman while keeping full technical accuracy. Supports intensity levels: lite, full (default), ultra, wenyan-lite, wenyan-full, wenyan-ultra. Use when user says "caveman mode", "talk like caveman", "use caveman", "less tokens", "be brief", or invokes /caveman. Also auto-triggers when token efficiency is requested.

1023331 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

686011 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3331 votes

catchup

Recovers prior coding-agent session context by running `catchup <agent> --since-compact`, which extracts a clean summary of a previous Codex, Claude Code, Antigravity, OpenCode, or Pi Agent session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", or asks to recover/summarize a previous session before continuing. Do NOT use for the current conversation, git history, or any non-agent log.

611 votes

math-skill

A comprehensive mathematical reasoning skill for AI assistants — handles arithmetic to research-level problems with rigorous step-by-step reasoning, systematic verification, and transparent uncertainty handling

381 votes
View all in ai-agents →