Support separate API key for background agent work

Add agent_api_key config option. When set, all LLM calls (experience-mine,
fact-mine, consolidation, knowledge-loop, digest) use this key via
ANTHROPIC_API_KEY env var on the claude subprocess, keeping daemon token
usage on a separate quota from interactive sessions.

Config: {"config": {"agent_api_key": "sk-ant-..."}}

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Kent Overstreet 2026-03-05 22:28:39 -05:00
parent aa24c40a1c
commit 2f3ac1ecb6
2 changed files with 18 additions and 6 deletions

View file

@ -21,13 +21,18 @@ fn call_model(model: &str, prompt: &str) -> Result<String, String> {
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(())
})