ln-002-session-analyzer

Analyzes current or recent session for errors, inefficiencies, and improvement opportunities across skills, tools, hooks, and communication. Use after completing a task or periodically.

310 stars

Best use case

ln-002-session-analyzer is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Analyzes current or recent session for errors, inefficiencies, and improvement opportunities across skills, tools, hooks, and communication. Use after completing a task or periodically.

Teams using ln-002-session-analyzer should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/ln-002-session-analyzer/SKILL.md --create-dirs "https://raw.githubusercontent.com/levnikolaevich/claude-code-skills/main/skills-catalog/ln-002-session-analyzer/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/ln-002-session-analyzer/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How ln-002-session-analyzer Compares

Feature / Agentln-002-session-analyzerStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Analyzes current or recent session for errors, inefficiencies, and improvement opportunities across skills, tools, hooks, and communication. Use after completing a task or periodically.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

> **Paths:** File paths (`shared/`, `references/`, `../ln-*`) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root. If `shared/` is missing, fetch files via WebFetch from `https://raw.githubusercontent.com/levnikolaevich/claude-code-skills/master/skills/{path}`.

# Session Analyzer (Standalone Utility)

**Type:** Standalone Utility
**Category:** 0XX Shared

Analyzes a session for errors, inefficiencies, and improvement opportunities. Produces actionable fixes for skills, tools, hooks, and communication style.

**Scope:** Single-session deep analysis (10 dimensions). Broader than protocol self-audit, narrower than `/audit-sessions` batch.
For skill self-audit: `shared/references/meta_analysis_protocol.md` §7. For multi-day patterns: `/audit-sessions`.

---

## When to Use This Skill

- After completing a task — find what went wrong and how to improve
- Periodically — audit recent sessions for patterns
- After a skill run — analyze how well the skill instructions worked
- When debugging tool/hook issues — find root causes in session data

---

## Input

`$ARGUMENTS`:
- (empty) — analyze current session (conversation context)
- `recent` — scan latest JSONL session per agent (Claude, Codex, Gemini)
- `{skill-name}` — focus analysis on that skill's execution within the session

---

## Dimensions

| # | Dimension | Scan for | Improvement target |
|---|-----------|---------|-------------------|
| D1 | Tool Errors | NOOP_EDIT, TEXT_NOT_FOUND, hash mismatch, out of range | SKILL.md steps — add paths, anchors |
| D2 | Tool Waste | Full reads without outline, repeated reads, bash fallbacks | SKILL.md — "outline first", name MCP tools |
| D3 | Process Issues | Tool loops 3+, retry storms, dead ends, wrong targets | SKILL.md phases — decompose |
| D4 | Script Extraction | Ad-hoc bash/python scripts written each run | `references/scripts/` |
| D5 | Hook & Permission | Hook blocks, permission denials, built-in instead of MCP | Hook config, `allowed-tools` |
| D6 | Communication | Over-explaining, missing status, unnecessary confirmations | CLAUDE.md prefs, skill output notes |
| D7 | Decision Quality | Dead ends before pivot, trial-and-error, slow error detection | SKILL.md decision trees, step clarity |
| D8 | Context Pressure | Re-reading same files, re-asking resolved, thread loss | Caching notes, compact instructions |
| D9 | Subagent Quality | Empty results, timeouts, overbroad prompts | Agent prompts, timeout settings |
| D10 | Scope Drift | Deviation from goal, accidental expansion, pivot without reason | Scope guards, goal gates |

---

## Phase 1: Collect Session Data

Determine source based on `$ARGUMENTS`:

### Current session (empty args)

Scan conversation context directly. You have access to all tool call results, errors, and messages.

### Recent sessions (`recent` arg)

Find latest session per agent (paths per `shared/references/meta_analysis_protocol.md` §7c):

```bash
echo "=== LATEST SESSIONS ==="

echo "## Claude"
CLAUDE_LATEST=$(stat -c '%Y %n' ~/.claude/projects/*/*.jsonl 2>/dev/null | sort -rn | head -1 | cut -d' ' -f2-)
[ -n "$CLAUDE_LATEST" ] && echo "  $CLAUDE_LATEST ($(wc -l < "$CLAUDE_LATEST") lines)" || echo "  No sessions found"

echo "## Codex"
CODEX_LATEST=$(stat -c '%Y %n' ~/.codex/sessions/????/??/??/rollout-*.jsonl 2>/dev/null | sort -rn | head -1 | cut -d' ' -f2-)
[ -n "$CODEX_LATEST" ] && echo "  $CODEX_LATEST ($(wc -l < "$CODEX_LATEST") lines)" || echo "  No sessions found"

echo "## Gemini"
GEMINI_LATEST=$(stat -c '%Y %n' ~/.gemini/tmp/*/chats/session-*.json 2>/dev/null | sort -rn | head -1 | cut -d' ' -f2-)
[ -n "$GEMINI_LATEST" ] && echo "  $GEMINI_LATEST" || echo "  No sessions found"
```

