Audit Agent Sessions banner
levnikolaevich levnikolaevich

Audit Agent Sessions

Security community intermediate

Description

Analyze all agent sessions from the last 3 days across Claude, Codex, and Gemini. Produce actionable optimization report. **Scope:** Multi-day batch analysis (3 days, all agents). Aggregate patterns a

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

Repository README

This is the README for levnikolaevich/claude-code-skills, shared by 22 entries in this directory. It describes the repository, not this entry specifically.


description: "Analyze agent sessions (3 days) for MCP, hooks, skills optimization opportunities with real token stats" allowed-tools: "Bash, Agent, Read, Glob, mcp__hex-line__read_file, mcp__hex-line__grep_search, mcp__hex-line__outline"

Audit Agent Sessions

Analyze all agent sessions from the last 3 days across Claude, Codex, and Gemini. Produce actionable optimization report.

**Scope:** Multi-day batch analysis (3 days, all agents). Aggregate patterns across sessions. For single-session deep analysis: `ln-002-session-analyzer`. For skill self-audit: meta-analysis protocol §7.

**Scope:** `$ARGUMENTS` — `all` (default), `mcp`, `hooks`, `skills`, `tokens`, `problems`.

Session Storage

Agent Path Format
Claude ~/.claude/projects/*/*.jsonl JSONL ({hash}.{idx}\t{json})
Codex ~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl JSONL
Gemini ~/.gemini/tmp/*/chats/session-*.json JSON (messages[] array)

Analysis Dimensions

Code Dimension Scope Filter
D1 MCP Problems & Optimization mcp, all
D2 Built-in Operations to MCP-ify mcp, all
D3 Hook Correctness & Efficiency hooks, all
D4 Cross-Agent Comparison all
D5 General Problems & Bottlenecks problems, all
D6 Skill Extraction Opportunities skills, all
D7 Skill Usage Analysis skills, all
D8 Token Statistics (real numbers) tokens, mcp, all
D9 Chronology & Trends all, mcp, tokens

Step 1: Session Inventory

Collect session file paths into temp files for all subsequent steps. Run as single bash block.

CUTOFF=$(date -d '3 days ago' +%s)
> /tmp/audit_claude.txt; > /tmp/audit_codex.txt; > /tmp/audit_gemini.txt
C_COUNT=0; C_SIZE=0; X_COUNT=0; X_SIZE=0; G_COUNT=0; G_SIZE=0

echo "=== SESSION INVENTORY (since $(date -d @$CUTOFF +%Y-%m-%d)) ==="

echo "## Claude"
for proj_dir in "$HOME/.claude/projects"/*/; do
  [ -d "$proj_dir" ] || continue
  for f in "$proj_dir"*.jsonl; do
    [ -f "$f" ] || continue
    MOD=$(stat -c %Y "$f" 2>/dev/null)
    [ -z "$MOD" ] && continue
    [ "$MOD" -lt "$CUTOFF" ] && continue
    SIZE=$(wc -c < "$f" | tr -d ' ')
    LINES=$(wc -l < "$f" | tr -d ' ')
    C_SIZE=$((C_SIZE + SIZE)); C_COUNT=$((C_COUNT + 1))
    echo "$f" >> /tmp/audit_claude.txt
    echo "  $LINES lines, ${SIZE}B: $(basename "$(dirname "$f")")/$(basename "$f")"
  done
done
echo "  Total: $C_COUNT sessions, $((C_SIZE / 1024))KB"

echo "## Codex"
for f in "$HOME/.codex/sessions"/????/??/??/rollout-*.jsonl; do
  [ -f "$f" ] || continue
  MOD=$(stat -c %Y "$f" 2>/dev/null)
  [ -z "$MOD" ] && continue
  [ "$MOD" -lt "$CUTOFF" ] && continue
  SIZE=$(wc -c < "$f" | tr -d ' ')
  X_SIZE=$((X_SIZE + SIZE)); X_COUNT=$((X_COUNT + 1))
  echo "$f" >> /tmp/audit_codex.txt
  echo "  ${SIZE}B: $(basename "$f")"
done
echo "  Total: $X_COUNT sessions, $((X_SIZE / 1024))KB"

echo "## Gemini"