AGENT SKILL

session-report

Generates a self-contained HTML report of session usage — tokens, cache efficiency, subagent costs, and slash command frequency — from local transcripts.

License 许可
MIT
最近更新
2026-11-03
Stars
★ 2
Forks
0

01 前言 Front Matter

name
session-report
description
Generates a self-contained HTML report of session usage — tokens, cache efficiency, subagent costs, and slash command frequency — from local transcripts.
when_to_use
Run when the user asks what a session or period cost — "token usage", "how much did I spend", "cache hit rate", "session report". Works for Claude Code (~/.claude) and Codex (~/.codex). Pass a time range as argument (24h, 7d, 30d, all) — defaults to 7d. Not for saving state to continue work later — that's session-handoff.
argument-hint
[24h|7d|30d|all]
disable-model-invocation
true

02 资源文件 6

03 SKILL.md 正文

Session Report

Produce a self-contained HTML report of session usage and save it to <git-root>/.session-report/.

Steps

  1. Detect tool and pick analyzer. Run:

    if [ -n "$CODEX_HOME" ] || [ -n "$CODEX_SANDBOX_NETWORK_DISABLED" ]; then
      TOOL=codex; ANALYZER=analyze-codex.mjs
    elif [ -d "$HOME/.codex/sessions" ] && [ ! -d "$HOME/.claude/projects" ]; then
      TOOL=codex; ANALYZER=analyze-codex.mjs
    elif [ -d "$HOME/.claude/projects" ]; then
      TOOL=claude; ANALYZER=analyze-claude.mjs
    else
      TOOL=codex; ANALYZER=analyze-codex.mjs
    fi
    

    Ambiguous case — if both ~/.codex/sessions and ~/.claude/projects exist and no env var matched, the shell above falls through to TOOL=claude. Honor that result exactly:

    • If you are Codex: override to TOOL=codex; ANALYZER=analyze-codex.mjs
    • If you are Claude Code: the shell result is correct — keep TOOL=claude; ANALYZER=analyze-claude.mjs. Do not change it.

    The user can also force the tool with --tool codex or --tool claude.

  2. Parse time range from $ARGUMENTS (e.g. 7d, 30d, 24h). Default: 7d. If all — omit --since.

  3. Run the analyzer. Both scripts live alongside this SKILL.md — use the absolute path. Resolve the report directory first and write the JSON there too (it is this skill's working-state home, already gitignored — /tmp would strand the intermediate outside the artifact contract). The ${TOOL} suffix keeps concurrent runs from different tools from colliding:

    OUT_DIR="$(git rev-parse --show-toplevel 2>/dev/null || pwd)/.session-report"
    mkdir -p "$OUT_DIR"
    # With --since:
    node <skill-dir>/$ANALYZER --json --since 7d > "$OUT_DIR/session-report-${TOOL}.json"
    
    # All-time:
    node <skill-dir>/$ANALYZER --json > "$OUT_DIR/session-report-${TOOL}.json"
    

    Period comparison. When the user asks to compare weeks or periods ("how did this week compare", "week over week"), add --compare weekly (or 7d, 24h, any <N>d|<N>h) and, optionally, --periods N (default 4, trailing windows ending now, oldest first; --compare-end <ISO> ends them at a past date instead). The JSON then carries periods[] and the report gains a "period comparison" section; without --compare neither exists. The comparison widens the report window to cover every period, so --since is not needed alongside it.

    The analyzers read the usage-trace store when one exists and fall back to transcripts when it doesn't (--source store|transcripts|auto, default auto). The JSON's source and coverage fields say which one priced the report and why.

  4. Read $OUT_DIR/session-report-${TOOL}.json. Skim overall, by_project, by_subagent_type, by_skill, cache_breaks, top_prompts, and periods when present (a partial period had no data at its start, so do not read its totals as a drop).

  5. Copy the template into the report directory:

    # $OUT_DIR was resolved in step 3
    cp <skill-dir>/template.html "$OUT_DIR/session-report-$(date +%Y%m%d-%H%M).html"
    

    Reports are gitignored working state, not project docs. Before the first write in a repo, run the bootstrap once: git check-ignore -q .session-report/ — if it isn't ignored, ask once ("Reports are scratch — add .session-report/ to .gitignore?") and append on yes, or write to .git/info/exclude if the user would rather not touch a tracked file. Never edit either file without asking. Outside a git repo the path falls back to ./.session-report/ — say so once. An AGENTS.md override wins.

  6. Edit the output file (use Edit, not Write — preserve the template's JS/CSS):

    • Replace the contents of <script id="report-data" type="application/json"> with the full JSON from step 3. The analyzers serialize < as \u003c, so transcript text cannot close the script element; preserve those escapes exactly. The page's JS renders everything automatically from this blob. IMPORTANT: the script tag must contain only valid JSON — no comments, no debug lines, no analysis notes. Any non-JSON text before or after the {...} will break JSON.parse() and leave all sections blank.

    • Fill the <!-- AGENT: anomalies --> block with 3–5 one-line findings. Express figures as % of total tokens (total = overall.input_tokens.total + overall.output_tokens):

      <div class="take bad"><div class="fig">41.2%</div><div class="txt"><b>project-x</b> consumed 41% of the week across 3 sessions</div></div>
      

      Classes: .take bad (red) for waste/anomalies, .take good (green) for healthy signals, .take info (blue) for neutral. Look for: project eating disproportionate share, cache-hit <85%, single prompt >2% of total, subagents averaging >1M tokens/call, clustering cache breaks.

      Codex note: pct_cached will be 0 for most OpenAI models — only flag this if the model supports prompt caching.

    • Fill the <!-- AGENT: optimizations --> block with <div class="callout"> suggestions. Work the checklist below and write one callout per signal that actually fires — typically 3–6. Each callout must name the row it came from and the change it implies; a suggestion with no number attached to it is noise.

      Check Data path Fires when Say
      Cache breaks overall.cache_breaks_over_100k, cache_breaks[] > 0, especially clustered in one project or one day Which project and when, and that a /compact before the repeated resume is the cheaper path
      Subagent cost overall.subagent.avg_tokens_per_call > 500k per call Which subagent type from by_subagent_type dominates, and that its brief is carrying the context rather than the work
      Cache hit rate overall.input_tokens.pct_cached < 85% (Claude only — see the Codex note) The rate, and which project in by_project drags it down
      Project concentration by_project[].input_tokens.total one project > 50% of the total Name it with its share and its cost_usd.total
      Model mix by_project[].by_model, the top model column an expensive model dominates a low-efficiency_score project The project, its dominant model, and its cost
      Per-project efficiency by_project[].efficiency_score any project scores below the overall score Which one, and which of cache / msgs / subagents its score is losing on
      Single-prompt cost top_prompts[0] > 2% of total tokens The prompt, truncated, with its share and session id
      Session hygiene overall.hours.active vs .wall_clock active < 50% of wall clock That sessions are being left open, and that every per-hour figure below is diluted by it

      Skip a row rather than inventing one: an empty checklist entry is a healthy report, not a gap to fill. If nothing fires, say so in a single callout.

    • HTML-escape every transcript-derived project, prompt, model, skill, and tool label inserted into either agent-authored block.

    • Do not restructure existing sections. Each section's body now sits inside a <details class="fold" open> with its <h2> in the <summary> — the two <!-- AGENT: … --> markers moved with it, so edit by marker, never by line number. Do not add, remove or reorder sections (the "period comparison" section is the template's own and removes itself when the JSON has no periods), and do not delete the hidden #prompt-histogram container: the render writes to it without a null guard, and removing it kills every render step that follows, including the section nav.

  7. Report the saved file path. Do not open it or render it.

Notes

  • The template auto-adjusts titlebar and command text from DATA.tool in the JSON.
  • For Codex: slash commands are extracted from message text (best-effort, not precise attribution). The by_skill table shows commands that appeared as /foo in user messages.
  • For Codex: the subagent replay overcounting problem is handled by the analyzer — events timestamped before the session's own start are discarded.
  • If JSON is >2MB, trim top_prompts and cache_breaks to 100 entries each before embedding.

04 同仓库更多 Skills

jabworks
jabworks/agentic-toolkit

orphan

暂无简介

★ 2
jabworks
jabworks/agentic-toolkit

no-blurb

暂无简介

★ 2
jabworks
jabworks/agentic-toolkit

workflow

Routes any dev task into the right execution tier (Small/Medium/Large) and carries condux's operating rules — proportional effort, lazy skill loading, soft gates, implement-yourself-by-default.

★ 2
jabworks
jabworks/agentic-toolkit

usage-trace

Checks and manages durable, local usage capture — ingest, health status, and the opt-in limit snapshot — for Claude Code and Codex. Capture itself runs automatically at session start.

★ 2
jabworks
jabworks/agentic-toolkit

toolkit-skill-standards

Use when writing or reviewing a SKILL.md for jabworks/agentic-toolkit — frontmatter budgets, the trigger contract ("Use when…" description or when_to_use field), progressive disclosure into references/, and keeping a new description out of existing skills' trigger space. Triggers include "review this skill description", "write the frontmatter", "does this collide with an existing skill", "where should this content live". Not for scaffold/sync mechanics; use toolkit-foundry.

★ 2
jabworks
jabworks/agentic-toolkit

toolkit-research-frontier

Use when planning improvement work on jabworks/agentic-toolkit itself — open problems (trigger-collision automation, YAML-strict frontmatter checks, docs-catalog enforcement), existing assets, the next three concrete steps, and the four-front library-health campaign with commands and success criteria. Triggers include "let's improve our toolkit", "let's improve this repo", "what should we improve next", "toolkit roadmap", "open problems", "run the health campaign".

★ 2