Skip to content

Extract scanner into a standalone, protocol-agnostic CLI (scan --stdin) #59

Description

@fahadsiddiqui

Problem

The scanning engine (src/scanner/engine.ts, src/scanner/detectors.ts) is currently coupled to the Claude Code hook protocol (stdin JSON envelope, hook-specific exit codes/response shape). The actual detection logic is generic and valuable independent of Claude Code — the same engine could back similar guardrails for Cursor, GitHub Copilot, Windsurf, or any other AI coding tool with an equivalent hook/extension point. This also hedges the platform risk called out in the product audit: if Anthropic ships native secret-redaction in Claude Code, the underlying scanning engine still has value elsewhere.

Proposal

Extract the core scanner (config loading, detectors, engine, allowlists, redaction) into a standalone, protocol-agnostic package/CLI:

privacy-guard-core scan --stdin

Taking raw text on stdin (or as an argument) and returning scan results as JSON, independent of any specific hook envelope. The existing Claude Code hook (scripts/prompt-guard.js) becomes a thin adapter that reads the Claude Code stdin envelope, extracts the prompt, calls the core scanner, and formats the hook-specific response.

Acceptance criteria

  • Core scanning logic has no Claude-Code-specific imports or assumptions
  • A standalone scan --stdin CLI mode exists and is documented
  • scripts/prompt-guard.js is refactored to be a thin wrapper around the core scanner (no behavior change for existing Claude Code users)
  • Existing test suite still passes after the extraction

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions