cargo-chec

Crates.iocargo-chec
lib.rscargo-chec
version0.1.8
created_at2026-01-16 05:16:15.111892+00
updated_at2026-01-22 04:56:22.683437+00
descriptionA cargo subcommand to run cargo check and output filtered error messages as a JSON array
homepage
repositoryhttps://github.com/permissionlessweb/cargo-chec
max_upload_size
id2047931
size86,925
Hard-Nett (hard-nett)

documentation

README

Cargo Chec

A cargo subcommand that wraps cargo check, filters Rust errors/warnings, and outputs them as a JSON array of strings. Perfect minimizing character/token count during agentic LLM sessions.

Companion Tool: Check out Cargo Tes for test failure filtering!

Tools in This Repository

Quick Start

  1. Install globally: cargo install cargo-chec
  2. Run in any Rust project: cargo chec

Outputs a JSON array like ["Error (severity 5)...", "Related..."]. No errors? [].

Installation

cargo install cargo-chec

Requires Rust and Cargo.

Features

  • Full cargo check support: All cargo check flags pass through (--release, --package, --all-targets, etc.)
  • Smart Filtering: Only shows errors (severity 5) and warnings (severity 4)
  • Structured Output: JSON array of strings for easy parsing
  • Flexible Input: Supports files, stdin, or default cargo check
  • Fast & Lean: Minimal dependencies (clap, serde_json)

Usage

Default: Run cargo check

cd your-rust-project
cargo chec
# Output: ["Error (severity 5) from rustc in src/main.rs at line 1:1-10: Message"]

With cargo check flags

All cargo check flags are supported:

# Check in release mode
cargo chec --release

# Check a specific package
cargo chec -p my-package

# Check all targets
cargo chec --all-targets

# Combine flags
cargo chec --release --all-targets -p my-package

Custom Input

Parse existing cargo check output instead of running cargo check:

# From file
cargo chec --input logs.json

# From stdin
cargo check --message-format=json | cargo chec --input -

Output Format

JSON array of strings:

[
  "Error (severity 5) from rustc in src/main.rs at line 10:5-15: cannot find value `x` in this scope",
  "Error (severity 4) from rustc in src/lib.rs at line 5:1-10: unused variable: `y` Related: In src/lib.rs at line 5:1-5: remove this line"
]

Empty on no issues: [].

Troubleshooting

  • Command not found? Run cargo install cargo-chec.
  • No output? Project has no errors/warnings.
  • Invalid JSON? If using custom input, ensure valid NDJSON from cargo check.

Benchmarks

============================================
Benchmark: cargo check vs cargo chec
============================================

Building cargo-chec...
Build complete.

Running cargo check --message-format=json...
  Output: 80233 characters, 37 lines

Running cargo chec (errors only)...
  Output: 5130 characters, 1 lines

Running cargo chec --include-warnings...
  Output: 12397 characters, 1 lines

============================================
Results Summary
============================================

cargo check --message-format=json:
  Characters: 80233
  Lines: 37

cargo chec (errors only):
  Characters: 5130
  Savings: 93.6%

cargo chec --include-warnings:
  Characters: 12397
  Savings: 84.5%

Contributing

Open issues/PRs on GitHub. Built for the Rust ecosystem.

Releasing

Use the provided Justfile for release tasks:

# Run all checks
just check

# Dry-run publish
just dry-run

# Full release
just release

Requires just (install via cargo install just).


For AI Agents: Workspace Specifications

This section provides structured details for AI tools to understand and interact with the codebase.

Project Structure

  • Source Code: src/main.rs (single-file binary)
  • Configuration: Cargo.toml (dependencies and metadata)
  • Scripts: scripts/ (sh scripts for release tasks)
  • Justfile: Justfile (command runner for release)
  • Build Artifacts: target/ (generated by Cargo)

Dependencies

  • clap: CLI argument parsing with cargo subcommand support
  • serde_json: JSON parsing and serialization

Build Commands

  • Build: cargo build --releasetarget/release/cargo-chec
  • Lint: cargo clippy
  • Format: cargo fmt
  • Test: cargo test
  • Publish: cargo publish

Runtime Behavior

  • Entry Point: main() in src/main.rs
  • Input: If no --input, runs cargo check --message-format=json with any additional args passed through
  • Filtering: Errors (severity 5) and warnings (severity 4) only
  • Output: JSON array of formatted error strings to stdout

Code Style

  • Idiomatic Rust with ? operator and iterator chains
  • Edition 2021, rustfmt-compliant
Commit count: 29

cargo fmt