diff --git a/crates/graphicle/src/agent_setup.rs b/crates/graphicle/src/agent_setup.rs index 9d11ade..686488e 100644 --- a/crates/graphicle/src/agent_setup.rs +++ b/crates/graphicle/src/agent_setup.rs @@ -1483,6 +1483,7 @@ fn hook_file(client: &str, cwd: &Path) -> Result { "claude-code" => Ok(cwd.join(".claude/settings.local.json")), "codex" => { let home = std::env::var_os("CODEX_HOME") + .filter(|value| !value.is_empty()) .map(PathBuf::from) .or_else(|| crate::platform::home_dir().map(|h| h.join(".codex"))) .ok_or_else(|| Error::bad("Home directory unavailable"))?; diff --git a/crates/graphicle/src/capture.rs b/crates/graphicle/src/capture.rs index 4629f62..dc3000e 100644 --- a/crates/graphicle/src/capture.rs +++ b/crates/graphicle/src/capture.rs @@ -1404,9 +1404,11 @@ pub fn default_root(client: Client) -> Option { let home = crate::platform::home_dir(); match client { Client::ClaudeCode => std::env::var_os("CLAUDE_CONFIG_DIR") + .filter(|d| !d.is_empty()) .map(|d| std::path::PathBuf::from(d).join("projects")) .or_else(|| home.map(|h| h.join(".claude/projects"))), Client::Codex => std::env::var_os("CODEX_HOME") + .filter(|d| !d.is_empty()) .map(|d| std::path::PathBuf::from(d).join("sessions")) .or_else(|| home.map(|h| h.join(".codex/sessions"))), // Muse Code keeps its data under the XDG data folder on every diff --git a/crates/graphicle/tests/it/capture.rs b/crates/graphicle/tests/it/capture.rs index bf66e1f..550b2b1 100644 --- a/crates/graphicle/tests/it/capture.rs +++ b/crates/graphicle/tests/it/capture.rs @@ -1740,6 +1740,49 @@ fn sessions_cli_imports_only_transcripts_of_synced_projects() { assert!(f.stored("am_connector_docs").is_empty()); } +#[test] +fn sessions_cli_empty_client_home_uses_the_default_folder() { + let f = Fixture::new(); + let home = TempDir::new().unwrap(); + let current = TempDir::new().unwrap(); + let cwd = f.root.to_string_lossy(); + let cases = [ + ( + "claude-code", + "CLAUDE_CONFIG_DIR", + home.path().join(".claude/projects/project/x.jsonl"), + claude(&cwd, true), + 2, + ), + ( + "codex", + "CODEX_HOME", + home.path().join(".codex/sessions/2026/09/30/rollout.jsonl"), + codex(&cwd), + 1, + ), + ]; + for (client, variable, transcript, contents, turns) in cases { + std::fs::create_dir_all(transcript.parent().unwrap()).unwrap(); + std::fs::write(transcript, contents).unwrap(); + let mut command = binary(&f); + crate::child_env::home(&mut command, home.path()); + command + .args(["sessions", "import", "--client", client]) + .current_dir(current.path()) + .env(variable, ""); + let output = run_without_input(&mut command); + assert!( + output.status.success(), + "{}", + String::from_utf8_lossy(&output.stderr) + ); + let report: Value = serde_json::from_slice(&output.stdout).unwrap(); + assert_eq!(report["transcripts"], 1, "{report:#}"); + assert_eq!(report["turns_imported"], turns, "{report:#}"); + } +} + #[test] fn connect_merges_claude_code_hooks_and_stays_idempotent() { let f = Fixture::new(); diff --git a/crates/graphicle/tests/it/easy_review.rs b/crates/graphicle/tests/it/easy_review.rs index b5527d8..0067848 100644 --- a/crates/graphicle/tests/it/easy_review.rs +++ b/crates/graphicle/tests/it/easy_review.rs @@ -455,6 +455,24 @@ fn disconnect_all_leaves_other_data_folders_alone() { ); } +#[test] +fn setup_codex_empty_home_writes_hooks_under_the_default_home() { + let m = Machine::new(); + let repo = m.repo("code/app"); + assert!(repo.exists()); + let args = ["setup", "--yes", "--clients", "codex", "--no-instructions"]; + json_of( + &m.run_with(&repo, &m.data, &args, &[("CODEX_HOME", "")]), + &args, + ); + let hooks = m.home.join(".codex/hooks.json"); + assert!(hooks.exists()); + let stop = read_json(&hooks)["hooks"]["Stop"].clone(); + assert!(!stop.as_array().unwrap().is_empty(), "{stop:#}"); + assert!(stop.to_string().contains("graphicle"), "{stop:#}"); + assert!(!repo.join("hooks.json").exists()); +} + /// Entries and capture hooks run the program through the link on PATH, so a /// Homebrew upgrade that removes the old version leaves them working; hooks /// an older setup pinned to a version that is gone are repaired by `doctor