Skip to content
Back to skills

Principle Trace Token Burn Loop

ASecurity

Apply when analyzing token burn or agent session spend. Prevents mistaking the top task_type or prompt_type for the root cause. Forces a trace from the session back to the loop script or plan entry point before prescribing a fix.

  • 4 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 19, 2026
ai-agentspythonshellexpress

Security analysis

A100/100

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

Scanned September 25, 2026

npx -y skills add EdbertChan/catstack --skill principle-trace-token-burn-loop --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Principle Trace Token Burn Loop?

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

Security grade badge for Principle Trace Token Burn Loop
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/edbertchan-principle-trace-token-burn-loop/badge)](https://www.skillsdirectory.com/skills/edbertchan-principle-trace-token-burn-loop)

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
---
name: principle-trace-token-burn-loop
description: >-
  Apply when analyzing token burn or agent session spend. Prevents mistaking
  the top task_type or prompt_type for the root cause. Forces a trace from the
  session back to the loop script or plan entry point before prescribing a fix.
disable-model-invocation: true
---

# Trace token burn back to the loop script

When a session miner reports a task_type or prompt_type consuming tokens, the
symptom (what the agent was doing) is not necessarily the cause (what kept
re-spawning the agent).

**Why:** session JSONL contains `cwd`, `workflow_id`, and the first user prompt,
but the scheduler name is missing. An unbounded outer loop — a worker
`intervalMs`, a `while true` shell driver, a cron plan, or a plan task with no
iteration limit — can make a cheap plan become an expensive burn.

**Pattern:**

1. Rank spend by task_type / prompt_type, then open one representative session
   file. Fleet-wide: `scripts/scan_session_tokens.py <session-dirs>` emits one
   JSONL row per session file (codex exec, codex rollout, claude, OMP formats;
   `--summary` for the agent x workload table), and is pipeable over ssh —
   `cat scan_session_tokens.py | ssh host python3 - ~/.invoker/agent-sessions
   ~/.claude/projects ~/.codex/sessions`. For a single session's pricing /
   thrash detail use `engine/skills/reflect/scripts/token_audit.py`.
1a. Check whether the burn is session-lifetime (few long sessions, context
    re-sent every turn) or run-count (many runs at a fixed per-run floor):
    `scripts/context_growth.py --summary <session.jsonl>` reports turns,
    peak/avg context, `clears` (sawtooth drops = /clear or compaction
    cycles), and gross resend total; without `--summary` it emits the raw
    per-call `{ts, ctx, out}` series. A long-running session that polls
    (ScheduleWakeup, sleep-and-recheck loops) will show turns x ~500K avg
    context; a one-shot run shows a single ramp. Cost ~= area under the
    curve, not the task size.
2. Read its `cwd` and first user prompt to map it to a plan or workflow.
3. Open that plan or worker file.
4. Look for an unbounded loop:
   - `intervalMs` without a max-tick or max-age bound
   - `while true`, `sleep`, or a cron expression
   - a plan task that calls `submitPlan` on every tick with no cooldown
   - a shell loop driver that re-enters the plan on failure
5. Before adding a worker-level cooldown or a smarter prompt, confirm the
   scheduler is not already responsible for re-running the same plan.
6. If the scheduler is unbounded, the root cause is the loop script / plan entry
   point, not the plan content.

Avoid stopping at the worker that submitted the plan. The worker may be correct
on each tick; the bug is the loop that keeps ticking.

Files in this skill

  • SKILL.md1.7 KB
  • tests/fires_example.md508 B
  • tests/stays_silent_example.md544 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.

Comments

Loading comments…

Newsletter

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