ai-scanner ai-scanner

ai-scanner

Scan your codebase for LLM SDK usage, AI frameworks, exposed API tokens, and hardcoded secrets.

CI npm MIT Node 18+ 145 patterns MCP

Zero dependencies. 145 detection patterns. Works with Node.js 18+. Detects 23 LLM SDKs, 24 AI frameworks, 20+ AI token patterns, and 59 generic secret patterns across Python, JavaScript, TypeScript, Go, Java, and more.

๐Ÿšจ Token & Secret Detection

Catches hardcoded API keys for OpenAI, Anthropic, Stripe, GitHub, Slack, Twilio, and 50+ more providers. AI tokens + generic secrets in one scan.

๐Ÿ“ฆ SDK Discovery

Detects imports and client initialization for 23 LLM SDKs across all major languages.

๐Ÿง  Framework Detection

Finds LangChain, LlamaIndex, CrewAI, AutoGen, DSPy, Vercel AI SDK, and 24 total frameworks.

๐Ÿงน Smart Filtering

Context-aware โ€” ignores mentions in docs and README files. Skips .env files by default.

๐Ÿค– MCP Server

Use with Claude Code, Cursor, and Windsurf via the Model Context Protocol. 3 tools for AI agents.

๐Ÿ”„ CI/CD Ready

JSON and SARIF output. Exit code flag. GitHub Actions, pre-commit hooks, scheduled audits.


Installation

# Run directly โ€” no install needed
npx ai-scanner ./my-project

# Or install globally
npm install -g ai-scanner
ai-scanner ./my-project
Tip

Requires Node.js 18 or higher. Zero dependencies โ€” the tool is completely self-contained.


Quick Start

Point ai-scanner at any directory to get instant results:

# Scan current directory (AI + generic secrets)
ai-scanner

# Scan a specific project
ai-scanner ./my-project

# Security-only: just find exposed tokens & secrets
ai-scanner --tokens-only

CLI Options

FlagDescription
-o, --output <file>Write JSON report to file
--sarif <file>Write SARIF report (for CI/CD integration)
--tokens-onlyOnly scan for exposed tokens & secrets (security mode)
--ai-onlyOnly scan AI-specific patterns (skip generic secrets)
--scan-envInclude .env files (skipped by default)
--no-endpointsSkip API endpoint detection
--no-modelsSkip model name reference detection
--jsonOutput results as JSON to stdout
--exit-codeExit with code 1 if critical/high findings
-h, --helpShow help message
-v, --versionShow version number
# Combine flags for CI pipelines
ai-scanner ./src --tokens-only --exit-code --json

# AI patterns only (no Stripe, GitHub tokens, etc.)
ai-scanner --ai-only

# Include .env files in the scan
ai-scanner --scan-env

Smart Filtering

ai-scanner is context-aware. It distinguishes between using an SDK in source code vs. mentioning it in documentation.

File typeSDK/Framework mentionsExposed tokens & secrets
Source code (.js, .py, .go, etc.)โœ… Reportedโœ… Reported
README, docs, markdownโŒ Ignoredโœ… Reported
examples/, samples/, docs/ dirsโŒ Ignoredโœ… Reported
.env filesโŒ SkippedโŒ Skipped by default
.env with --scan-envโ€”โœ… Reported
Why skip .env?

.env files are designed to hold secrets โ€” they should be in your .gitignore. The real risk is keys hardcoded directly in source files. Use --scan-env if you want to include them.


Detection Coverage

AI Tokens 20+

sk-proj-*sk-ant-*AIzaSy*hf_*AKIA*gsk_*r8_*ls__*fw_*Bearer *api_key=co-*msrl-*

Generic Secrets 59 patterns

CategoryDetections
PaymentStripe (live, restricted, webhook), Square, PayPal Braintree
CommunicationTwilio, SendGrid, Mailgun, Mailchimp, Postmark
Source ControlGitHub (PAT, fine-grained, OAuth, app), GitLab, Bitbucket, CircleCI
CloudGCP service accounts, DigitalOcean, Heroku, Vercel, Netlify, Cloudflare
MessagingSlack (bot, user, webhook), Discord (bot, webhook), Telegram
DatabasePostgres/MySQL/MongoDB/Redis/AMQP URIs, Supabase, Firebase, PlanetScale
AuthAuth0, Okta, Clerk
MonitoringDatadog, Sentry DSN, New Relic, Segment, Mixpanel
CryptoRSA, EC, DSA, SSH, PGP private keys
GenericPasswords, client secrets, connection strings, JWTs

