save-tokens

save-tokens is a skill for Claude Code, Codex from aspenkit/aspens. It costs 30 tokens per session (1,540 once invoked), scanned A, original, MIT.

A session-management feature for Claude Code, the command-line coding agent from Anthropic, that watches token usage and saves handoff notes before a session runs out of context.

In plain words
What is it for?
Use it to show token status, warn before limits, save the current task state, rotate sessions, and resume work from saved handoffs.
Why use it?
It helps preserve work when a long session needs to be compacted or moved into a fresh session.

Skill for Claude CodeCodex

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/aspenkit/aspens/save-tokens
Any agent
npx skills add aspenkit/aspens --skill save-tokens
Clone the repo
git clone --depth 1 https://github.com/aspenkit/aspens

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 save-tokens

README.md
[![agentmods](https://agentmods.dev/badge/skills/aspenkit/aspens/save-tokens.svg)](https://agentmods.dev/skills/aspenkit/aspens/save-tokens)
Your own site
<a href="https://agentmods.dev/skills/aspenkit/aspens/save-tokens"><img src="https://agentmods.dev/badge/skills/aspenkit/aspens/save-tokens.svg" alt="Measured on agentmods" height="20"></a>
Per session 30 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,540 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.00030 $0.01540
Opus 5 $0.00015 $0.00770
Sonnet 5 $0.00006 $0.00308
Haiku 4.5 $0.00003 $0.00154

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

Security

Grade A, and why

save-tokens 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.

.agents/skills/save-tokens/SKILL.md · 64 lines

How it starts

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

You are working on save-tokens — the feature that installs Claude Code hooks and commands to warn about token usage, auto-save handoffs before compaction, and support session rotation.

Domain purpose

aspens save-tokens installs three Claude Code hooks (statusline, prompt-guard, precompact) plus /save-handoff, /resume-handoff-latest, and /resume-handoff slash commands. The hooks observe Claude's own token telemetry and inject system messages telling Claude to rotate sessions before context blow-up. Handoff files persist enough state in .aspens/sessions/ to resume seamlessly in a fresh session.

Business rules / invariants

  • Claude-only feature. Hooks and statusline only work with Claude Code; Codex has no save-tokens integration. Config lives in .aspens.json under saveTokens.
  • Config thresholds default 175k warn / 200k compact. Number.MAX_SAFE_INTEGER is the disabled sentinel for either threshold; target.js#isValidSaveTokensConfig() validates shape, types, and threshold ordering — invalid config causes readConfig() to return null.
  • writeConfig preserves feature configsaveTokens is preserved across writeConfig calls unless explicitly set to null.
  • Sessions dir gitignored.aspens/sessions/.gitignore excludes everything except .gitignore and README.md.
  • Settings backup — first install creates .claude/settings.json.bak if settings exist and no backup exists yet.
  • StatusLine pre-existence guardcanInstallSaveTokensStatusLine() refuses to overwrite an unrelated custom statusLine.command; when refused, applyStatusLineAvailability() forces both thresholds to MAX_SAFE_INTEGER and disables sessionRotation.

Non-obvious behaviors

  • Three hook entry points dispatched by subcommand. Shell wrappers (*.sh) read stdin, resolve project dir, and call save-tokens.mjs with statusline, prompt-guard, or precompact. ASPENS_PROJECT_DIR env var overrides CLAUDE_PROJECT_DIR; both fall back to cwd.
  • Statusline doubles as telemetry recorder. recordClaudeContextTelemetry() writes .aspens/sessions/claude-context.json summing input_tokens + cache_creation_input_tokens + cache_read_input_tokens + output_tokens from context_window.current_usage. Telemetry older than 5 minutes is ignored by the prompt guard.
  • Prompt-guard speaks to Claude, not the user. Above compactAtTokens: saves a handoff (reason rotation-threshold if sessionRotation, else compact-threshold) and stdout-prints an "IMPORTANT — you must tell the user" block instructing fresh session + /resume-handoff-latest. Above warnAtTokens: suggests /save-handoff. When telemetry is missing, prints a one-time link to the aspens issues page.
  • Precompact hook only fires when saveHandoff is enabled and claude.enabled !== false; reason is precompact.
  • extractSessionFacts() parses the JSONL transcript to extract originalTask (first user message, 500 char cap), recentPrompts (last 3, 200 char cap each), filesModified (Edit/Write tool_use file_path), gitCommits (regex on Bash git commit -m "..."), and branch (from gitBranch on user records). Transcript path is validated to be inside projectDir; falls back to input.prompt when transcript is missing or outside the project.
  • Transcript parsing is best-effort — all errors caught, invalid JSON lines silently skipped; returns empty facts on failure.
  • pruneOldHandoffs() keeps newest 10 *-handoff.md files by lexicographic (timestamp) sort; older are unlinked. latestHandoff() uses the same sort.
  • --recommended install is non-interactive — used standalone or invoked by doc init --recommended (which also installs agents and the doc-sync git hook).
  • --remove cleans legacy artifacts too — removes both .sh and historic .mjs variants of each hook, plus the legacy save-tokens-resume.md command; strips statusLine if it points at save-tokens and filters any hook entry whose command contains save-tokens-; nulls saveTokens in .aspens.json.

Read the full file on GitHub · 64 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 · 64 lines · 30 tokens per session scan A 8513d16ba19b

Subscribe to this mod's changes

save-tokens is a skill published in the GitHub repository aspenkit/aspens (99 stars, last pushed 20d ago), licensed MIT. It adds 30 tokens to every session and 1,540 once invoked, about $0.0002 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

plan-a-feature-to-confluence

Builds a feature specification from scratch with plan-a-feature and publishes it to a user-specified Confluence location, posting the spec as a parent page and each companion artifact (decision log, team findings, technical notes) as a child page beneath it. Use when the user wants a new feature planned, designed…

testdouble/han · 154 tokens

sw-handoff

Write a portable, secret-scrubbed handoff doc plus a diff of your uncommitted edits so another tool or machine resumes where you stopped. Use for "handoff", "out of tokens", "switch to Codex".

anton-abyzov/specweave · 48 tokens

handoff

Write a portable, secret-scrubbed handoff doc so this work can continue in any AI tool or on any machine. Use when saying "handoff", "running out of tokens", or "continue elsewhere".

anton-abyzov/specweave · 44 tokens

work-items-to-jira

Break a work-items.md file (produced by /plan-work-items) into independently-grabbable Jira tickets, one per slice, in a single Jira project. Use when you want to turn a work-items file into Jira tickets, publish work items as Jira issues, or create implementation tickets that can be worked on and tracked in Jira.…

testdouble/han · 123 tokens

spike-consumer-baseline

OI-3 spike harness — heavy consumer skill, BASELINE arm. Builds an incident post-mortem and sources the readability standard mid-workflow by reading a file directly, with NO Skill-tool call. Use only when explicitly invoked by the spike harness with a TRIALID and data path.

testdouble/han · 66 tokens

spike-consumer-adversarial

OI-3 spike harness — heavy consumer, ADVERSARIAL arm. Worst-case early-exit test: the mid-workflow Skill call has no continuation guardrail and the guidance skill ends with a final-sounding anchor. Use only when explicitly invoked by the spike harness with a TRIALID and data path.

testdouble/han · 0 tokens