knowledge-session-state-and-context-context-compaction-token-budget-and-memory

knowledge-session-state-and-context-context-compaction-token-budget-and-memory is a skill for Claude Code, Codex from echoVic/blade-code. It costs 140 tokens per session (1,891 once invoked), scanned A, a copy of knowledge-session-state-and-context, MIT.

A context and project-memory component that controls how much conversation the model can see and preserves useful information across sessions.

In plain words
What is it for?
It is for tracking token usage, shortening context when needed, loading project memory, and extracting selected knowledge after context compression.
Why use it?
Long conversations can exceed a model's input limit, while important project knowledge can otherwise disappear between sessions. It separates short-term context reduction from longer-term project memory.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit It is for tracking token usage, shortening context when needed, loading project memory, and extracting selected knowledge after context compression.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/echovic/blade-code/context-compaction-token-budget-and-memory
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add echoVic/blade-code --skill context-compaction-token-budget-and-memory
Clone the repo
git clone --depth 1 https://github.com/echoVic/blade-code

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for knowledge-session-state-and-context-context-compaction-token-budget-and-memory

README.md
[![agentmods](https://agentmods.dev/badge/skills/echovic/blade-code/context-compaction-token-budget-and-memory.svg)](https://agentmods.dev/skills/echovic/blade-code/context-compaction-token-budget-and-memory)
Your own site
<a href="https://agentmods.dev/skills/echovic/blade-code/context-compaction-token-budget-and-memory"><img src="https://agentmods.dev/badge/skills/echovic/blade-code/context-compaction-token-budget-and-memory.svg" alt="Measured on agentmods" height="20"></a>
Per session 140 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,891 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin 88% copy Near-identical to another mod in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00140 $0.01891
Opus 5 $0.00070 $0.00945
Sonnet 5 $0.00028 $0.00378
Haiku 4.5 $0.00014 $0.00189

Measured 3d ago against content hash b01d4c018429, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

knowledge-session-state-and-context-context-compaction-token-budget-and-memory scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

This is a copy

88% identical to knowledge-session-state-and-context — 73 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

.trae/knowledges/session-state-and-context/context-compaction-token-budget-and-memory/SKILL.md · 58 lines

How it starts

The opening of the file, as written. The whole thing — 58 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Module Structure

该节点区分两种不同持久边界:compaction 只替换当前 Session 的模型可见上下文,Auto Memory 则把显式或启发式知识写入项目级文件供后续 Session 使用。二者只在成功压缩后的异步 consolidation 处相交。

Directory Layout

  • packages/cli/src/context/:Token 投影、handoff、snip、LLM/fallback 压缩与 replacement checkpoint
  • packages/cli/src/agent/loop/executeLoopGenerator.ts:每次 Provider 边界前协调上下文预算
  • packages/cli/src/services/SessionService.ts:分别加载完整 UI 历史与 replacement 后模型上下文
  • packages/cli/src/memory/:项目记忆索引、主题文件和压缩后启发式提取
  • packages/cli/src/tools/builtin/memory/:MemoryRead 与 MemoryWrite 工具适配
  • packages/cli/src/prompts/builder.ts:把有界 MEMORY.md 索引注入新模型上下文

Key Entry Points

  • checkAndCompactInLoop() in packages/cli/src/agent/loop/executeLoopGenerator.ts:每次 Provider 请求前的分层压缩协调
  • CompactionService.compact() in packages/cli/src/context/CompactionService.ts:LLM 摘要与 deterministic fallback
  • PersistentStore.saveCompaction() in packages/cli/src/context/storage/PersistentStore.ts:原子保存 replacement checkpoint
  • AutoMemoryManager.loadIndex() in packages/cli/src/memory/AutoMemoryManager.ts:启动时读取有界项目记忆
  • consolidateAfterCompaction() in packages/cli/src/memory/MemoryConsolidation.ts:从被压缩消息启发式提取项目记忆

Gotchas

  • ContextManager 已是 PersistentStore 薄门面,不拥有当前 Session 内存、filter 或 compaction;新增 runtime 上下文逻辑应接入 Agent loop/CompactionService,而不是恢复旧式 manager 状态 (packages/cli/src/context/ContextManager.ts, git:a074815b)
  • ContextAssembler 目前只有测试消费者,ContextCompressorContextFilter 没有生产调用点;修改这些类不会改变实际 Agent loop 的模型上下文 (packages/cli/src/context/ContextAssembler.ts, packages/cli/src/context/processors/ContextCompressor.ts, packages/cli/src/context/processors/ContextFilter.ts)
  • checkAndCompactInLoop() 的顺序是 cache-expiry micro compact、普通 snip、80% LLM compaction;snip 结果延迟应用,确保 LLM compaction 被取消或 checkpoint 失败时不会留下半更新内存 (packages/cli/src/agent/loop/executeLoopGenerator.ts)
  • replacement 必须先通过 saveCompaction() fsync 到 JSONL,再替换内存并重试 Provider;checkpoint commit 失败时本轮以 checkpoint phase 失败,不能仅在内存继续 (packages/cli/src/agent/loop/conversationPersistence.ts, packages/cli/src/agent/loop/executeLoopGenerator.ts)
  • 完整 transcript 始终保留,loadSessionModelContext() 只使用最新有效 replacement checkpoint 加其后事件;UI、搜索和导出仍看 materialized 完整历史 (packages/cli/src/services/SessionService.ts, packages/cli/src/context/compactionCheckpoint.ts)
  • computeAdaptiveBudget() 当前只有测试调用,生产 loop 仍使用默认 MessageBudgetTracker 与默认单结果预算;只修改 adaptive 函数不会改变实际 tool result 截断 (packages/cli/src/context/ToolResultBudget.ts, packages/cli/src/agent/loop/executeLoopGenerator.ts)
  • 压缩后 memory consolidation 是 fire-and-forget 且吞掉失败,并使用进程 getCwd() 建立项目记忆;多 workspace/worktree 调用不能把它当作 checkpoint 成功条件或精确 active-workspace 写入 (packages/cli/src/context/CompactionService.ts, packages/cli/src/memory/MemoryConsolidation.ts)
  • MemoryWrite 的敏感信息检查是少量正则启发式,不是通用 secret scanner;通过检查不代表内容适合持久化 (packages/cli/src/tools/builtin/memory/MemoryWriteTool.ts)

Read the full file on GitHub · 58 lines

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 58 lines · 140 tokens per session scan A b01d4c018429

Subscribe to this mod's changes

knowledge-session-state-and-context-context-compaction-token-budget-and-memory is a skill published in the GitHub repository echoVic/blade-code (178 stars, last pushed yesterday), licensed MIT. It adds 140 tokens to every session and 1,891 once invoked, about $0.0007 per session on Opus 5. A static security scan graded it A with 0 findings. It is 88% identical to knowledge-session-state-and-context, differing in 73 lines, and is treated as a copy.

Related

Other skills, from other repositories

algorithmic-art

Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright…

alleneee/skill-agent · 62 tokens

mcp-builder

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external agents through well-designed tools. Use when building MCP servers to integrate external APIs or agents, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

alleneee/skill-agent · 61 tokens

slack-gif-creator

Toolkit for creating animated GIFs optimized for Slack, with validators for size constraints and composable animation primitives. This skill applies when users request animated GIFs or emoji animations for Slack from descriptions like "make me a GIF for Slack of X doing Y".

alleneee/skill-agent · 57 tokens

canvas-design

Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.

alleneee/skill-agent · 59 tokens

self-improvement

A process for recording useful lessons from unexpected failures, user corrections, missing abilities, and reusable project patterns.

alleneee/skill-agent · 60 tokens

travel-planner

Creates comprehensive travel itineraries with destination analysis, budget planning, transportation, accommodation, and local insights. Use when planning trips, organizing travel schedules, or seeking destination recommendations.

alleneee/skill-agent · 38 tokens