LLM SDKs 23

OpenAIAnthropicGoogle GeminiVertex AICohereMistralGroqReplicateTogether AIAWS BedrockAzure OpenAIOllamaLiteLLMDeepSeekFireworks AIPerplexityHuggingFace

AI Frameworks 24

LangChainLangGraphLlamaIndexCrewAIAutoGenDSPyHaystackVercel AI SDKSemantic KernelInstructorChainlitvLLMMLflowW&BSpring AIGuidancePromptflowSmolagents

Severity Levels

LevelMeaningExample
CRITICALExposed key with known prefixsk-ant-abc123..., sk_live_..., ghp_...
HIGHLikely hardcoded credentialapi_key = "...", JWT tokens, DB strings
INFOSDK/framework usage (awareness)import openai

MCP Server

Use ai-scanner as a tool for AI agents via the Model Context Protocol. Works with Claude Code, Claude Desktop, Cursor, and Windsurf.

Setup

# Claude Code โ€” one command
claude mcp add ai-scanner npx ai-scanner-mcp

For Claude Desktop, Cursor, or Windsurf โ€” add to your MCP config file:

{
  "mcpServers": {
    "ai-scanner": {
      "command": "npx",
      "args": ["ai-scanner-mcp"]
    }
  }
}

Tools

ToolDescription
scan_directoryFull scan โ€” LLM SDKs, AI frameworks, exposed tokens, and hardcoded secrets
check_secretsSecurity check โ€” pass/fail for exposed credentials only
ai_inventoryAI stack overview โ€” which SDKs, frameworks, models are used

Once connected, ask your AI agent things like:

Example prompts

"Scan this project for any exposed API keys" ยท "Check if there are any hardcoded secrets before I commit" ยท "What AI frameworks does this codebase use?"

See ai-scanner-mcp for full documentation.


Examples

Scan a GitHub Repo

Clone any public repo and scan it in one command:

git clone --depth 1 https://github.com/user/repo /tmp/repo
npx ai-scanner /tmp/repo
rm -rf /tmp/repo

Or use the included helper scripts:

# Shell โ€” clones, scans, cleans up automatically
./examples/scan-github-repo.sh https://github.com/langchain-ai/langchainjs

# Node.js โ€” uses ai-scanner as a library, saves JSON report
node examples/scan-github-repo.js https://github.com/langchain-ai/langchainjs

Batch Scan Multiple Repos

# Edit the REPOS array in the script, then run:
node examples/scan-multiple-repos.js

# Output:
#   ๐Ÿšจ my-api          12 findings   3 critical  2 SDKs  1 frameworks
#   ๐Ÿ“ฆ my-app           8 findings   0 critical  3 SDKs  2 frameworks
#   โœ… my-lib           0 findings   0 critical  0 SDKs  0 frameworks

Use as a Library

const { Scanner } = require('ai-scanner');

const scanner = new Scanner({ rootDir: './my-project' });
const result = scanner.scan();

// Access structured results
console.log(result.stats.criticalFindings);
console.log(result.findings.filter(f => f.type === 'token'));
More examples

See the examples/ directory for pre-commit hooks, GitHub Actions workflows, and more.


CI/CD Integration

GitHub Actions

# .github/workflows/ai-scan.yml
name: AI Security Scan
on: [push, pull_request]
jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Scan for exposed tokens & secrets
        run: npx ai-scanner --tokens-only --exit-code

Pre-commit Hook

# .husky/pre-commit
npx ai-scanner --tokens-only --exit-code
Exit codes

With --exit-code, the tool returns 0 if clean, 1 if critical/high findings are detected โ€” perfect for CI gates.


About

Contributing

Contributions welcome โ€” especially new detection patterns.

Contributing Guide โ†’

License

MIT License. Free to use in personal and commercial projects.

View License โ†’

Built by Aakash Bhardwaj.