### Extract raw data from JSONL session

Run for each found session file (`$F`):

```bash
echo "=== TOOL CALLS ==="
grep -oE '"name"\s*:\s*"[^"]*"' "$F" 2>/dev/null | sed 's/"name"\s*:\s*"//;s/"//' | sort | uniq -c | sort -rn | head -30

echo "=== ERRORS ==="
grep -oE 'NOOP_EDIT|TEXT_NOT_FOUND|FILE_NOT_FOUND|HASH_HINT|DANGEROUS|out of range|mismatch|tool_use_error|permission denied' "$F" 2>/dev/null | sort | uniq -c | sort -rn

echo "=== TOOL LOOPS (3+ consecutive) ==="
grep -oE '"name"\s*:\s*"[^"]*"' "$F" 2>/dev/null | sed 's/"name"\s*:\s*"//;s/"//' | uniq -c | sort -rn | awk '$1 >= 3'

echo "=== BUILT-IN vs MCP ==="
grep -oE '"name"\s*:\s*"(Read|Edit|Write|Grep|mcp__hex-line__\w+)"' "$F" 2>/dev/null | sed 's/.*"name"\s*:\s*"//;s/"//' | sort | uniq -c | sort -rn

echo "=== HOOK EVENTS ==="
grep -oE 'hook_progress|blocking error|PreToolUse|PostToolUse|hex-confirmed|Obligatory use|Use mcp__hex-line' "$F" 2>/dev/null | sort | uniq -c | sort -rn

echo "=== SKILL/COMMAND INVOCATIONS ==="
grep -oE '"display":\s*"/[a-z-]+' "$F" 2>/dev/null | sed 's/"display":\s*"//' | sort | uniq -c | sort -rn
```

---

## Phase 2: Analyze by Dimensions

Apply D1-D10 to collected data. Classify each finding:

| Severity | Dimensions | Meaning |
|----------|-----------|---------|
| **Error** | D1, D5 | Something broke — tool failed, permission denied |
| **Waste** | D2, D4, D8 | Unnecessary work — redundant reads, ad-hoc scripts, re-gathering |
| **Pattern** | D3, D6, D7, D9, D10 | Improvable behavior — loops, communication, decisions |

### D1: Tool Errors
Count by type: NOOP_EDIT, TEXT_NOT_FOUND, hash mismatch, out of range, FILE_NOT_FOUND. For each, identify which step/phase caused it.

### D2: Tool Waste
- Reads without preceding outline (file >100 lines)
- Same file read 3+ times
- Bash `cat`/`grep`/`head`/`sed` when MCP equivalent exists

### D3: Process Issues
- Tool loops: same tool on same file 3+ times without progress
- Retry storms: 3+ attempts with different parameters
- Dead ends: approach explored then abandoned
- Wrong target: looked at file X when needed Y

### D4: Script Extraction
- Bash/Python scripts written during session
- If script would be needed on every run of the skill → candidate for `references/scripts/`

### D5: Hook & Permission
- Hook blocks (PreToolUse/PostToolUse blocking errors)
- Built-in Read/Edit/Write/Grep used when MCP enforced
- `hex-confirmed` bypasses — were they justified?

### D6: Communication
- Message length distribution (over-explaining vs terse)
- Unnecessary confirmations ("shall I proceed?")
- Missing status updates at milestones
- Redundant summaries

### D7: Decision Quality
- Time to detect error and pivot (tool calls between error and correction)
- Trial-and-error sequences vs targeted approach
- Tool selection reasoning (used wrong tool first)

### D8: Context Pressure
- Same file read multiple times across phases
- Information re-gathered that was already available
- Signs of thread loss (re-asking resolved questions)

### D9: Subagent Quality
- Agent tool invocations with empty or low-value results
- Agent timeouts
- Overbroad prompts (agent did too much or too little)

### D10: Scope Drift
- Initial goal vs actual deliverables — any deviation?
- Unplanned additions during execution
- Pivots without explicit reason

---

## Phase 3: Map to Fixes

For each finding, determine specific target and fix:

