Agent skill

Claude Session Introspect

by swyxio in swyxio/skills

Inspect Claude Code session JSONL files at ~/.claude/projects/ to extract real conversation telemetry: token counts (input/output/cache reads/cache writes), assistant turn counts, human prompt…

MITAuto-check passedAgent Workflows

Install Claude Session Introspect

skills CLI
$ npx skills add swyxio/skills --skill claude-session-introspect -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install swyxio/skills claude-session-introspect --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/swyxio/skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/claude-session-introspect .claude/skills/claude-session-introspect && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
claude-session-introspect
GitHub stars
176
Token cost
~2k tokens
SKILL.md length
592 words
Files
3
Skills in repo
89
Repo updated
First seen
Licence
MIT

At a glance

Inspect Claude Code session JSONL files at ~/.claude/projects/ to extract real conversation telemetry: token counts (input/output/cache reads/cache writes), assistant turn counts, human prompt…

  • The user asks how many tokens did this session use
  • SKILL.md covers Where sessions live, Quick locate: find the current…, The headline stats (one-shot) and Gotchas, plus 2 more sections
  • Runs Shell scripts from its folder; calls jq, bash and claude
  • How many prompts have I sent

What it does

Claude Session Introspect is an agent skill from swyxio/skills. Inspect Claude Code session JSONL files at ~/.claude/projects/ to extract real conversation telemetry: token counts (input/output/cache reads/cache writes), assistant turn counts, human prompt counts, tool-use counts, compaction boundaries, and the contents of compaction summaries. Use this skill when the user asks "how many tokens did this session use", "how many prompts have I sent", "show me the stats for this conversation", "what got compacted", "where are the compaction boundaries", "introspect the session"…

Its SKILL.md is about 2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 2 other files (for example `README.md` and `stats.sh`). Compatibility notes: Requires jq. Sessions live at ~/.claude/projects/<encoded-cwd/<session-uuid.jsonl. The encoded-cwd is the absolute working directory with / replaced by - and…

It sits in Agent Workflows, covering Context engineering. The repository describes itself as: Agent skills for Claude Code and other AI agents. The licence is MIT.

When your agent uses it

  • The user asks how many tokens did this session use
  • How many prompts have I sent
  • Show me the stats for this conversation
  • What got compacted

Example prompts

  • “how many tokens did this session use”
  • “how many prompts have I sent”
  • “show me the stats for this conversation”
  • “/claude-session-introspect”

Requirements

  • A Bash shell
  • Compatibility (from SKILL.md): Requires `jq`. Sessions live at `~/.claude/projects/<encoded-cwd>/<session-uuid>.jsonl`. The encoded-cwd is the absolute working directory with `/` replaced by `-` and a leading `-`. Each line is a JSON object with `type`, `message`, `toolUseResult`, etc.

What it can do on your machine

Read from SKILL.md and the folder at commit 038ef34. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships script files (Shell), which the agent can run.

    Shell commands in SKILL.md call:

    • jq
    • bash
    • claude

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • talraviv.co

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

  • Compatibility

    Requires `jq`. Sessions live at `~/.claude/projects/<encoded-cwd>/<session-uuid>.jsonl`. The encoded-cwd is the absolute working directory with `/` replaced by `-` and a leading `-`. Each line is a JSON object with `type`, `message`, `toolUseResult`, etc.

    From compatibility in the SKILL.md frontmatter.

Context cost

Claude Session Introspect loads about 2k tokens when it runs. Until then it costs about 188 tokens; SKILL.md has 592 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~188
When it runs · the whole SKILL.md, loaded when a task matches
~2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from swyxio/skills at commit 038ef34, republished under its MIT licence (© swyxio). 592 words, ~2,045 tokens.

