context-optimization

context-optimization is a skill for Claude Code from JubaKitiashvili/context-mem. It costs 167 tokens per session (2,084 once invoked), scanned A, original, MIT.

A guide for using context-mem, a project memory system that stores, compresses, searches, and restores useful information across coding-agent sessions.

In plain words
What is it for?
Use it to observe logs or code, search saved context, restore previous sessions, detect conflicting notes, and share knowledge across projects.
Why use it?
It helps agents avoid rereading large outputs and preserve relevant project knowledge between sessions.

Skill for Claude Code

Written for Claude Code: PostToolUse hook event.

Part of the context-mem plugin — 1 skill, 6 commands, 5 hooks, 1 MCP server shipped together

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.

agentmods
npx agentmods add skills/jubakitiashvili/context-mem/context-optimization
Any agent
npx skills add JubaKitiashvili/context-mem --skill context-optimization
Clone the repo
git clone --depth 1 https://github.com/JubaKitiashvili/context-mem

Made for: Claude Code.

Or install context-mem, the plugin that ships this one along with the rest of its 1 skill, 6 commands, 5 hooks, 1 MCP server.

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 context-optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/jubakitiashvili/context-mem/context-optimization.svg)](https://agentmods.dev/skills/jubakitiashvili/context-mem/context-optimization)
Your own site
<a href="https://agentmods.dev/skills/jubakitiashvili/context-mem/context-optimization"><img src="https://agentmods.dev/badge/skills/jubakitiashvili/context-mem/context-optimization.svg" alt="Measured on agentmods" height="20"></a>
Per session 167 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,084 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found 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.00167 $0.02084
Opus 5 $0.00084 $0.01042
Sonnet 5 $0.00033 $0.00417
Haiku 4.5 $0.00017 $0.00208

Measured 6d ago against content hash 4b012cad4702, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

context-optimization 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 6d 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.

skills/context-optimization/SKILL.md · 160 lines

How it starts

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

Use context-mem to compress large tool outputs, search stored observations before re-reading files, and persist knowledge across sessions. Leverage its 14 content-aware summarizers (plus community plugins), 4-layer hybrid search (BM25 + Trigram + Levenshtein + Vector) with intent-aware adaptive reranking and block-level memory attention, cross-session memory, and cross-project knowledge transfer through 29 MCP tools. Dashboard receives real-time updates via WebSocket. Optional LLM enhancement (Ollama / OpenRouter / Claude API) is available when enabled — adds query expansion, smarter title/tag generation, contradiction explanation, and LLM summarization, all with deterministic fallback.

Core Tools

observe — After any large output (500+ tokens)

Store and compress content for later retrieval. Auto-summarizes based on content type. Built-in privacy engine auto-redacts secrets (AWS keys, GitHub tokens, JWTs, etc.) before storage.

observe(content: "<large output>", type: "log|code|error|test|commit|decision|context", source: "tool-name")

search — Before re-reading files

Search stored observations first. Adaptive reranking selects intent-specific weight vectors (causal / temporal / lookup / general) so results are scored differently based on what the query is asking. Block-level memory attention searches across four scope-based blocks (session, project, global, archive) using softmax attention to allocate the result budget, with per-block score normalization. Canonically identical queries return cached results (30s TTL).

search(query: "authentication error handler", type_filter: ["code", "error"], limit: 5)

get — After finding results via search

Retrieve full observation content by ID. Never guess IDs — always get them from search or timeline first.

get(id: "<observation-id-from-search>")

restore_session — At session start

Recover context from previous sessions. Session ID is optional — defaults to current session.

Read the full file on GitHub · 160 lines

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. 6d ago First seen · 160 lines · 167 tokens per session scan A 4b012cad4702

Subscribe to this mod's changes

context-optimization is a skill published in the GitHub repository JubaKitiashvili/context-mem (18 stars, last pushed 4mo ago), licensed MIT. It adds 167 tokens to every session and 2,084 once invoked, about $0.0008 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories