Skip to main content

CodeGuard

Fast, offline static analysis that finds security anti-patterns in Python, JavaScript, and TypeScript — and drops into every gate of your workflow (editor, pre-commit, PR/CI, scheduled audit) from a single config file.

Status: 2.1.0 (beta). Rule IDs, the Finding/JSON schema, config keys, and exit codes are a stable contract from 2.0. See migration notes if you used the 0.1 alpha.

License Python CI PyPI


What it does

CodeGuard scans Python, JavaScript, and TypeScript and reports security findings. Each finding has a stable rule ID, severity, CWE/OWASP mapping, and a plain-English fix suggestion.

Current rules (see docs/rules/ for detail):

ID What it catches Severity CWE Languages
CG-SEC-001 SQL built with f-strings / % / .format() HIGH CWE-89 Python
CG-SEC-002 Hardcoded passwords, API keys, tokens HIGH CWE-798 Python
CG-SEC-003 eval() / exec() on non-literal input HIGH CWE-95 Python
CG-SEC-004 pickle.loads / yaml.load without SafeLoader HIGH CWE-502 Python
CG-SEC-005 subprocess(..., shell=True) with non-literal args HIGH CWE-78 Python
CG-SEC-101 eval / new Function / string timers on dynamic input HIGH CWE-95 JS, TS
CG-SEC-102 child_process.exec with a dynamic command HIGH CWE-78 JS, TS
CG-SEC-103 innerHTML / document.write assigned a non-literal HIGH CWE-79 JS, TS
CG-SEC-104 dangerouslySetInnerHTML with a non-literal value HIGH CWE-79 JS, TS
CG-SEC-105 Hardcoded passwords, API keys, tokens HIGH CWE-798 JS, TS
CG-SEC-106 Math.random() used for a token / secret / id MEDIUM CWE-338 JS, TS

What it does not do (yet)

  • Baseline / diff scanning, a CI-native command, packaged distribution (planned for v2.0)
  • AI-generated-code detection (deferred to a post-2.0 experimental module)
  • Web dashboard or REST API

Install

pipx install codeguard-cli      # or: uv tool install codeguard-cli
pip install codeguard-cli       # into the current environment

# or from source:
git clone https://github.com/mevichitra/codeguard
cd codeguard
pip install -e ".[dev]"

The PyPI project is codeguard-cli; the installed command is codeguard.

Requires Python 3.10+. No database, no Redis, no Docker needed.


Usage

# Scan a file or directory
codeguard scan myproject/

# Output as JSON
codeguard scan myproject/ --format json

# Output as SARIF (for GitHub code scanning)
codeguard scan myproject/ --format sarif > results.sarif

# Only run specific rules
codeguard scan myproject/ --rule CG-SEC-001 --rule CG-SEC-002

# Only report HIGH and above
codeguard scan myproject/ --severity high

Example output (human format):

myproject/auth.py:12:4  [CG-SEC-001] HIGH  SQL query built with string formatting
  → Use parameterized queries: cursor.execute("SELECT ... WHERE id = %s", (user_id,))

myproject/config.py:5:0  [CG-SEC-002] HIGH  Hardcoded secret: password
  → Load secrets from environment variables or a secrets manager.

2 findings  (2 high, 0 medium, 0 low)

Exit codes: 0 = no findings, 1 = findings found, 2 = error.

Inline suppression

query = f"SELECT * FROM users WHERE id = {uid}"  # codeguard: ignore[CG-SEC-001]

Suppressed findings still appear with suppressed: true in JSON/SARIF output.

Config file

Place a codeguard.toml in your project root:

[codeguard]
exclude = ["tests/", "migrations/"]
severity = "medium"   # ignore findings below this level

[codeguard.rules]
disabled = ["CG-SEC-002"]  # not yet

(Config file support is on the roadmap; not yet implemented.)


CI integration

GitHub Actions

- name: Run CodeGuard
  run: |
    pip install codeguard-cli
    codeguard scan src/ --format sarif > codeguard.sarif

- name: Upload SARIF
  uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: codeguard.sarif

Zed editor integration

CodeGuard includes a development extension for Zed that displays findings as native editor diagnostics while keeping all analysis local.

# Install this checkout so Zed can find the command.
pipx install -e .
# or: uv tool install -e .

In Zed, open Extensions, select Install Dev Extension, and choose the editors/zed directory. The extension starts codeguard lsp, scans the workspace on startup, and refreshes open files after edits. Findings appear as warnings. Clicking a CodeGuard rule link opens the local dashboard; the 🛡 Open CodeGuard Dashboard quick action provides an additional route.

The dashboard is a local Markdown report stored in the user cache rather than the analyzed repository. It can also be generated directly:

codeguard dashboard .
codeguard dashboard . --output codeguard-report.md

The LSP can also be started directly by any compatible editor:

codeguard lsp

Contributing

See CONTRIBUTING.md for how to add a rule or file a bug.
Adding a rule requires: one rule file + two test fixtures (vulnerable + safe). See the rule authoring guide.


Project status and roadmap

2.0 (beta). Rule IDs, the Finding / JSON schema, config keys, and the exit-code contract are stable. Full details in the changelog and docs/.

On the roadmap:

  1. Light intraprocedural taint tracking (source → sink, sanitizer-aware) to cut false positives further
  2. A Semgrep-compatible YAML rule subset for custom rules
  3. Autofix (--fix) for the safe-fix rules
  4. Standalone single-file binaries and a Homebrew tap
  5. Published editor extensions and managed standalone language-server binaries
  6. Optional, offline AI-assisted triage (confidence + rationale, no code leaves the machine)

License

Apache-2.0. See LICENSE.

Contributions are accepted under the Developer Certificate of Origin (DCO). Sign your commits with git commit -s.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codeguard_cli-2.1.0.tar.gz (194.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codeguard_cli-2.1.0-py3-none-any.whl (86.9 kB view details)

Uploaded Python 3

File details

Details for the file codeguard_cli-2.1.0.tar.gz.

File metadata

  • Download URL: codeguard_cli-2.1.0.tar.gz
  • Upload date:
  • Size: 194.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for codeguard_cli-2.1.0.tar.gz
Algorithm Hash digest
SHA256 734f9586470cedcee94a6a691f840b24ae889efba9429cb5b286d89d084ca36c
MD5 169843bb0590bbb26a65d8bf42b8f6b5
BLAKE2b-256 1ab31e550abe2f35764d079605cb98e1f904db52ed7793a7bdf06f315810f9ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for codeguard_cli-2.1.0.tar.gz:

Publisher: release.yml on mevichitra/codeguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codeguard_cli-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: codeguard_cli-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 86.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for codeguard_cli-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b4a49c3d8386ca7acb909a37ed125011558f58f68ad49b3a1a46ce994af58904
MD5 f548a3553026485de9dd07e0c7782bf2
BLAKE2b-256 abd260811d67717a6ed96184ec72d2c079c4edf66b0f880039e1d1bc00b74468

See more details on using hashes here.

Provenance

The following attestation bundles were made for codeguard_cli-2.1.0-py3-none-any.whl:

Publisher: release.yml on mevichitra/codeguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 files

2.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page