Skip to content
Back to skills

Common Context Optimization

ASecurity

Treat this as a context-shape problem as well as a token-volume problem. A growing, frequently changing history can reduce KV-cache reuse because the model no longer sees the same prefix. Apply these controls: - Keep the prompt in a stable order: `System -> Tools -> RAG -> User`. Keep the system instructions, tool definitions, and other static material unchanged and at the front. - Make the conversation append-only. Do not insert new messages into the middle or rewrite earlier turns. Put new ...

  • 584 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added September 5, 2026
developmentgoapi

Works with

  • api

Security analysis

A100/100

Pro scans all 11 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill common-context-optimization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Common Context Optimization?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Common Context Optimization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-common-context-optimization-40d1bee6/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-common-context-optimization-40d1bee6)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
Treat this as a context-shape problem as well as a token-volume problem. A growing, frequently changing history can reduce KV-cache reuse because the model no longer sees the same prefix.

Apply these controls:

- Keep the prompt in a stable order: `System -> Tools -> RAG -> User`. Keep the system instructions, tool definitions, and other static material unchanged and at the front.
- Make the conversation append-only. Do not insert new messages into the middle or rewrite earlier turns. Put new dynamic information at the end.
- Mask oversized observations after extracting their signal. Any output over roughly 50 lines or 1 KB should be reduced to a semantic summary containing only relevant findings, IDs, errors, and next-step evidence. Never carry raw log/JSON dumps forward unnecessarily.
- Compact the older dialogue into a rolling state every 10 turns or 8,000 tokens. Preserve the original system prompt and last three messages verbatim; retain the goal, active task, status, errors, key decisions, active files, and next steps; drop chatter and superseded intermediate work.

The result should look like a stable prefix followed by a small current-state suffix, rather than a continuously rewritten transcript. For example:

```text
System: <unchanged system instructions>
Tools: <unchanged tool definitions>
RAG: <stable/relevant retrieved context>
Current_State: Goal=...; Status=...; Decisions=...; Errors=...; Next_Steps=...
Last_3_Messages: <kept verbatim>
New user/agent turn: <appended>
```

This bounds context growth, keeps the most important state visible, and maximizes the chance that the static prefix remains cacheable across API calls. Measure latency/cache behavior after adopting the stable ordering and compaction schedule to confirm the improvement.

Files in this skill

  • eval-1.baseline.md1.4 KB
  • eval-1.with-skill.md1.7 KB
  • eval-2.baseline.md1.3 KB
  • eval-2.with-skill.md1.6 KB
  • eval-3.baseline.md1.7 KB
  • eval-3.with-skill.md1.7 KB
  • trigger-1.md171 B
  • trigger-2.md162 B
  • trigger-3.md156 B
  • trigger-4.md150 B

Attribution

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

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.