{"record":{"id":"e14b922c58b2b144","repo":"Hmbown/CodeWhale","slug":"refusing-terminal-output-pipe-credential-handoff","errorCode":null,"errorMessage":"refusing terminal output; pipe credential handoff to the intended local client","messagePattern":"refusing terminal output; pipe credential handoff to the intended local client","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/credential_handoff.rs","lineNumber":15,"sourceCode":"use super::{runtime_overrides_for_provider, xai_auth_diagnostics};\nuse anyhow::{Context, Result, bail, ensure};\nuse codewhale_config::{\n    CliRuntimeOverrides, ConfigStore, ProviderKind, RuntimeApiKeySource,\n    auth_mode_uses_kimi_imported_token,\n};\nuse codewhale_secrets::Secrets;\nuse std::io::{ErrorKind, Write};\nuse zeroize::Zeroizing;\n\nconst TERMINAL_REFUSAL: &str =\n    \"refusing terminal output; pipe credential handoff to the intended local client\";\n\npub(crate) fn prepare_stdout(stdout_is_terminal: bool) -> Result<()> {\n    ensure!(!stdout_is_terminal, TERMINAL_REFUSAL);\n    #[cfg(unix)]\n    // SAFETY: this one-shot CLI exits before another command can inherit it.\n    unsafe {\n        let _ = libc::signal(libc::SIGPIPE, libc::SIG_IGN);\n    }\n    Ok(())\n}\n\npub(crate) fn resolve_api_key(\n    store: &ConfigStore,\n    secrets: &Secrets,\n    provider: ProviderKind,\n    runtime_overrides: &CliRuntimeOverrides,\n) -> Result<String> {\n    let resolved = store.config.resolve_runtime_options_with_secrets(\n        &runtime_overrides_for_provider(runtime_overrides, provider),\n        secrets,\n    );","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/cli/src/credential_handoff.rs#L1-L33","documentation":"Guard in prepare_stdout: the credential handoff command refuses to write the secret line when stdout is a terminal. The handoff is designed to be piped to a local client; printing a raw credential to an interactive terminal would expose it to screen, scrollback, and accidental copy.","triggerScenarios":"Thrown at crates/cli/src/credential_handoff.rs:15 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pipe stdout to the intended local client instead of a terminal, e.g. `codewhale ... | client-ingest`.","Redirect stdout to a file or FIFO consumed by the local client process.","Capture stdout programmatically from the parent process (piped ChildStdout)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}