pi-loop-forensics

pi-loop-forensics is a skill for Claude Code, Codex from dimetron/pi-go. It costs 65 tokens per session (2,154 once invoked), scanned A, original, MIT.

A diagnostic guide for investigating pi-go agent loops, such as repeated tool calls or long turns with no tool use. It separates model repetition from tool parsing errors, race conditions, and overly strict safeguards.

In plain words
What is it for?
Use it to inspect session logs and state, understand loop-detection rules, and compare replayed sessions across model providers.
Why use it?
The message that an agent loop was aborted describes the symptom, not the cause. This guide helps identify the underlying failure before changing code or settings.

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/dimetron/pi-go/pi-loop-forensics
Any agent
npx skills add dimetron/pi-go --skill pi-loop-forensics
Clone the repo
git clone --depth 1 https://github.com/dimetron/pi-go

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 pi-loop-forensics

README.md
[![agentmods](https://agentmods.dev/badge/skills/dimetron/pi-go/pi-loop-forensics.svg)](https://agentmods.dev/skills/dimetron/pi-go/pi-loop-forensics)
Your own site
<a href="https://agentmods.dev/skills/dimetron/pi-go/pi-loop-forensics"><img src="https://agentmods.dev/badge/skills/dimetron/pi-go/pi-loop-forensics.svg" alt="Measured on agentmods" height="20"></a>
Per session 65 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,154 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 $0.00065 $0.02154
Opus 5 $0.00032 $0.01077
Sonnet 5 $0.00013 $0.00431
Haiku 4.5 $0.00006 $0.00215

Measured 4d ago against content hash c1f16ec5158e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

pi-loop-forensics 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 4d ago.

The scan reads SKILL.md. This mod also ships 3 executable files (ab_replay.sh, scan_logs.py, score_run.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

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.

.pi-go/skills/pi-loop-forensics/SKILL.md · 169 lines

How it starts

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

Loop Forensics

Use when a run dies with agent loop aborted: ..., or a model burns a long turn thinking without ever calling a tool. This skill decides why before anything is changed: the abort message names a symptom, not a cause.

Sibling skill pi-check-session-logs covers tool call errors. This one covers repetition and runaway turns. They do not overlap.

Where the evidence lives

What Path
Session logs (JSONL, one per run) ~/.pi-go/log/<yyyy-mm-dd>/session-HH-MM-SS.log
Session state (resumable) ~/.pi-go/sessions/<id>/events.jsonl, meta.json, trajectory.atif.json
Detector source internal/tui/agent_loop.go

Log rows are {"time","type","content",...} with type in session_start, thinking, llm_text, tool_call, tool_result, user, error. The model name is on the session_start row — always record it, findings are per-model.

How the guard actually works

stuckDetector (internal/tui/agent_loop.go:119) has three independent arms:

  • observe — identical consecutive tool calls, trips at maxRepeatToolCalls=10. Pagination args are stripped first (volatileToolArgs), so paging one file collapses to one fingerprint.
  • observeError — same tool failing maxToolErrorStreak=10 times running.
  • observeOutput (:246) — the model's own text/thinking. Needs a period ≥ minOutputPeriod=16 bytes, ≥ minPeriodVariety=8 distinct bytes, and maxOutputRepeats=12 byte-exact back-to-back copies inside an 8 KB tail.

The third arm is the only one that sees a turn making no tool calls at all. outBuf is never reset across a run, and the thinking branch (:690) skips dedup.SkipText, unlike the text branch (:697).

Timeline caveat — check this before judging any old log. Sessions predating these commits cannot be compared against current behavior:

Commit Landed Effect
e069b34 2026-08-08 06:56:44 +0200 added observeOutput (the phrase-repetition arm)
5a4cb8b 2026-08-08 18:52:42 +0200 stopped aborting productive polling (bash_output)

Read the full file on GitHub · 169 lines

Files

What ships with it

3 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. 4d ago First seen · 169 lines · 65 tokens per session scan A c1f16ec5158e

Subscribe to this mod's changes

pi-loop-forensics is a skill published in the GitHub repository dimetron/pi-go (151 stars, last pushed today), licensed MIT. It adds 65 tokens to every session and 2,154 once invoked, about $0.0003 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.