message-display-secrets-mask
Skill0 starsChanged 5 months agoMITView on GitHub
Claude Code v2.1.152+ の MessageDisplay hook で、表示前のメッセージから secrets (sk-/ghp_/AKIA/AIza/xox 等) をマスクし、巨大コードブロックを collapse する hook を実装するとき。
In this repository99 other files it gives its agents.
- agents-tools-quoted-jsonSkill
- asc-api-app-store-submitSkill
- asd-ste100Skill
- automation-bool-selector-pitfallsSkill
- automation-stale-cooldown-flagSkill
- autonomous-build-verifySkill
- book-to-skillSkill
- ccusage-cli-cost-trackingSkill
- chrome-ext-mv3-programmatic-injectSkill
- chrome-ext-store-assetsSkill
- claude-headless-p-invocationSkill
- claude-plugin-context-auditSkill
- claude-session-log-to-kbSkill
- cloudflare-workers-do-deploySkill
- codebase-to-courseSkill
- codesign-keychain-prompt-fixSkill
- codex-cli-setupSkill
- codex-delegation-handoffSkill
- content-factory-grounding-dedupSkill
- conversation-log-append-patternSkill
- cron-to-launchd-macosSkill
- cross-automation-shared-resource-killSkill
- design-token-migration-rnSkill
- discord-bot-image-to-claudeSkill
- discord-gateway-resume-dedupSkill
- excel-filtered-url-http-auditSkill
- execution-budget-vs-capsSkill
- expo-free-local-ios-testflightSkill
- ga4-connect-projectsSkill
- gcal-oauth-desktop-setupSkill
- git-commit-helperSkill
- git-prepush-secret-remote-checkSkill
- gsc-cli-automationSkill
- hatena-blogsync-autopostSkill
- hook-latency-wrapSkill
- hook-log-append-patternSkill
- html-to-pdf-slide-deckSkill
- humanizerSkill
- human-review-gate-shellSkill
- implementation-model-routingSkill
- insights-to-claude-mdSkill
- ios-permission-key-security-matrixSkill
- ios-sim-store-screenshotsSkill
- launchd-exit78-exconfig-debugSkill
- llm-content-pipeline-quality-gateSkill
- local-ai-video-pipelineSkill
- local-flux-mflux-image-genSkill
- local-llm-slow-diagnosisSkill
- local-music-generationSkill
- lottie-skottie-authoring-pitfallsSkill
- machine-wide-api-ratelimit-latchSkill
- macos-hook-path-timeoutSkill
- md-to-docx-reportSkill
- memory-md-inject-bloat-auditSkill
- metric-source-attributionSkill
- migrate-icloud-desktop-assetsSkill
- nextauth-local-e2e-sessionSkill
- nextjs-rsc-payload-slimSkill
- nothing-designSkill
- openclaw-ollama-setupSkill
- The first 60 shown.
The file
Files
Procedure
- 入力 schema 確定: hook stdin は
{session_id, transcript_path, cwd, hook_event_name, message, role}。最初は変換せず log だけ取って実物で確認。 - 出力 schema:
{"hookSpecificOutput":{"hookEventName":"MessageDisplay","displayContent":"<変換後>"}}を stdout に。変更不要なら exit 0 で passthrough (空 stdout = 原文維持)。 - secrets マスク: 正規表現で
sk-[A-Za-z0-9]+,ghp_[A-Za-z0-9]+,github_pat_[A-Za-z0-9_]+,AKIA[A-Z0-9]+,AIza[A-Za-z0-9_-]+,xox[a-z]-[A-Za-z0-9-]+を[REDACTED]に置換。 - コードブロック collapse: 250 行超の
```ブロックは head 6 行 +... <N> lines omitted ...+ tail 6 行に圧縮。 - 例外時 passthrough: python/jq 失敗・schema 想定外なら必ず
exit 0で原文維持。hook が表示を止めない設計。
Pitfalls
displayContentを空文字で返すと画面が空になる → 「変更なし」は 空 stdout + exit 0 であってdisplayContent: ""ではない。- 正規表現が貪欲だと長い token のあとの空白まで食う →
[A-Za-z0-9_-]+で word-class を限定し境界明示。 - secrets を「マスクして表示」しても transcript JSONL には生で残る → 真に隠したいなら別途
transcript-pathを書き換える必要 (副作用大、推奨せず)。 - 250 行閾値は適当に決めず実トラフィックで調整。最初は閾値高め (500+) で誤 collapse を避ける。
- settings.json に配線する前に
echo '{...}' | <hook>.shで 3 パターン (passthrough / secrets / collapse) を手動テスト。
Verification
- passthrough test: 短文 stdin → 空 stdout + exit 0。
- secrets test:
sk-ant-test12345...を含む stdin →[REDACTED]置換確認。 - collapse test: 300 行のコードブロック含む stdin → 13 行 + 省略行数表記。
- settings.json 配線後、実セッションで
tail -F ~/.claude/logs/message-display.logで発火確認。 - hook 失敗時 (例: jq 削除) でも Claude Code の表示が止まらない (graceful degradation)。
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.