| Target type | Example |
|------------|---------|
| SKILL.md step | "ln-400 Step 2: add file path `src/config.ts`" |
| SKILL.md phase | "ln-300 Phase 3: decompose into 3a-3c sub-steps" |
| `allowed-tools` | "ln-400: add `mcp__hex-line__edit_file`" |
| Hook config | "settings.json: add exception for `npm test`" |
| `references/scripts/` | "ln-520: move `test_harness.sh` to references/scripts/" |
| CLAUDE.md | "Add preference: terse responses, no trailing summaries" |
| MCP tool | "hex-line edit_file: hash mismatch on concurrent edits" |
| Agent prompt | "ln-310 Agent A: narrow scope to security-only" |
| Scope guard | "ln-400: add Goal Articulation Gate at Phase 1" |

---

## Phase 4: Report

Output to chat per `shared/references/meta_analysis_protocol.md` format.

```
### Session Analysis: {session identifier}

#### Improvements
| # | Dim | Finding | Target | Fix |
|---|-----|---------|--------|-----|
| 1 | D1 | 3 edit failures Phase 4 | ln-400 Step 2 | Add file path |
| 2 | D4 | test.sh written ad-hoc | ln-520 | Move to references/scripts/ |
| 3 | D6 | Over-explained 5 times | CLAUDE.md | Add "terse" pref |
| 4 | D5 | Hook blocked Read 4x | settings.json | Add MCP permission |

#### Session Errors
| Problem Type | Count | Examples |
|-------------|-------|---------|
| Retry storm | 4 | 3x edit_file on config.ts |
| Wrong target | 2 | Read utils.ts not helpers.ts |

#### Subagent Errors: {Agent Name}  (per agent, if any)
| Problem Type | Count | Examples |
|-------------|-------|---------|
| {type} | {N} | {brief} |

IF no findings AND no errors: "Session analysis: clean run."
```

---

## Anti-Patterns

| Do NOT | Instead |
|--------|---------|
| Define own output template | Reference protocol format |
| Analyze files not in session | Only analyze what was actually used |
| Generic recommendations | Each fix tied to specific file + location |
| Report OK dimensions | Only findings with issues |

---

## Phase 5: Meta-Analysis

**MANDATORY READ:** Load `shared/references/meta_analysis_protocol.md`

Analyze this session per protocol §7. Output per protocol format.

---

## Definition of Done

- [ ] D1-D10 dimensions checked
- [ ] JSONL scanning works (`recent` mode)
- [ ] Each finding has specific Target + Fix
- [ ] Output per protocol format (improvements-only)
- [ ] No template duplication
- [ ] Meta-Analysis run

---

**Version:** 1.0.0
**Last Updated:** 2026-03-21

Related Skills

ln-641-pattern-analyzer

310
from levnikolaevich/claude-code-skills

Analyzes single pattern implementation, calculates compliance/completeness/quality scores, identifies gaps. Use when auditing a specific pattern.

ln-514-test-log-analyzer

310
from levnikolaevich/claude-code-skills

Analyzes application logs: classifies errors, checks log quality, maps stack traces to source. Use when logs need review after test runs or during development.

ln-914-community-responder

310
from levnikolaevich/claude-code-skills

Responds to unanswered GitHub discussions and issues with codebase-informed replies. Use when clearing community question backlog.

ln-913-community-debater

310
from levnikolaevich/claude-code-skills

Launches RFC and debate discussions on GitHub. Use when proposing changes that need community input or voting.

ln-912-community-announcer

310
from levnikolaevich/claude-code-skills

Composes and publishes announcements to GitHub Discussions. Use when sharing releases, updates, or news with the community.

ln-911-github-triager

310
from levnikolaevich/claude-code-skills

Produces prioritized triage report from open GitHub issues, PRs, and discussions. Use when reviewing community backlog.

ln-910-community-engagement

310
from levnikolaevich/claude-code-skills

Analyzes community health and delegates engagement tasks. Use when managing GitHub issues, discussions, and announcements.

ln-840-benchmark-compare

310
from levnikolaevich/claude-code-skills

Runs built-in vs hex-line benchmark with scenario manifests, activation checks, and diff-based correctness. Use when measuring hex-line MCP performance against built-in tools.

ln-832-bundle-optimizer

310
from levnikolaevich/claude-code-skills

Reduces JS/TS bundle size via tree-shaking, code splitting, and unused dependency removal. Use when optimizing frontend bundle size.

ln-831-oss-replacer

310
from levnikolaevich/claude-code-skills

Replaces custom modules with OSS packages using atomic keep/discard testing. Use when migrating custom code to established libraries.

ln-830-code-modernization-coordinator

310
from levnikolaevich/claude-code-skills

Modernizes codebase via OSS replacement and bundle optimization. Use when acting on audit findings to reduce custom code.

ln-823-pip-upgrader

310
from levnikolaevich/claude-code-skills

Upgrades Python pip/poetry/pipenv dependencies with breaking change handling. Use when updating Python dependencies.