agent-arch
Deterministic codebase architecture guardrails & sub-15ms topology indexer for AI coding agents.
AI coding agents (Claude Code, Codex, Cursor) often edit files with local context only. This causes architectural erosion:
- Low-level modules import high-level UI modules to save time.
- Refactoring steps silently break exported symbols and APIs.
- Reading whole repositories wastes tens of thousands of tokens per turn.
agent-arch provides a zero-token, sub-15ms AST safety net. It builds a deterministic topology map and enforces strict layering rules with a physical Git hook.
Quick Start
Two commands to protect your codebase from AI coding agent erosion:
# 1. Query upstream and downstream dependencies for an agent (< 15ms)
uvx agent-arch --query <module_or_symbol>
# 2. Install Git pre-commit hook and AGENTS.md rules in one command
uvx agent-arch --init
The diagram uses example layer names. Configure layer ranks for your project.
The sub-15ms figure applies to cache reads. Local architecture checks use zero LLM tokens. These checks cover layering and public APIs. They do not prove that all code is correct. See the benchmark report and image prompts and settings.
Features
- Sub-15ms Index Latency: Deterministic AST scanning with compact JSON caching.
- Zero Token Verification: Check architectural rules locally with zero LLM API cost.
- No Reverse Imports: Prevent lower layers from importing upper layers.
- Public API Safety Net: Detect breaking changes and require backward-compatible facade shims.
- Zero External Dependencies: Pure standard library Python with optional
orjsonacceleration.
Comparison with Existing Tools
| Tool | Primary Purpose | Latency | Token Cost | Architecture Guardrails | Agent Surgical Query |
|---|---|---|---|---|---|
agent-arch (This tool) |
AI Agent Orientation & Guardrail | < 15 ms | 0 tokens | YES (Layering & API shims) | YES (< 30 lines Markdown) |
Aider repo-map |
Whole-repo symbol ranking for prompts | 500 ms - 2 s | High (prompt bloat) | NO (Architecture-blind) | NO (Dumps bulk symbols) |
| Tach / Import Linter | CI boundary enforcement for monoliths | 200 ms - 3 s | 0 tokens | YES (Module boundaries) | NO (No query API for agents) |
ast-grep (sg) |
Single-file AST structural pattern matching | < 50 ms | 0 tokens | NO (No global dependency graph) | NO (File-local only) |
| arch-analyzer | LLM-based architecture review wrapper | 30 s - 3 min | Very High (10k+ tokens) | Fuzzy / Probabilistic | NO (Heavy report generator) |
Key Differences
- vs Aider
repo-map: Aider ranks symbols with PageRank to feed large context into LLM prompts, but it does not prevent architectural erosion.agent-archenforces strict single-direction layering and API compatibility checks. - vs Tach / Import Linter: Tach and Import Linter target human CI pipelines with terminal error outputs. They lack a sub-15ms surgical query interface for agents to look up upstream dependencies and downstream callers on-demand.
- vs ast-grep:
ast-grepis a powerful single-file CST pattern matcher, but it cannot resolve imports across files or detect circular dependency cycles. - vs arch-analyzer / LLM Reviewers: Wrapping LLMs to review code is slow, expensive, and non-deterministic.
agent-archuses deterministic, zero-token local AST analysis that runs on every git commit.
Installation
Run directly with uvx (no prior installation needed):
uvx agent-arch --query <symbol_or_module>
uvx agent-arch-guard --strict
Or install via uv / pip:
uv add --dev agent-arch
# or
pip install agent-arch
Usage
0. One-Click Guardrail Installation (--init)
Enforce guardrails on any repository with a single command:
uvx agent-arch --init
This command automatically:
- Installs a Git pre-commit hook (
.git/hooks/pre-commit) that physically blocks anygit commitviolating architectural rules. - Appends architectural guidelines to
AGENTS.mdso AI agents (Claude Code, Codex, Cursor) know the constraints before writing code. - Initializes
.agent_arch/cache and defaultpyproject.tomlsettings.
1. Query Codebase Topology (Surgical Agent Orientation)
Display a clean architectural summary of your codebase:
agent-arch
Query a specific module to inspect its layer, classes, upstream imports, and downstream callers:
agent-arch --query relabel.py
Locate a symbol across the entire repository:
agent-arch --query UserEntity
2. Verify Architecture Integrity (CI & Preflight Guardrails)
Run layering and compatibility checks:
agent-arch-guard
Compare API compatibility across Git revisions:
agent-arch-guard --base origin/main
Compare two files directly:
agent-arch-guard --compare-files old_module.py new_module.py
Configuration
Add an optional [tool.agent-arch] section to your pyproject.toml to customize layers and scanned directories:
[tool.agent-arch]
scan_dirs = ["src"]
exclude_dirs = [".git", ".venv", "tests", "dist"]
cache_path = ".agent_arch/index.json"
cache_ttl = 300.0
[tool.agent-arch.layers]
0 = { name = "Domain", description = "Base entities and types", match = ["domain", "models", "types"] }
1 = { name = "Storage", description = "Database and file I/O", match = ["storage", "io", "db"] }
2 = { name = "Core", description = "Business logic and algorithms", match = ["services", "core", "algorithms"] }
3 = { name = "Workflow", description = "Controllers and handlers", match = ["controllers", "handlers"] }
4 = { name = "UI", description = "User interface and entrypoints", match = ["ui", "views", "cli", "main"] }
Benchmarks
See BENCHMARK_AND_VERIFICATION.md for stress test records across 2,300+ modules and sub-1ms cache latency measurements.
License
MIT License.
Metadata
Release files for agent-arch 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| agent_arch-0.1.1.tar.gz | 68.0 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agent_arch-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 90.3 kB
Release files / agent_arch-0.1.1.tar.gz
| Download URL | agent_arch-0.1.1.tar.gz |
|---|---|
| Size | 68.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
67ec682d8280642b50214262af02536e422e39115511bac150b0ed7d3af3fc9f
|
|
BLAKE2b-256 checksum How to use checksums |
77431404c2a97c6559aa9f5cdec7a373e727347194fd75eaeb680a83aec81b72
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logRelease files / agent_arch-0.1.1-py3-none-any.whl
| Download URL | agent_arch-0.1.1-py3-none-any.whl |
|---|---|
| Size | 22.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f49e443a88399a10cc68ca1dc82f87a9eaab4c95345711d68502cee15cd1b5de
|
|
BLAKE2b-256 checksum How to use checksums |
18e031f3821df995d42209e4df9aea7870faa632ebe2d3ed72b8511c1aec7049
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logSecurity for agent-arch 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for agent_arch-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.