From 5c9723574b788d516180ee2e9d372144276d0535 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Sat, 11 Apr 2026 16:56:00 -0300 Subject: [PATCH] fix(tui): cache github cli availability Cache the resolved `gh` executable path for the life of the process so status line and terminal title refreshes do not repeatedly scan `PATH`. This keeps animated title refreshes cheap when `github-pr` is configured. --- codex-rs/tui/src/github_pr.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/codex-rs/tui/src/github_pr.rs b/codex-rs/tui/src/github_pr.rs index a4cb2356dd..fbc6ab09b5 100644 --- a/codex-rs/tui/src/github_pr.rs +++ b/codex-rs/tui/src/github_pr.rs @@ -16,6 +16,7 @@ use std::ffi::OsStr; use std::path::Path; use std::path::PathBuf; use std::process::Stdio; +use std::sync::OnceLock; use serde::Deserialize; use tokio::process::Command; @@ -24,6 +25,8 @@ use tokio::time::timeout; const GH_LOOKUP_TIMEOUT: Duration = Duration::from_secs(2); +static GH_PATH: OnceLock> = OnceLock::new(); + /// Compact GitHub pull request metadata that can be rendered in status surfaces. /// /// The number is used for the visible `PR #123` label and the URL is used for @@ -91,7 +94,9 @@ pub(crate) async fn lookup_current_branch_pull_request(cwd: &Path) -> Option Option { - resolve_gh_path_from_path(std::env::var_os("PATH").as_deref()) + GH_PATH + .get_or_init(|| resolve_gh_path_from_path(std::env::var_os("PATH").as_deref())) + .clone() } fn resolve_gh_path_from_path(path_env: Option<&OsStr>) -> Option {