Skip to main content

Agent Code Guard

Agent Code Guard project mark

Deterministic maintainability guardrails for source code and Markdown changed by a human or coding agent.

Production Analysis PyPI Python 3.10–3.14 License: MIT

Agent Code Guard measures file size, callable size, structural nesting, cyclomatic complexity, Markdown document size, and Markdown section size. It reports deterministic PASS, REVIEW, or FAIL results without rewriting your files.

It complements rather than replaces tests, compilers, linters, formatters, security tools, and design judgment.

Why it is useful

Code Guard surfaces files and callables that are becoming difficult to review, deep nesting and complex decision logic, and Markdown specifications that are losing navigability. It gives humans and agents the same repeatable review point after edits and can prevent silent LOC growth beyond an explicit project policy.

What humans gain

  • Consistent signals across supported languages and Markdown, whether a change came from a person or an agent.
  • A shared PASS/REVIEW/FAIL vocabulary: continue, inspect with judgment, or block pending correction or an authorized exception.
  • The same checks locally and in CI, with no configuration required for ordinary use and no automatic source mutation.

What agents gain

  • Deterministic feedback after edits and consistent process exits.
  • Changed-file scope instead of unnecessary full-repository scans.
  • Compact JSON that omits normalized pass noise while retaining actionable findings and result structure.
  • Named required policies, so only relevant guidance needs to be loaded, plus a version-matched bundled skill with REVIEW-judgment and anti-gaming rules.

This workflow is designed to reduce unnecessary output and policy loading. It still requires the source context needed to understand and judge each finding; it makes no claim about measured token savings.

Installation

pipx isolates the command from project environments:

pipx install agent-code-guard
code-guard --version
code-guard doctor

--version confirms the installed distribution identity. doctor checks the active installation's health. See the usage guide for virtual environment, uv, and developer alternatives.

Ask your agent to adopt it

Copy this prompt to a coding agent:

Consult the official Agent Code Guard repository and documentation. Install the published distribution in an isolated supported way, preferably with pipx; verify code-guard --version and run code-guard doctor. Locate the installed version-matched skill with code-guard --skill-path, and use or export only that skill through the documented mechanism. Inspect this repository without creating a LOC baseline and use changed-work scope. Ask before exporting into a persistent skill directory, changing persistent agent or platform configuration, or configuring hooks. Never weaken thresholds, exclusions, configuration, or baselines merely to silence findings.

Five-minute start

From a Git worktree, inspect the current change:

code-guard . --changed-only

Git supplies the changed candidates; every enabled and applicable guard runs. No configuration is needed. A REVIEW asks for inspection and judgment, not an automatic refactor. Outside Git, pass the exact edited files instead, such as code-guard src/app.py docs/guide.md.

See the agent workflow guide for repeated human and agent use.

Recommended workflow

edit supported code or Markdown
        ↓
run Code Guard on changed scope
        ↓
PASS → continue
REVIEW → inspect, justify or genuinely improve
FAIL → fix or obtain an explicitly authorized exception
        ↓
rerun
        ↓
report the result before completion

Use code-guard . --changed-only --json --json-mode compact for a structured, low-noise manual agent check. Hooks are optional, platform-owned, and require user authorization; Code Guard does not install them. The workflow guide owns the complete manual and hook-assisted process.

Interpreting results

  • PASS — no special action; exit 0.
  • REVIEW — inspect and decide whether genuine structural improvement is warranted; normally exit 1.
  • Completed FAIL — blocks normal completion until fixed or an explicitly authorized exception applies; exit 2 with a completed report on stdout.
  • An argparse usage or invalid-choice error exits 2, writes usage/error text to stderr, and produces no completed report.
  • Other Code Guard tool, configuration, scope, or provider errors exit 3.

--ci makes REVIEW nonblocking at the process level by changing its exit to 0; it does not hide the findings or change FAIL and tool-error exits.

Never game a metric. Do not create artificial helpers, files, abstractions, formatting, exclusions, or policy changes merely to lower a measurement. A REVIEW is not proof of a defect or a mandatory refactor.

Guard reference

