debug-env-variables

Diagnose environment variable loss across shell boundaries and subprocess layers.

6|1|Updated May 11, 2026
One-click install
npx skills add https://github.com/yakeworld/Synthos --skill debug-env-variables-yakeworld
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: debug-env-variables
Source: https://github.com/yakeworld/Synthos/tree/main/skills/private/extended/external-automation/debug-env-variables
Command: npx skills add https://github.com/yakeworld/Synthos --skill debug-env-variables-yakeworld

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Environment variables that work in an interactive shell often disappear in scripts, bash -c invocations, or Python subprocesses, leaving API keys and credentials empty at runtime with no obvious cause. ## Core Features & Use Cases - Layer-by-layer diagnosis: Trace a missing variable through the parent process, interactive shell, bash -c, and Python subprocess layers to pinpoint exactly where it vanishes (.bashrc guard, quoting boundary, or never set). - Reliability-ordered fixes: Receive fixes ranked by reliability — moving exports before the case $- in *i*) guard, setting BASH_ENV, file-based .api_key fallback, or /etc/environment. - Use Case: Your CI job or subprocess.run(shell=True) call reads an empty API key even though echo $API_KEY works in your terminal. This Skill identifies the non-interactive shell guard as the culprit and recommends a file-based credential fallback instead of relying on .bashrc. ## Quick Start Debug why the environment variable SEMANTIC_SCHOLAR_API is set in my interactive shell but empty when my Python script runs via subprocess.

Frequently Asked Questions about debug-env-variables

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why do environment variables work in my terminal but not in scripts?

Bash's .bashrc contains a `case $- in *i*)` guard that returns early for non-interactive shells, so exports placed after it are invisible to scripts. Move exports before the guard or set BASH_ENV to load them in non-interactive shells.

How do I fix subprocess.run(shell=True) losing environment variables?

The bash -c shell spawned by subprocess.run does not source .bashrc, and nested quoting can consume exports before Python sees them. Use a file-based fallback where Python reads a .api_key file when os.environ is empty, or pass variables explicitly via the env parameter.

Is .bashrc reliable for API keys in CI or cron jobs?

No, .bashrc exports are unreliable for automated processes like CI, cron, and subprocesses because non-interactive shells may never source it. Use /etc/environment or a file-based credential fallback instead, and never store secrets in .bashrc.

How do I find where an environment variable disappears?

Test the variable at each layer: interactive shell with echo, non-interactive with bash -c, after sourcing .bashrc, and inside Python via os.environ. The layer where it vanishes identifies the cause: the .bashrc guard, a quoting boundary, or the variable never being set.

What is the most reliable way to pass credentials to automated processes?

A file-based fallback is the most reliable approach: store the key in a gitignored file like .api_key and have the application read it when os.environ is empty. For system-wide coverage with root access, /etc/environment is read by all PAM-authenticated sessions.