MCPcopy Index your code
hub / github.com/astral-sh/hawk

github.com/astral-sh/hawk @0.1.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.1.3 ↗ · + Follow
353 symbols 839 edges 30 files 1 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

hawk

CI crates.io License

A workspace-aware Cargo lint for unnecessary Rust visibility.

Experimental: This project was authored by GPT-5.5 and is not intended for public consumption. Use at your own risk.

Hawk finds pub declarations that are unused or can be restricted to pub(crate) when a Cargo workspace builds one or more shipped binaries. It also finds explicit restricted visibility modifiers that can be removed. Optionally, it can suggest restricting pub(crate) declarations to pub(super).

Motivation

Hawk is intended for projects like Ruff and uv, where the product is a binary but the workspace itself is decomposed into many crates. In such projects, the workspace is largely the only client of its pub APIs: pub is commonly needed only to make symbols visible across crates within the workspace.

rustc's dead_code lint identifies unused, unexported items, and its opt-in unreachable_pub lint identifies pub items that cannot be reached outside a single crate. It does not perform the closed-world analysis needed to decide which workspace-internal pub APIs are actually required. Hawk assumes that the workspace represents the world and identifies dead code and unnecessarily public symbols across crates within a single workspace.

Highlights

  • Analyzes public surface across an entire Cargo workspace, starting from configured production targets.
  • Reports hawk::dead_public for unused public items, hawk::unnecessary_public for pub items that can become pub(crate), and hawk::unnecessary_restricted_visibility for restricted items that can become private.
  • Optionally reports hawk::unnecessary_crate_visibility for pub(crate) items that can become pub(super).
  • Models production separately from tests, benches, examples, and doctests.
  • Applies machine-applicable visibility fixes through cargo fix.
  • Uses Clippy-style -A/-W/-D lint levels for incremental CI adoption.

Installation

Hawk uses rustc_private and must run with the exact Rust toolchain it was built against. Prebuilt releases are available for macOS and Linux, but they are not independent of Rust. Install the normal Rust 1.95.0 toolchain:

rustup toolchain install 1.95.0

Install the latest prebuilt release:

curl --proto '=https' --tlsv1.2 -LsSf \
  https://github.com/astral-sh/hawk/releases/latest/download/cargo-hawk-installer.sh | sh

The installer places cargo-hawk and its internal cargo-hawk-driver executable together on your PATH. You can instead download the archive for your platform from GitHub Releases and place both executables on your PATH in the same directory. A prebuilt release does not require rustc-dev, RUSTC_BOOTSTRAP, or a source build.

Hawk validates the selected compiler before analysis. If a workspace selects another Rust version, invoke Hawk with its pinned toolchain:

cargo +1.95.0 hawk

To build Hawk from source, install the compiler development component:

rustup toolchain install 1.95.0 --component rustc-dev

To install the current development version from Git:

RUSTC_BOOTSTRAP=1 cargo +1.95.0 install --locked \
  --git https://github.com/astral-sh/hawk cargo-hawk

Install a released version from crates.io with:

RUSTC_BOOTSTRAP=1 cargo +1.95.0 install --locked cargo-hawk

RUSTC_BOOTSTRAP=1 is required during installation because cargo install does not use this repository's Cargo configuration when it compiles the installed package.

Getting started

Declare each shipped binary in a workspace-root hawk.toml:

[[production]]
package = "app"
bin = "app"
reason = "shipped application binary"

Analyze the workspace:

cargo hawk \
  --manifest-path /path/to/workspace/Cargo.toml

To enforce findings in CI or apply visibility fixes:

cargo hawk \
  --manifest-path /path/to/workspace/Cargo.toml \
  -D warnings

cargo hawk \
  --manifest-path /path/to/workspace/Cargo.toml \
  --fix

Documentation

  • Using Hawk: running analysis, CI enforcement, fixes, and cross-compilation.
  • Configuration: production targets, overrides, exclusions, and target selectors.
  • Architecture: how Hawk differs from Clippy and how the workspace analysis is implemented.
  • MVP design: the original analysis scope and design rationale.

Status

Hawk is experimental. It assumes workspace library crates are internal to the configured binary product unless they are explicitly excluded from analysis. Because it integrates with compiler internals, it is pinned to Rust 1.95.0. Hawk was authored entirely by GPT-5.5 in Codex.

License

hawk is licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in hawk by you, as defined in the Apache-2.0 license, shall be dually licensed as above, without any additional terms or conditions.

Made by Astral

Extension points exported contracts — how you extend this code

ProductContext (Interface)
(no doc) [1 implementers]
tests/fixtures/basic/library/src/lib.rs
RefinedBuildContext (Interface)
(no doc) [1 implementers]
tests/fixtures/basic/library/src/lib.rs
PrivateContext (Interface)
(no doc) [1 implementers]
tests/fixtures/basic/library/src/lib.rs
PublicRenderer (Interface)
(no doc) [1 implementers]
tests/fixtures/basic/library/src/lib.rs
InternalRenderer (Interface)
(no doc) [1 implementers]
tests/fixtures/basic/library/src/lib.rs

Core symbols most depended-on inside this repo

path
called by 79
src/config.rs
fragments
called by 36
src/graph.rs
analyze
called by 29
src/graph.rs
id
called by 21
src/driver.rs
apply
called by 14
src/config.rs
target
called by 13
src/config.rs
candidate_crates
called by 12
src/config.rs
node
called by 10
src/graph.rs

Shape

Function 226
Class 64
Method 45
Enum 13
Interface 5

Languages

Rust100%

Modules by API surface

src/graph.rs74 symbols
tests/fixtures/basic/library/src/lib.rs66 symbols
src/cli.rs58 symbols
src/config.rs44 symbols
src/driver.rs42 symbols
tests/end_to_end.rs14 symbols
tests/fixtures/crate_visibility_fixes/library/src/lib.rs9 symbols
tests/fixtures/grouped_reexport_fixes/library/src/lib.rs7 symbols
tests/fixtures/basic/unit_support/src/lib.rs5 symbols
tests/fixtures/non_production_targets/library/src/lib.rs4 symbols
tests/fixtures/production_consumers/library/src/lib.rs3 symbols
tests/fixtures/doctest_consumers/library/src/lib.rs3 symbols

For agents

$ claude mcp add hawk \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact