envtrace 0.1.0

Trace where environment variables are defined and modified
Documentation

envtrace

CI License: MIT Rust

Trace where environment variables are defined and modified through shell startup sequences.

envtrace answers the question: "Where did this environment variable come from?"

Shell startup is complex -- variables can be set, overridden, or appended across dozens of files depending on your platform, shell, and whether you're in a login shell, a cron job, or a GUI app. envtrace walks the actual file chain and shows you exactly what happens.

Installation

From source

cargo install --path .

Pre-built binaries

Download from GitHub Releases.

Usage

Trace a variable (default mode)

# Trace PATH through the default shell context
envtrace PATH

# Trace in a specific context
envtrace --context login PATH
envtrace --context cron PATH

# Verbose output (shows skipped files)
envtrace --verbose PATH

Find all definitions

# Search all config files regardless of context
envtrace --find PATH
envtrace --find JAVA_HOME

Compare across contexts

# See how a variable differs between login and cron
envtrace -C login,cron PATH

Trace shell functions

# Trace a function definition
envtrace -F my_function

# Find all definitions of a function
envtrace -F --find my_function

# Compare a function across contexts
envtrace -F -C login,interactive my_function

JSON output

envtrace --format json PATH
envtrace -F --format json my_function

System sanity checks

# Check config files for common issues
envtrace --check

Platform Support

Platform Shell Contexts
macOS zsh login, interactive, non-interactive, launchd agent/daemon
Linux bash login, interactive, non-interactive (cron), systemd service/user

envtrace understands platform-specific differences:

  • macOS uses /etc/zshenv, /etc/zprofile, ~/.zshrc, etc.
  • Linux uses /etc/profile, /etc/profile.d/*.sh, ~/.bashrc, etc.
  • macOS launchd agents use plist files (does not inherit shell env)
  • Linux systemd services use unit files and environment.d

Building from Source

Requires Rust edition 2024 (rustc 1.85+).

git clone https://github.com/FlerAlex/envtrace.git
cd envtrace
cargo build --release

The binary will be at target/release/envtrace.

Running tests

cargo test
cargo fmt --check
cargo clippy

License

MIT