diff --git a/src/config.rs b/src/config.rs index f397c42..c1d60f6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -49,6 +49,9 @@ pub struct Config { pub journal_max: usize, /// Ordered context groups for session-start loading. pub context_groups: Vec, + /// Separate API key for background agent work (daemon jobs). + /// If set, passed as ANTHROPIC_API_KEY to model calls. + pub agent_api_key: Option, } impl Default for Config { @@ -69,6 +72,7 @@ impl Default for Config { source: ContextSource::Store, }, ], + agent_api_key: None, } } } @@ -122,6 +126,9 @@ impl Config { if let Some(m) = cfg.get("journal_max").and_then(|v| v.as_u64()) { config.journal_max = m as usize; } + if let Some(s) = cfg.get("agent_api_key").and_then(|v| v.as_str()) { + config.agent_api_key = Some(s.to_string()); + } continue; } diff --git a/src/llm.rs b/src/llm.rs index 00fca5f..519aafa 100644 --- a/src/llm.rs +++ b/src/llm.rs @@ -21,13 +21,18 @@ fn call_model(model: &str, prompt: &str) -> Result { fs::write(&tmp, prompt) .map_err(|e| format!("write temp prompt: {}", e))?; + let mut cmd = Command::new("claude"); + cmd.args(["-p", "--model", model, "--tools", "", "--no-session-persistence"]) + .stdin(fs::File::open(&tmp).map_err(|e| format!("open temp: {}", e))?) + .env_remove("CLAUDECODE"); + + // Use separate API key for agent work if configured + if let Some(ref key) = crate::config::get().agent_api_key { + cmd.env("ANTHROPIC_API_KEY", key); + } + let result = unsafe { - Command::new("claude") - .args(["-p", "--model", model, "--tools", "", "--no-session-persistence"]) - .stdin(fs::File::open(&tmp).map_err(|e| format!("open temp: {}", e))?) - .env_remove("CLAUDECODE") - .pre_exec(|| { - // Kill this child if the parent dies + cmd.pre_exec(|| { libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGTERM); Ok(()) })