Download SKILL.mdSave it as .claude/skills/claude-session-introspect/SKILL.md (or your agent's skills folder). This skill also uses 2 other files; get the full folder from GitHub.
name
claude-session-introspect
description
Inspect Claude Code session JSONL files at ~/.claude/projects/ to extract real conversation telemetry: token counts (input/output/cache reads/cache writes), assistant turn counts, human prompt counts, tool-use counts, compaction boundaries, and the contents of compaction summaries. Use this skill when the user asks "how many tokens did this session use", "how many prompts have I sent", "show me the stats for this conversation", "what got compacted", "where are the compaction boundaries", "introspect the session", "do brain surgery on the JSONL", or wants any data point that lives inside the on-disk session log rather than the live context window. Inspired by Tal Raviv's "I wanted to know how compaction works" article.
compatibility
Requires `jq`. Sessions live at `~/.claude/projects/<encoded-cwd>/<session-uuid>.jsonl`. The encoded-cwd is the absolute working directory with `/` replaced by `-` and a leading `-`. Each line is a JSON object with `type`, `message`, `toolUseResult`, etc.
license
MIT
metadata.author
swyxio
metadata.version
1.0
metadata.last-updated
2026-04-08
metadata.primary-tools
jq, bash

Claude Session Introspect

Claude Code persists every conversation as a JSONL file on disk. This skill is the recipe for opening one and pulling out the numbers you actually want — token usage, prompt counts, compaction events, tool calls — without guessing.

Where sessions live

~/.claude/projects/<encoded-cwd>/<session-uuid>.jsonl

<encoded-cwd> is the absolute path of the project's working directory with / replaced by - and a leading -. Example: /Users/swyx/Work/foo → -Users-swyx-Work-foo.

Each line is one event. The interesting type values:

typewhat it is
usera real user message OR a tool result (distinguished by toolUseResult being non-null)
assistantan assistant turn (one model response). message.usage has the token counts.
systemsystem messages (mostly compaction-related)
file-history-snapshotedited-file snapshots used for undo
attachmentimage/file attachments
permission-modepermission mode toggles

Quick locate: find the current session

bash
# 1. encode current working directory
ENC="-$(pwd | sed 's,/,-,g' | sed 's/^-//')"
# 2. list the project's session files, newest first
ls -t "$HOME/.claude/projects/$ENC/"
# 3. the most recent .jsonl is usually the live one
SESSION="$HOME/.claude/projects/$ENC/$(ls -t "$HOME/.claude/projects/$ENC/" | head -1)"
echo "$SESSION"

If you know the session UUID (Claude Code shows it, and image-cache paths embed it), you can grep all projects:

bash
find ~/.claude/projects -name '<uuid>.jsonl'

The headline stats (one-shot)

The stats.sh script in this skill folder takes a session path and prints token totals, turn counts, prompt counts, tool-use counts, and any compaction events.

bash
bash stats.sh "$SESSION"

If you don't have the script handy, here are the inline jq one-liners.

Token totals across the whole session
bash
jq -s '
  [.[] | select(.message.usage)] |
  {
    assistant_turns: length,
    input_tokens:        (map(.message.usage.input_tokens // 0)              | add),
    output_tokens:       (map(.message.usage.output_tokens // 0)             | add),
    cache_read_tokens:   (map(.message.usage.cache_read_input_tokens // 0)   | add),
    cache_create_tokens: (map(.message.usage.cache_creation_input_tokens // 0)| add)
  }
' "$SESSION"

input_tokens is the FRESH (non-cached) input. cache_read_tokens is the dominant number on long sessions — it's how much was re-read from prompt cache. cache_create_tokens is what got newly written into the cache. Effective total tokens processed = input + cache_read + cache_create.

Counts by event type
bash
jq -r '.type' "$SESSION" | sort | uniq -c
Real human prompts (excluding tool results and system reminders)

A type:"user" line is a human message only if toolUseResult is null. Even then, the content may be a system-injected reminder, not the human's words.

bash
jq -r '
  select(.type == "user" and .toolUseResult == null) |
  (.message.content
    | if type == "string" then .
      else (map(select(.type == "text") | .text) | join("\n"))
      end)
' "$SESSION" > /tmp/prompts.txt

# total non-empty user message blocks
grep -cv '^$' /tmp/prompts.txt

# distinct human messages = blocks not starting with <system-reminder> or <command-
awk '
  BEGIN { n = 0; cur = "" }
  /^$/ { if (cur != "" && cur !~ /^<system-reminder>/ && cur !~ /^<command-/) n++; cur=""; next }
  { if (cur=="") cur=$0 }
  END { if (cur != "" && cur !~ /^<system-reminder>/ && cur !~ /^<command-/) n++; print n }
' /tmp/prompts.txt

(Blunt but works. If you want surgical accuracy, parse the content array and skip blocks whose first text element is a <system-reminder> tag.)

Tool calls — how many and which tools
bash
jq -r '
  select(.type == "assistant") |
  .message.content[]? |
  select(.type == "tool_use") |
  .name
' "$SESSION" | sort | uniq -c | sort -rn
Compaction boundaries — where, why, and what survived

Compaction inserts a system event with subtype:"compact_boundary" (older builds may use isCompactSummary on the next user message). The summary itself is the next user message, prefixed with "This session is being continued from a previous conversation that ran out of context."

bash
# count compaction events
jq -r 'select(.type=="system" and (.subtype // "") == "compact_boundary") | .timestamp' "$SESSION" | wc -l

# was each one auto or manual?
jq -r '
  select(.type == "system" and (.subtype // "") == "compact_boundary") |
  {ts: .timestamp, trigger: (.compactMetadata.trigger // "unknown"), preTokens: (.compactMetadata.preCompactTokens // null)}
' "$SESSION"

# read the compaction summaries (the actual contents that survived)
jq -r '
  select(.type == "user" and (.isCompactSummary == true or
    ((.message.content // "") | tostring | test("session is being continued from a previous conversation"))))
  | (.message.content | if type == "string" then . else (map(select(.type=="text").text)|join("\n")) end)
' "$SESSION" | less
Show full SKILL.md (245 more words)Show less
Per-turn token usage (for spotting blowups)
bash
jq -r '
  select(.message.usage) |
  [.timestamp,
   (.message.usage.input_tokens // 0),
   (.message.usage.output_tokens // 0),
   (.message.usage.cache_read_input_tokens // 0)]
  | @tsv
' "$SESSION" | column -t

This is how you find the one tool result that bloated your context — sort by cache_read ascending across the session and watch for the jump.

Gotchas

  • type:"user" is overloaded. Tool results are also type:"user". Always filter on toolUseResult == null to get human turns.
  • input_tokens looks tiny on long sessions. That's correct — it's the delta sent uncached. Almost everything flows through cache_read_input_tokens.
  • The "live" session file isn't always the newest. If multiple Claude Code windows are open in the same project, both write to the same project folder. Disambiguate by UUID — the chat header and image-cache paths both expose it.
  • JSONL files grow without bound. A long-running project folder can have hundreds of session files. ls -t | head is your friend.
  • Don't edit a live JSONL. Claude Code reads it back on /resume. If you want to do "brain surgery" (Tal Raviv's term), copy the file out, edit the copy, and use claude --resume <copied-uuid> from a clean directory.

When to reach for this skill

  • "How many tokens has this session burned?"
  • "How many prompts have I sent today?"
  • "Where did compaction kick in and what got summarized?"
  • "Which tool call blew up the context?"
  • Building a stats display, leaderboard, or "built with Claude Code" badge that needs real numbers.
  • Forensics on a session that went sideways — replaying tool calls in order.

Reference

© swyxio, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 2 other files in claude-session-introspect of swyxio/skills.

  • SKILL.md
  • README.md
  • stats.sh

Open the folder on GitHubat commit 038ef34

Compare with similar skills

Claude Session Introspect next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Claude Session Introspect compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Claude Session Introspect this skillswyxio/skills176—~2kAutomated safety check: PassMIT
Context Mode Output Sandboxmksglu/context-mode26k—~4.1kAutomated safety check: PassCustom licence
Memori Long-Term MemoryMemoriLabs/Memori17k—~2kAutomated safety check: NotesCustom licence
Picoclaw Skill Creatorsipeed/picoclaw30k—~4.4kAutomated safety check: PassMIT
ccc Semantic Code Searchcocoindex-io/cocoindex-code2.8k—~938Automated safety check: PassApache-2.0
Context Mode for Antigravity CLImksglu/context-mode26k—~850Automated safety check: PassCustom licence

Similar skills

  • Context Mode Output Sandbox

    mksglu/context-mode

    Routes large command, file, API and browser output through context-mode tools so only the needed result enters the agent's context, instead of dumping it via Bash.

    26k GitHub stars~4.1k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Memori Long-Term Memory

    MemoriLabs/Memori

    Connects Claude Code to Memori Cloud for long-term memory, recalling stored context before substantive replies and saving new context afterward.

    17k GitHub stars~2k tokensUpdated 8 days ago
    Agent WorkflowsAuto-check: notes
  • Picoclaw Skill Creator

    sipeed/picoclaw

    Guidance for creating, updating and reviewing Picoclaw skills, from the SKILL.md structure to organizing bundled scripts, references and assets.

    30k GitHub stars~4.4k tokensUpdated yesterday
    Agent WorkflowsAuto-check passed
  • ccc Semantic Code Search

    cocoindex-io/cocoindex-code

    Semantic code search and index management with the ccc CLI: the agent initializes, indexes and queries the project by concept, filtering by language or path.

    2.8k GitHub stars~938 tokensUpdated 4 days ago
    Agent WorkflowsAuto-check passed
  • Routing rules for using context-mode MCP tools in Antigravity CLI: sandboxed code runs, file analysis, indexed search and web fetches that keep large output out of the conversation.

    26k GitHub stars~850 tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Token Optimizer

    alexgreensh/token-optimizer

    Audit a Claude Code or Codex setup for context-window waste, then fix it and measure the savings.

    2.5k GitHub stars~3.6k tokensUpdated 2 days ago
    Agent WorkflowsAuto-check passed

More from swyxio/skills

All 89 skills in this repo
  • Programmatic Agents

    swyxio/skills

    Run a selected coding-agent CLI programmatically, with latency, error, usage, cost, and trace logging.

    176 GitHub stars~2.2k tokensUpdated 6 days ago
    Auto-check passed
  • Design, implement, audit, or refresh protected username and handle namespaces for public products.

    176 GitHub stars~1.1k tokensUpdated 6 days ago
    Auto-check passed
  • New Mac Setup

    swyxio/skills

    Fully automated new Mac setup for fullstack web developers and AI engineers.

    176 GitHub stars~4.3k tokensUpdated 6 days ago
    Auto-check passed
  • Youtube API

    swyxio/skills

    Manage YouTube videos programmatically via the YouTube Data API v3 — upload video files, upload custom thumbnails, update video metadata (titles, descriptions, tags), and query video/channel info…

    176 GitHub stars~2.2k tokensUpdated 6 days ago
    Auto-check passed
  • Batch YouTube Studio upload workflow for videos sourced from Airtable, Google Drive, Loom, YouTube, or local files.

    176 GitHub stars~1.5k tokensUpdated 6 days ago
    Auto-check: warnings
  • Reconstruct and visually analyze paired agent, game, or policy trajectories to determine whether changed actions produced their intended effects.

    176 GitHub stars~1.8k tokensUpdated 6 days ago
    Auto-check passed

Categories

Questions about Claude Session Introspect

What does Claude Session Introspect do?

Inspect Claude Code session JSONL files at ~/.claude/projects/ to extract real conversation telemetry: token counts (input/output/cache reads/cache writes), assistant turn counts, human prompt…. Claude Session Introspect is an agent skill from swyxio/skills.claude/projects/ to extract real conversation telemetry: token counts (input/output/cache reads/cache writes), assistant turn counts, human prompt counts, tool-use counts, compaction boundaries, and the contents of compaction summaries.

When should I use Claude Session Introspect?

Claude Session Introspect fits situations like: the user asks how many tokens did this session use; how many prompts have I sent; show me the stats for this conversation; what got compacted.

How do I install Claude Session Introspect in Claude Code?

Run `npx skills add swyxio/skills --skill claude-session-introspect -a claude-code`. Or copy the skill folder (claude-session-introspect in swyxio/skills) into .claude/skills/claude-session-introspect in your project. Claude Code loads it when a task matches its description.

How do I install Claude Session Introspect in Codex?

Run `npx skills add swyxio/skills --skill claude-session-introspect -a codex`. Or copy the skill folder (claude-session-introspect in swyxio/skills) into .agents/skills/claude-session-introspect in your project. Codex loads it when a task matches its description.

Can I use Claude Session Introspect in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add swyxio/skills --skill claude-session-introspect -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/claude-session-introspect, .gemini/skills/claude-session-introspect, .github/skills/claude-session-introspect and .opencode/skills/claude-session-introspect in your project.

What does Claude Session Introspect need to run?

Going by SKILL.md and its folder, Claude Session Introspect needs a shell for the scripts in its folder and the command-line tools its instructions call (jq, bash and claude). Our summary lists: A Bash shell. Compatibility (from SKILL.md): Requires `jq`. Sessions live at `~/.claude/projects/<encoded-cwd>/<session-uuid>.jsonl`. The encoded-cwd is the absolute working directory with `/` replaced by `-` and a leading `-`. Each line is a JSON object with `type`, `message`, `toolUseResult`, etc. .

Does Claude Session Introspect access the network?

SKILL.md names 1 domain. As links in the text: talraviv.co. This is read from the text; nothing was executed.

Is Claude Session Introspect safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Claude Session Introspect use?

Claude Session Introspect is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Claude Session Introspect use?

About 2k tokens (SKILL.md is roughly 8.2k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Claude Session Introspect?

Skills that share tags, products or a category with Claude Session Introspect: Context Mode Output Sandbox (mksglu/context-mode, 26k stars), Memori Long-Term Memory (MemoriLabs/Memori, 17k stars), Picoclaw Skill Creator (sipeed/picoclaw, 30k stars) and ccc Semantic Code Search (cocoindex-io/cocoindex-code, 2.8k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Claude Session Introspect?

swyxio (a GitHub user) maintains it in swyxio/skills, which has 176 GitHub stars. The repository holds 89 skills in this directory. The repository was last updated on October 5, 2026.

Source: swyxio/skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.