Skip to content

feat(secure-at-inception/claude): surface user-visible messages when hooks run - #50

Open
lcrowther-snyk wants to merge 1 commit into
snyk:mainfrom
lcrowther-snyk:feat/hook-run-messages
Open

feat(secure-at-inception/claude): surface user-visible messages when hooks run#50
lcrowther-snyk wants to merge 1 commit into
snyk:mainfrom
lcrowther-snyk:feat/hook-run-messages

Conversation

@lcrowther-snyk

Copy link
Copy Markdown

What

Adds clear, branded UI messages so users can see when each Secure-at-Inception hook fires and what it did, for the Claude async-CLI variant.

Messages are emitted via the hook response's systemMessage field, prefixed 🔒 Snyk Secure at Inception ·:

Hook When Message
SessionStart session begins (prereqs OK) session started — security scanning is active (warming scan cache).
PostToolUse each tracked code edit/write change detected in <file> — running a background security scan…
Stop no new vulns ✅ Stop hook ran — scan complete, no new vulnerabilities introduced. Safe to stop.
Stop new vulns found 🚨 Stop hook blocked — N new code + M new dependency vulnerability(ies) introduced…
Stop scan couldn't run ⚠️ Stop hook ran — security scan could not complete; see fallback instructions.

Why

Previously the hook ran silently from the user's point of view (only [SAI] stderr lines, visible in transcript/verbose). There was no positive confirmation that scanning was active, and in particular no explicit "all clear" message when the Stop hook found no newly introduced vulnerabilities. These messages make the guardrail's activity visible and reassuring.

How

  • output_response() gains an optional system_message param; when set, it attaches systemMessage (prefixed with a new HOOK_BANNER constant).
  • Call sites updated for SessionStart, PostToolUse (code files only), and all three Stop outcomes.
  • No-op paths (non-code edits, unknown events, no-pending-changes stops) stay silent to avoid noise.

Scope

  • Single file: guardrail_directives/secure_at_inception/hooks_version/claude/async_cli_version/snyk_secure_at_inception.py (+40/-7).
  • dist/ artifacts are not included — per repo convention they're regenerated in chore: release commits, not per feature PR.

Testing

  • python3 -m py_compile passes.
  • Smoke-tested output_response output shape (clean / block / no-message) and confirmed no-op handler paths still return {}.
  • Built locally and reinstalled; messages render as expected across SessionStart, PostToolUse, and Stop.

🤖 Generated with Claude Code

…hooks run

Adds a branded systemMessage (HOOK_BANNER "Snyk Secure at Inception") to the
hook's JSON responses so it's clear in the UI when each hook fires and what it
did:

- SessionStart       -> "session started — security scanning is active"
- PostToolUse        -> "change detected in <file> — running a background scan"
- Stop (clean)       -> "Stop hook ran — no new vulnerabilities introduced"
- Stop (blocked)     -> "Stop hook blocked — N new code + M new dependency vuln(s)"
- Stop (scan failed) -> "Stop hook ran — security scan could not complete"

output_response gains an optional system_message param; no-op paths (non-code
edits, unknown events) stay silent.

dist/ artifacts are regenerated at release time per repo convention, so they
are intentionally not included in this PR.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@lcrowther-snyk
lcrowther-snyk requested review from a team as code owners May 25, 2026 05:41
@lcrowther-snyk

Copy link
Copy Markdown
Author

example message from claude code cli
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant