/kstack:k-tokens [status|audit [--days N] [--project text] [--json]|apply]from K-stack
Audits local Claude Code transcripts to identify token waste from idle cache rewrites, polling, and large context. Applies optimized settings to reduce token usage and cost.
Ships in K-stack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
!node "${CLAUDE_SKILL_DIR}/scripts/k-tokens.js" status
The table above came from the k-tokens script, which ran before you read this skill. It shows the current values next to the recommended ones. Do not edit ~/.claude/settings.json or ~/.claude/CLAUDE.md yourself. Only the apply script writes them.
Pick the mode from the argument. With no argument, show the table and ask which mode: Audit, Apply.
status: show the table and stop. If it starts with k-tokens error:, say that line and stop.audit: go to Audit.apply: go to Apply.Run the audit script with the user's flags. It reads ~/.claude/projects/**/*.jsonl on this machine and sends nothing anywhere. On a large history it can take half a minute.
node "${CLAUDE_SKILL_DIR}/scripts/k-tokens-audit.js" [--days N] [--project <substring>] [--json]
Show the report as printed, then restate the "What to change" section in your own words, most valuable first. Offer to run Apply for the settings it names. Do not read the transcripts yourself.
Notes for reading the report:
Ask one AskUserQuestion call with four questions. Put the recommended option first and label it (Recommended). Skip a question whose setting already matches the recommended value in the table, and say so.
Cache TTL):
1h (Recommended): agents that wait on long builds or tests keep their cache. Otherwise an idle subagent rewrites its whole context every 5 minutes.Default (5m): removes the key.Compaction):
250k (Recommended): about one compaction per long job, and cheaper per request than a 400k window.200k, 300k.Default: removes the key, and Claude Code picks a window for the model.Subagents):
Sonnet (Recommended): an agent started without a model never silently inherits Opus.Inherit: removes the variable.Effort):
Sonnet high, Opus high (Recommended): Haiku is not touched.Leave as is.Then ask once, in plain text, whether to add the agent working rules block to ~/.claude/CLAUDE.md (default yes). It is the block between <!-- kstack-tokens: begin --> and <!-- kstack-tokens: end -->: batch tool calls, trim output, crop images, wait quietly instead of polling, keep a HANDOVER.md, one agent per job, cheap models for log summaries, subagents over teams.
Build the command from the answers. Leave out the flag for any setting the user wants unchanged:
node "${CLAUDE_SKILL_DIR}/scripts/k-tokens.js" apply [--ttl 1h|default] [--compact 250000|200000|300000|default] [--subagent-model sonnet|inherit] [--effort high] [--rules on|off] [--dry-run]
Run it once with --dry-run and show the change list. If the user accepts, run it again without the flag. The script:
settings.json as it was;~/.claude/backups/ before writing, and parses it again after the write;Finish in three lines or fewer: what changed, where the backup is, and that open sessions need a restart to read the new settings.
Checked against the Claude Code settings and environment-variable documentation on 2026-10-13.
| Choice | Key | Value |
|---|---|---|
| Subagent cache TTL | subagentPromptCacheTtl | "5m" or "1h". Needs Claude Code 2.1.242 or later. Applies to subagents, workflows and background helper requests. |
| Auto-compact window | autoCompactWindow | Tokens, a number from 100000 to 1000000. |
| Default subagent model | env.CLAUDE_CODE_SUBAGENT_MODEL | An alias such as sonnet, or a full model name. Used when an agent names no model and its definition has none. inherit is the same as unset. |
| Effort | modelSettings.<model-id>.effortLevel | low, medium, high or xhigh. Needs Claude Code 2.1.251 or later. Keyed by full model id; the script writes claude-sonnet-5-5 and claude-opus-5-5, and --models changes the list. |
env block.autoCompactWindow, so off is not offered. Default removes the key.effortLevel. It is documented, but does not apply to Opus 5.5, so the per-model form is used.ENABLE_PROMPT_CACHING_1H=1 is documented and covers both buckets, but writes cost more per token. The audit mentions it. The script does not set it.The status table prints a note when one of these is set, since each wins over the setting it matches:
CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL and FORCE_PROMPT_CACHING_5M over subagentPromptCacheTtl.CLAUDE_CODE_AUTO_COMPACT_WINDOW over autoCompactWindow.CLAUDE_CODE_SUBAGENT_MODEL_FORCE over every per-agent model choice.CLAUDE_CODE_EFFORT_LEVEL over modelSettings.Claude Code ignores the 1 hour cache while a subscription is drawing on usage credits, and an agent definition can set its own experimental.cacheTtl or model. Those win over the global setting for that agent.
What SKILL.md sets; muted values are Claude Code's defaults
14 skills in this plugin
/k-agent-timeUse when asked to improve, optimize, redesign or solve an open-ended technical problem, or before dismissing an option as too big, slow or costly. Prices effort for agents, not human-hours./k-cursor-architectDelegate focused implementation or investigation from Claude Code to the Cursor Agent CLI (cursor-agent) running Grok 4.7. Use when the user invokes /k-cursor-architect, asks Claude to hand work to Cursor or Grok, or enables session-only delegation. Session mode makes Cursor the exclusive delegation backend and blocks native Claude teammates. Never enables a global or persistent mode./k-designDesign before implementing. Opus produces the data shape, interface, file plan, failure cases, tests, and verification commands for a change, and runs a competing-designs bakeoff when the design is contested or has no precedent. Use for architecture, system or API design, implementation plans, repo restructuring, RFC-grade decisions, or from k-mode before code that crosses a function boundary./k-e2e-qaE2E and UI verification workflows. AgentController for native macOS apps (mcp__agentcontroller__*) and for iOS simulators and physical iPhones (mcp__agentcontroller-ios__*), Maestro or raw adb for Android (mcp__maestro__*), Claude in Chrome or Playwright MCP for the web. Use when running UI tests, QA automation, simulator or device testing, or driving and verifying a macOS app, iPhone, Android device, or web page./k-effortSwitch K-stack's routing level the way /effort switches session effort. Levels are lean < balanced < quality, plus burn on top. A typed level applies now and is saved as the default; add "session" to keep it to this session. Use for /k-effort, "kstack effort", "cheaper kstack routing", or "more effort on kstack"./k-exploreExplain how a subsystem works, trace a runtime flow, answer where code should live, or dig up why something was built this way (git history). Read-only. Use for "how does X work", "walk me through", "why is this like this", "where should this live", onboarding onto unfamiliar code, or from k-mode before changing a subsystem.npx claudepluginhub kasempiternal/k-stack --plugin kstackOther plugins' skills for the same job