Guard Default
File LOC REVIEW >400, FAIL >600
Callable size REVIEW >80 physical LOC
Structural nesting REVIEW >4
Cyclomatic complexity REVIEW >15
Markdown document size REVIEW >800 physical lines
Markdown direct-section size REVIEW >200 physical lines

Comparisons are strictly greater-than, so equality passes. All guards except file LOC are REVIEW-only; only file LOC can FAIL. A new guard must provide distinct, deterministic value rather than duplicate conventional tooling. See Guard admission.

Result and JSON reference

Every completed analysis reports selected, analyzed, inapplicable, and all-guard-excluded file counts. Bare --json is the compatible full output; --json-mode debug is byte-identical for the same completed invocation, while --json-mode compact removes only normalized pass findings and retains the result, scope, required policies, guards, ordering, and actionable findings. Named modes require --json. See Usage for the schema and option contract.

Common scope commands

# Current Git work
code-guard . --changed-only

# Pull request or branch comparison
code-guard . --base-ref origin/main --ci

# Deliberate full audit
code-guard .

The base ref must exist in the chosen environment. Changed work is not a full audit; do not repeatedly scan unrelated files after every edit.

Supported languages and formats

Syntax guards support Python, Go, Kotlin, C#, Java, JavaScript, TypeScript, JSX, TSX, Vue JavaScript/TypeScript script regions, C++, Rust, PHP, Swift, and Dart. Markdown guards apply to .md files.

Generic .h files are not syntax-dispatched; .markdown is not enabled; Vue template and style regions are not executable syntax input; and unsupported artifacts are inapplicable. Malformed applicable syntax or a required provider failure is a fail-closed tool error. See Language support.

Skill integration

An installed distribution includes the matching Code Guard skill payload:

code-guard --skill-path
code-guard --export-skill <target-directory>

Skill activation is platform-specific and is not performed by pipx or Code Guard. See Skill distribution. The checkout compatibility runner is for repository development, not normal installation.

Configuration

Built-in defaults require no configuration. Configure a project only for a concrete policy reason; see the configuration guide. The LOC baseline is an explicit adoption tool for established legacy repositories, not an ordinary-use requirement or a way to silence findings.

Trust, CI, and platform support

CI installs Agent Code Guard and analyzes its own real checkout. REVIEW findings remain visible but non-blocking, while FAIL findings and tool errors block the workflow; the repository intentionally uses no LOC baseline.

The maintained interpreter range is CPython 3.10–3.14. See Platform support for supported binary platforms and source-build boundaries.

Documentation

Feedback, security, and license

Report defects through the bug report form, propose measurements through the candidate guard form, and follow the security policy for vulnerabilities.

Agent Code Guard grew from the Agent LOC Guard prototype and is now the canonical implementation. Licensed under the MIT License.

Download files

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

Source Distribution

agent_code_guard-0.2.0.tar.gz (50.2 kB view details)

Uploaded Source

Built Distribution

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

agent_code_guard-0.2.0-py3-none-any.whl (64.9 kB view details)

Uploaded Python 3

File details

Details for the file agent_code_guard-0.2.0.tar.gz.

File metadata

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

File hashes

Hashes for agent_code_guard-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0422161ed9b95335517c50e29e9f05250310f410a8cb123125c8ca4c4695488d
MD5 6e6a090a4eb2851a9a7458319e2e05c3
BLAKE2b-256 d8e08341261ff85cf3df5e502a4c2fc2dcaf762712a57ef7a0387301399747ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_code_guard-0.2.0.tar.gz:

Publisher: release.yml on stef-k/agent-code-guard

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

File details

Details for the file agent_code_guard-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agent_code_guard-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 626191894b5ef63324479afffcf9bdd826a0d69d95d2c67ebf8cc64107935061
MD5 c0ec19dc69c8ef402d359834f52a7e18
BLAKE2b-256 91369774e815ab9b62d073d866ec36ca41999bd986024131e4a328c308ba3cf2

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_code_guard-0.2.0-py3-none-any.whl:

Publisher: release.yml on stef-k/agent-code-guard

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

Release history Release notifications | RSS feed

0.3.1

2 files

0.3.0

2 files

This release

0.2.0 This release

2 files

0.1.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