session-length-compact-audit
Skill0 starsChanged 4 months agoMITView on GitHub
transcript を session 別に集計し、session 長(メッセージ数)と compact 発生回数を実測して衛生違反(長すぎる session・compact 多発)を抽出する。トリガー語彙: session 長監査, compact 頻度, session 衛生, session hygiene, compact 回数, session 分割, /compact 過多, 長時間 session
In this repository46 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- a11y-standardsSkill
- a11y-static-gateSkill
- adversarial-refute-voteSkill
- antigravity-buildSkill
- architecture-parity-gateSkill
- ci-required-check-installerSkill
- codex-buildSkill
- codex-imagegenSkill
- codex-spark-delegateSkill
- commit-convention-gateSkill
- commit-msg-quality-scoreSkill
- consumer-finding-ledgerSkill
- context-bloat-trackerSkill
- coverage-floor-lockSkill
- destructive-env-guardSkill
- dev-standardsSkill
- eval-dataset-buildSkill
- eval-regression-guardSkill
- fanout-verify-synthSkill
- gate-forgeSkill
- hallucination-rate-meterSkill
- harness-kpi-ledgerSkill
- judge-rubric-voteSkill
- knowledge-citation-coverageSkill
- knowledge-dedup-scanSkill
- knowledge-index-guardSkill
- live-state-verify-guardSkill
- maker-checker-relaySkill
- memory-distillSkill
- mistake-rule-distillSkill
- oneshotSkill
- prompt-ab-evalSkill
- report-shapeSkill
- retry-failure-classifierSkill
- review-finding-reproSkill
- rule-dedup-scanSkill
- rule-promote-auditSkill
- rule-promotion-extractSkill
- secret-scan-hardeningSkill
- self-heal-ciSkill
- startSkill
- subagent-usage-analyzerSkill
- task-success-rate-trackSkill
- token-codegen-gateSkill
- trigger-vocab-dedupSkill
The file
Files
session-length-compact-audit(session 長 × compact 頻度監査)
docs/practices.md(「New task = new session」「/compact は hint 付きで」)を 実測側から検証する観測 skill。 ルールは「長い session は分割・compact は都度」と定めるが、実際に session がどれだけ伸び/何回 compact したかは transcript を集計しないと分からない。本 skill は session 別のメッセージ数と compact 回数を機械集計し、 衛生違反(長すぎる session・compact 多発 session)を可視化して session 分割・compact 運用の改善材料にする(原則 P1 自己申告禁止)。
目的
~/.claude/projects/*/*.jsonl(実 transcript)を session 別に集計し、メッセージ数(session 長) と compact 回数 を実測する- compact は
type=systemかつsubtype=compact_boundary、またはisCompactSummaryを持つレコードを 1 回として数える - session 長降順で並べ、長時間・compact 多発の session を上位に列挙する(衛生違反の抽出)
- 「New task = new session」が守られず 1 session に多タスクが載って伸びる/
/compact頻発でコンテキストが安定しない パターンを検出し、session 分割・/compacthint 運用の改善に供する - ログ源(transcript)が無い環境では「観測継続」として exit0(観測不足は失敗ではない)
実行手順
- 集計を表示する:
python3 scripts/agentlog.py session-hygiene # 人間可読サマリ python3 scripts/agentlog.py session-hygiene --json # 機械可読(JSON)- 既定源:
~/.claude/projects/*/*.jsonl(--transcript <path>で単一ファイル指定・--projects-dirで差替可) - 出力: session 総数 / session 長降順の top15(
msgs=<メッセージ数> compacts=<compact 回数> <sessionId>) - 集計単位:
typeがuser/assistantのレコードを 1 メッセージとして数える。compact はcompact_boundaryシステムレコードとisCompactSummaryレコードの合算。 - 源が無い時(transcript 未発見):
観測継続と表示して exit0。これは壊れではなく「まだ測る材料がない」状態。 空出力を「0 件」と即断しない(docs/incidents.md空≠ゼロ件)。
- 既定源:
- 衛生違反が継続的に出るなら運用側で対処:
- 突出して長い session(上位の msgs)→ タスク切替時に new session を起動する(
docs/practices.md) - compact が多発する session →
/compactを hint 付きで早めに打つ/そもそもタスクを分割する - 近似入力量(chars)ベースの肥大は姉妹 skill context-bloat-tracker の
--check(閾値 msgs≥200 / chars≥400,000)で別途管理
- 突出して長い session(上位の msgs)→ タスク切替時に new session を起動する(
- 月次
/harness-reviewの E 項(生産性)で長時間 session 率・compact 多発 session の推移を記録する。
決定論 --check(コマンドと exit の意味)
python3 scripts/agentlog.py session-hygiene --self-test- exit 0 = self-test PASS: hermetic temp fixture(session
s1に user+assistant+compact_boundary+isCompactSummary、 sessions2に user 1 件)でsessions=2/s1のmessages=3/s1のcompacts=2/ 欠如パスは source_ok=False かつ render に「観測継続」を機械検証する。fixture は tempfile に作り実行後に削除する(リポジトリに残さない)。 - exit 非0 = FAIL: session 長・compact カウント集計または源欠如耐性が壊れている(stderr に失敗内容)。
集計ロジックは姉妹 skill context-bloat-tracker と共通の _collect_sessions(scripts/agentlog.py)を用いる。
原則 P1 の floor 運用に従い、判定を甘くする方向の変更は禁止(据え置き/厳格化のみ)。
参照
- 実装:
scripts/agentlog.pyサブコマンドsession-hygiene(run_session_hygiene/render_session_hygiene/selftest_session_hygiene・集計は共通_collect_sessions) - 集計源:
~/.claude/projects/*/*.jsonl(各 Claude Code session の transcript) - 姉妹 skill: context-bloat-tracker(近似入力量ベースの肥大検出)/ harness-review(月次 E 項)
- 運用ルール:
docs/practices.md(New task = new session / compact hint)/docs/incidents.md(空≠ゼロ件) - 設計原則: 原則 P1(自己申告禁止・決定論ゲート)/ ハーネス再設計 H1(context 最小化)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

