Skip to content
Back to skills

Context Audit

ASecurity

Analyze Claude Code session transcripts for repeated full-file reads, large re-derived tool output and other context-cost waste; recommend small scripts or ferrule commands (like `ferrule spec section`), or a PreToolUse guard / convention edit where the waste bypasses an existing convention. Use for "audit context cost", "reduce context bloat", "what scripts should we add", "analyze tool usage", or /context-audit.

  • 5 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 7, 2026
toolsgoshellbashgitapi

Works with

  • claude code
  • api

Security analysis

A100/100

Scanned November 7, 2026

npx -y skills add TumbleOwlee/ferrowl --skill context-audit --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Context Audit?

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

Security grade badge for Context Audit
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tumbleowlee-context-audit/badge)](https://www.skillsdirectory.com/skills/tumbleowlee-context-audit)

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: context-audit
description: Analyze Claude Code session transcripts for repeated full-file reads, large re-derived tool output and other context-cost waste; recommend small scripts or ferrule commands (like `ferrule spec section`), or a PreToolUse guard / convention edit where the waste bypasses an existing convention. Use for "audit context cost", "reduce context bloat", "what scripts should we add", "analyze tool usage", or /context-audit.
---

# Context cost audit

**Concise, compact, facts only.**

Read-only. Never write a script — recommend, user decides.

## 1. Find the transcripts

`~/.claude/projects/<project-slug>/*.jsonl`, one per session, JSON Lines. `<project-slug>` = cwd with `/` → `-`. Ask scope — this session, last N, all — default last 5.

## 2. Tally tool usage

Per session: every `Read` `input.file_path`, `Bash` `input.command`, `Grep` `input.pattern`/`input.path`. `jq` only:

```sh
jq -r 'select(.message.content != null) | .message.content[]?
  | select(.type=="tool_use" and .name=="Read") | .input.file_path' \
  ~/.claude/projects/<slug>/*.jsonl | sort | uniq -c | sort -rn
```

Same for `Bash` (`.input.command`) and `Grep` (`.input.pattern`).

## 2b. Rank cost by tool

Which tool's *results* eat most context, not which is called most. Join each `tool_result` to its `tool_use` by id, sum result size per tool, sort descending:

```sh
jq -s '
  ( [.[] | .message.content[]? | select(.type=="tool_use") | {key: .id, value: .name}] | from_entries ) as $names
  | [.[] | .message.content[]? | select(.type=="tool_result") | {name: ($names[.tool_use_id] // "unknown"), size: ((.content | tostring) | length)}]
  | group_by(.name) | map({name: .[0].name, calls: length, chars: (map(.size) | add)})
  | sort_by(-.chars)[]
  | "\(.name)\t\(.calls) calls\t~\(.chars/4|floor) tokens"
' ~/.claude/projects/<slug>/*.jsonl
```

`chars/4` is rough, good enough for ranking. `Bash` near the top → drill into which commands (section 2) drive it; that's section 3's script-candidate list.

## 3. Flag waste patterns

- **Full-file re-read, same file, ≥3 times in one session, no `Edit` between two of them.** Check the file's structure (headings, JSON keys, log sections) against what was quoted after each Read — only one part ever used = `ferrule spec section` candidate (or `jq`/`awk` slice for JSON/log). `wc -c <file>... | sort -rn` ranks repeat offenders by cost (~chars/4 tokens).
- **Large file (`wc -l`) read whole when the same heading/keyword recurs across sessions** — same pattern over time.
- **Repeated identical `Bash` command** — deterministic output (`git log`, version check) re-run instead of reasoned from context. Behavioral fix, not a script; note separately.
- **`Grep` with a large match count, re-run later with `-l`/path filter** — narrowing came a call too late.
- **`Bash` dominates section 2b** — a raw `gh`/`git`/`curl`/API command dumping full JSON/log when only a few fields get used is a ferrule command candidate shaped like `ferrule pr failed`/`ferrule issue view` (compact, pre-filtered). Require repetition across sessions before recommending.

## 4. Report

Ranked table: file/pattern, count, rough cost (`lines × occurrences` for Reads), proposed fix. One line each, no praise, no summary. Precede with section 2b's per-tool ranking, unabridged. `ferrule spec section` already covers markdown-heading slicing — recommend *extending its use*, never a duplicate. New script only when the data shape doesn't fit (JSON, log tail, CSV column).

## 5. Propose enforcement when the pattern is a bypassed convention

A recurring waste pattern that `AGENTS.md` Conventions already forbid (e.g. raw Bash `cat` of a whole `.md`/large file when `ferrule spec section`/`sed -n`/Read exist) is not a missing script — the fix exists and is routed around. For each, propose as a numbered list, most costly first:

- **A `PreToolUse` hook** detecting the exact bypass shape at the tool-call boundary and denying with a message pointing at the intended path — shape of `ferrule hook shell` (extend an existing guard covering an overlapping shape before adding one). State matcher (tool name), detection condition, redirect message.
- **A convention-wording gap**, if the bypass happened because the bullet didn't cover the observed shape (wrong tool, file type, ambiguous wording) — quote current bullet and proposed edit.

One line each: pattern → proposed fix → which file changes (a `ferrule hook shell` rule — an issue on ferrule — or the Conventions bullet).

If the user approves a specific recommendation, draft that one script: POSIX `sh`, single file, one clear job, tested against a real sample before reporting done. A recommendation that belongs in ferrule itself (a new subcommand or hook rule) is an issue on ferrule, not a script here.

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.

View all in tools →

Comments

Loading comments…

Newsletter

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