sxyazi/yazi · error
No `YAZI_ID` environment variable found.
Error message
No `YAZI_ID` environment variable found.
What it means
`CommandPub::receiver` resolves the target Yazi instance's id from the `YAZI_PID` environment variable (despite the error mentioning `YAZI_ID`). When `YAZI_PID` is unset or empty, it bails because there is no receiver to send the `ya` command to.
Source
Thrown at yazi-cli/src/args.rs:131
pub(super) kind: String,
/// Send the message with a string body.
#[arg(long)]
pub(super) str: Option<String>,
/// Send the message with a JSON body.
#[arg(long)]
pub(super) json: Option<String>,
/// Send the message as a list of strings.
#[arg(long, num_args = 0..)]
pub(super) list: Vec<String>,
}
impl CommandPub {
#[allow(dead_code)]
pub(super) fn receiver() -> Result<Id> {
if let Some(s) = std::env::var("YAZI_PID").ok().filter(|s| !s.is_empty()) {
Ok(s.parse()?)
} else {
bail!("No `YAZI_ID` environment variable found.")
}
}
}
#[derive(clap::Args)]
pub(super) struct CommandPubTo {
/// Receiver ID.
#[arg(index = 1)]
pub(super) receiver: Id,
/// Kind of message.
#[arg(index = 2)]
pub(super) kind: String,
/// Send the message with a string body.
#[arg(long)]
pub(super) str: Option<String>,
/// Send the message with a JSON body.
#[arg(long)]
pub(super) json: Option<String>,View on GitHub (pinned to 5f901b886b)
Solutions
- Run `ya` from within the shell/terminal session launched by a running Yazi instance, which exports `YAZI_PID`.
- Manually export `YAZI_PID=<pid of yazi>` before calling `ya`.
- Verify a Yazi instance is actually running (`pgrep yazi`) and that it is a version that exports `YAZI_PID`.
Example fix
// before (bare shell) ya mount // after export YAZI_PID=$(pgrep -x yazi | head -1) ya mount
Defensive patterns
Strategy: try-catch
Validate before calling
if [ -z "$YAZI_PID" ]; then echo "not inside a yazi session (YAZI_PID unset)" >&2; exit 1; fi
Try / catch
match CommandPub::receiver() {
Ok(id) => id,
Err(_) => { eprintln!("run `ya` inside a shell launched by yazi, or export YAZI_PID"); return; }
} Prevention
- Only run `ya` commands from the shell/terminal spawned by Yazi.
- Export YAZI_PID manually when scripting against a known instance.
- Check `pgrep yazi` before invoking `ya` in automation.
When it happens
Trigger: Invoking a `ya pub`/`ya pub-to` command outside of a Yazi-spawned shell where `YAZI_PID` was never exported; running `ya` from a separate terminal that Yazi did not start; the env var being emptied by a wrapper script.
Common situations: Running `ya` commands in a fresh terminal instead of the one hosting Yazi; using tmux panes not spawned by Yazi; testing the CLI standalone.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- failed to determine the Cargo bin directory
- {}
- Unknown error
- Expected custom payload of kind `{reply_kind}`
- Connection closed before receiving reply
AI-assisted analysis of sxyazi/yazi@5f901b886b (2026-09-02).
Data as JSON: /api/errors/6fb7d885b7e6e11e.
Report an issue: GitHub.