From 06457825ab242c8a839813895e5feb2e30af9efc Mon Sep 17 00:00:00 2001 From: Daniel Edrisian Date: Tue, 26 Aug 2025 10:03:30 -0700 Subject: [PATCH] Use $CODEX_HOME instead --- codex-rs/README.md | 2 +- codex-rs/core/src/codex.rs | 15 +++++++++------ codex-rs/core/src/custom_prompts.rs | 10 ++++++---- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/codex-rs/README.md b/codex-rs/README.md index 377bcfbbdd..98d2b63d78 100644 --- a/codex-rs/README.md +++ b/codex-rs/README.md @@ -67,7 +67,7 @@ codex completion fish Save frequently used prompts as Markdown files and reuse them quickly from the slash menu. -- Location: Put files in `~/.codex/prompts/` (create the folders if they don’t exist). +- Location: Put files in `$CODEX_HOME/prompts/` (defaults to `~/.codex/prompts/`). - File type: Only Markdown files with the `.md` extension are recognized. - Name: The filename without the `.md` extension becomes the slash entry. For a file named `my-prompt.md`, type `/my-prompt`. - Content: The file contents are sent as your message when you select the item in the slash popup and press Enter. diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 5362d706ae..2076bda7df 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -1281,12 +1281,15 @@ async fn submission_loop( let sub_id = sub.id.clone(); // Discover prompts under the default prompts dir (includes content). - let custom_prompts: Vec = tokio::task::spawn_blocking(|| { - let dir = crate::custom_prompts::default_prompts_dir(); - crate::custom_prompts::discover_prompts_in(&dir) - }) - .await - .unwrap_or_default(); + let custom_prompts: Vec = + tokio::task::spawn_blocking( + || match crate::custom_prompts::default_prompts_dir() { + Some(dir) => crate::custom_prompts::discover_prompts_in(&dir), + None => Vec::new(), + }, + ) + .await + .unwrap_or_default(); let event = Event { id: sub_id, diff --git a/codex-rs/core/src/custom_prompts.rs b/codex-rs/core/src/custom_prompts.rs index fef0073bd7..0c92a1c0d3 100644 --- a/codex-rs/core/src/custom_prompts.rs +++ b/codex-rs/core/src/custom_prompts.rs @@ -3,10 +3,12 @@ use std::collections::HashSet; use std::path::Path; use std::path::PathBuf; -/// Return the default prompts directory: ~/.codex/prompts based on $HOME. -pub fn default_prompts_dir() -> PathBuf { - let home = std::env::var("HOME").unwrap_or_else(|_| ".".to_string()); - PathBuf::from(format!("{home}/.codex/prompts")) +/// Return the default prompts directory: `$CODEX_HOME/prompts`. +/// If `CODEX_HOME` cannot be resolved, returns `None`. +pub fn default_prompts_dir() -> Option { + crate::config::find_codex_home() + .ok() + .map(|home| home.join("prompts")) } /// Discover prompt files in the given directory, returning entries sorted by name.