use crate::context::{Context, Environment};
use crate::host::{Administered, Hive, Os};
use crate::provider::claude::paths as claude;
use serde_json::Value;
use std::path::{Path, PathBuf};
pub(crate) const OVERRIDING_ENV: [&str; 10] = [
"ANTHROPIC_API_KEY",
"ANTHROPIC_AUTH_TOKEN",
"CLAUDE_CODE_OAUTH_TOKEN",
"CLAUDE_CODE_USE_BEDROCK",
"CLAUDE_CODE_USE_VERTEX",
"CLAUDE_CODE_USE_FOUNDRY",
"CLAUDE_CODE_USE_GATEWAY",
"CLAUDE_CODE_USE_ANTHROPIC_AWS",
"CLAUDE_CODE_USE_ANTHROPIC_GOOGLE_CLOUD",
"CLAUDE_CODE_USE_MANTLE",
];
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct Override {
pub(crate) layer: String,
pub(crate) key: String,
}
impl std::fmt::Display for Override {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{} in {}", self.key, self.layer)
}
}
pub(crate) fn managed_dir(os: Os) -> PathBuf {
match os {
Os::MacOs => "/Library/Application Support/ClaudeCode".into(),
Os::Linux => "/etc/claude-code".into(),
Os::Windows => r"C:\Program Files\ClaudeCode".into(),
}
}
const POLICIES: &str = r"SOFTWARE\Policies\ClaudeCode";
const POLICY: &str = "Settings";
const PREFERENCES: &str = "com.anthropic.claudecode.plist";
fn preferences(user: Option<String>) -> Vec<PathBuf> {
let root = Path::new("/Library/Managed Preferences");
user.map(|user| root.join(user).join(PREFERENCES))
.into_iter()
.chain([root.join(PREFERENCES)])
.collect()
}
fn plist_taken(ctx: &Context, paths: &[PathBuf]) -> Result<Option<Layer>, String> {
for path in paths {
match ctx.host().managed_plist(path) {
Administered::Set(text) => {
return Ok(
holds_policy(&text).then(|| administered(path.display().to_string(), &text))
);
}
Administered::Unreadable(why) => return Err(format!("{}: {why}", path.display())),
Administered::Unset => {}
}
}
Ok(None)
}
struct Layer {
name: String,
text: String,
}
fn managed_files(ctx: &Context) -> Vec<PathBuf> {
let dir = managed_dir(ctx.os);
let mut files = vec![dir.join("managed-settings.json")];
let mut drop_ins: Vec<PathBuf> = ctx
.host()
.administered_folder(&dir.join("managed-settings.d"))
.into_iter()
.filter(|p| p.extension().is_some_and(|e| e == "json"))
.collect();
drop_ins.sort();
files.extend(drop_ins);
files
}
fn managed(ctx: &Context) -> Vec<Layer> {
let host = ctx.host();
let mut there = false;
let mut layers: Vec<Layer> = managed_files(ctx)
.into_iter()
.filter_map(|path| match host.administered_file(&path) {
Administered::Set(text) => {
there |= holds_policy(&text);
Some(administered(path.display().to_string(), &text))
}
Administered::Unreadable(_) => {
there = true;
None
}
Administered::Unset => None,
})
.collect();
if ctx.os == Os::MacOs {
for path in preferences(crate::host::user::login_name()) {
if let Administered::Set(text) = host.managed_plist(&path) {
layers.push(administered(path.display().to_string(), &text));
}
}
}
if ctx.os == Os::Windows {
for hive in [Hive::Machine, Hive::User] {
if hive == Hive::User && there {
break;
}
match host.policy(hive, POLICIES, POLICY) {
Administered::Set(text) => {
there |= holds_policy(&text);
layers.push(administered(
format!(r"{}\{POLICIES}\{POLICY}", hive.name()),
&text,
));
}
Administered::Unreadable(_) => there |= hive != Hive::Machine,
Administered::Unset => {}
}
}
}
layers
}
fn managed_taken(ctx: &Context) -> Result<Vec<Layer>, String> {
let (mut taken, merged) = managed_tiers(ctx)?;
taken.extend(merged);
Ok(taken)
}
fn managed_pins(ctx: &Context) -> Result<Vec<Layer>, String> {
managed_tiers(ctx).map(|(taken, _)| taken)
}
fn managed_tiers(ctx: &Context) -> Result<(Vec<Layer>, Vec<Layer>), String> {
let host = ctx.host();
let mut folder = Vec::new();
let mut unread = None;
for path in managed_files(ctx) {
match host.administered_file(&path) {
Administered::Set(text) => {
folder.push(administered(path.display().to_string(), &text));
}
Administered::Unreadable(why) => {
unread.get_or_insert(format!("{}: {why}", path.display()));
}
Administered::Unset => {}
}
}
let folder = || unread.map_or(Ok(folder), Err);
let policy = |hive: Hive| {
let name = format!(r"{}\{POLICIES}\{POLICY}", hive.name());
match host.policy(hive, POLICIES, POLICY) {
Administered::Set(text) if holds_policy(&text) => Ok(Some(administered(name, &text))),
Administered::Set(_) | Administered::Unset => Ok(None),
Administered::Unreadable(why) => Err(format!("{name}: {why}")),
}
};
let first = match ctx.os {
Os::Windows => policy(Hive::Machine)?,
Os::MacOs => plist_taken(ctx, &preferences(crate::host::user::login_name()))?,
Os::Linux => None,
};
if let Some(first) = first {
let merges = serde_json::from_str::<Value>(&first.text)
.ok()
.and_then(|json| Some(json.get("managedSourcesBehavior")?.as_str()? == "merge"))
.unwrap_or(false);
let merged = if merges { folder()? } else { Vec::new() };
return Ok((vec![first], merged));
}
let folder = folder()?;
if ctx.os != Os::Windows || folder.iter().any(|layer| holds_policy(&layer.text)) {
return Ok((folder, Vec::new()));
}
Ok((policy(Hive::User)?.into_iter().collect(), Vec::new()))
}
fn holds_policy(text: &str) -> bool {
let text = claude::without_byte_order_mark(text);
match serde_json::from_str::<Value>(text) {
Ok(Value::Object(keys)) => keys.keys().any(|key| {
!matches!(
key.as_str(),
"managedSourcesBehavior" | "wslInheritsWindowsSettings"
)
}),
Ok(_) | Err(_) => !text.trim().is_empty(),
}
}
fn is_set(value: &str) -> bool {
!matches!(value.trim(), "" | "0" | "false")
}
fn own(path: &Path) -> Option<Layer> {
let bytes = std::fs::read(path).ok()?;
let text = match bytes.strip_prefix(&[0xFF, 0xFE]) {
Some(wide) => String::from_utf16(
&wide
.as_chunks::<2>()
.0
.iter()
.map(|pair| u16::from_le_bytes(*pair))
.collect::<Vec<_>>(),
)
.ok()?,
None => String::from_utf8(bytes).ok()?,
};
Some(Layer {
name: path.display().to_string(),
text: claude::without_byte_order_mark(&text).to_owned(),
})
}
fn config(ctx: &Context) -> Option<Layer> {
let path = claude::config_file(ctx);
let text = std::fs::read_to_string(&path).ok()?;
Some(Layer {
name: path.display().to_string(),
text: claude::without_byte_order_mark(&text).to_owned(),
})
}
fn administered(name: String, text: &str) -> Layer {
Layer {
name,
text: claude::without_byte_order_mark(text).to_owned(),
}
}
fn overrides_in(layer: &Layer) -> Vec<Override> {
let Ok(json) = serde_json::from_str::<Value>(&layer.text) else {
return Vec::new();
};
let layer = layer.name.clone();
let mut found = Vec::new();
if json
.get("apiKeyHelper")
.and_then(Value::as_str)
.is_some_and(|h| !h.trim().is_empty())
{
found.push(Override {
layer: layer.clone(),
key: "apiKeyHelper".into(),
});
}
if let Some(env) = json.get("env").and_then(Value::as_object) {
for name in OVERRIDING_ENV {
let set = match env.get(name) {
Some(Value::String(v)) => is_set(v),
Some(Value::Bool(b)) => *b,
Some(Value::Number(n)) => n.as_i64() != Some(0),
_ => false,
};
if set {
found.push(Override {
layer: layer.clone(),
key: format!("env.{name}"),
});
}
}
}
found
}
fn gateway_in(layer: &Layer) -> Vec<Override> {
let Ok(json) = serde_json::from_str::<Value>(&layer.text) else {
return Vec::new();
};
let required = [
json.get("forceLoginMethod").and_then(Value::as_str) == Some("gateway"),
names_a_gateway(&json),
];
["forceLoginMethod", "forceLoginGatewayUrl"]
.into_iter()
.zip(required)
.filter(|(_, set)| *set)
.map(|(key, _)| Override {
layer: layer.name.clone(),
key: key.into(),
})
.collect()
}
fn names_a_gateway(json: &Value) -> bool {
json.get("forceLoginGatewayUrl")
.and_then(Value::as_str)
.is_some_and(|url| !url.is_empty())
}
fn layered(ctx: &Context, settings: &Path) -> Vec<Override> {
managed(ctx)
.iter()
.flat_map(|layer| overrides_in(layer).into_iter().chain(gateway_in(layer)))
.chain(own(settings).iter().flat_map(overrides_in))
.collect()
}
const FEDERATION: &str = "oidc_federation";
const OAUTH: &str = "user_oauth";
const CONFIG_DIR: &str = "ANTHROPIC_CONFIG_DIR";
const NAMED: &str = "ANTHROPIC_PROFILE";
const PAIR: [&str; 2] = ["ANTHROPIC_FEDERATION_RULE_ID", "ANTHROPIC_ORGANIZATION_ID"];
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub(crate) struct Profiles {
started: Vec<(&'static str, String)>,
fallback: Option<PathBuf>,
}
impl Profiles {
pub(crate) fn read(env: &Environment) -> Profiles {
let set = |name| env.text(name).map(str::trim).filter(|v| !v.is_empty());
let under = |name, path: &[&str]| {
set(name).map(|dir| path.iter().fold(PathBuf::from(dir), |p, part| p.join(part)))
};
Profiles {
started: [CONFIG_DIR, NAMED, PAIR[0], PAIR[1]]
.into_iter()
.filter_map(|name| Some((name, env.text(name)?.to_owned())))
.collect(),
fallback: match env.os() {
Os::Windows => under("APPDATA", &["Anthropic"])
.or_else(|| under("USERPROFILE", &["AppData", "Roaming", "Anthropic"])),
Os::MacOs | Os::Linux => under("XDG_CONFIG_HOME", &["anthropic"])
.or_else(|| under("HOME", &[".config", "anthropic"])),
},
}
}
fn started(&self, name: &str) -> Option<&str> {
self.started
.iter()
.find_map(|(set, value)| (*set == name).then_some(value.as_str()))
}
}
fn taken(ctx: &Context, layers: &[Layer], name: &str) -> Option<(String, Override)> {
let set = layers.iter().find_map(|layer| {
let text = match setting(ctx.os, layer, name)? {
Value::String(text) => text,
Value::Number(number) => number.to_string(),
Value::Bool(flag) => flag.to_string(),
_ => return None,
};
Some((
text,
Override {
layer: layer.name.clone(),
key: format!("env.{name}"),
},
))
});
let (value, from) = set.or_else(|| {
let started = ctx.anthropic.started(name)?;
Some((
started.to_owned(),
Override {
layer: "the environment".into(),
key: name.into(),
},
))
})?;
let value = value.trim();
(!value.is_empty()).then(|| (value.to_owned(), from))
}
fn profile_file(folder: &Path, name: &str) -> PathBuf {
folder.join("configs").join(format!("{name}.json"))
}
fn mode(folder: &Path, name: &str) -> Option<String> {
let profile: Value =
serde_json::from_str(&std::fs::read_to_string(profile_file(folder, name)).ok()?).ok()?;
let authentication = profile.get("authentication")?;
let mode = authentication.get("type")?.as_str()?;
if mode == OAUTH {
let credentials = authentication
.get("credentials_path")
.and_then(Value::as_str)
.map_or_else(
|| folder.join("credentials").join(format!("{name}.json")),
PathBuf::from,
);
std::fs::metadata(credentials)
.ok()
.filter(|file| file.is_file() && file.len() > 0)?;
}
Some(mode.to_owned())
}
fn profile(ctx: &Context) -> Vec<Override> {
let layers: Vec<Layer> = managed_taken(ctx)
.unwrap_or_else(|_| managed(ctx))
.into_iter()
.chain(own(&claude::config_dir(ctx).join("settings.json")))
.chain(config(ctx))
.collect();
let folder = taken(ctx, &layers, CONFIG_DIR)
.map(|(dir, _)| PathBuf::from(dir))
.or_else(|| ctx.anthropic.fallback.clone());
if let Some((name, from)) = taken(ctx, &layers, NAMED) {
return folder
.and_then(|folder| mode(&folder, &name))
.filter(|mode| [FEDERATION, OAUTH].contains(&mode.as_str()))
.map(|_| from)
.into_iter()
.collect();
}
if let [Some((_, rule)), Some((_, organisation))] = PAIR.map(|name| taken(ctx, &layers, name)) {
return if rule.layer == organisation.layer {
vec![Override {
layer: rule.layer,
key: format!("{} and {}", rule.key, organisation.key),
}]
} else {
vec![rule, organisation]
};
}
let Some(folder) = folder else {
return Vec::new();
};
let active = std::fs::read_to_string(folder.join("active_config"))
.ok()
.map(|name| name.trim().to_owned())
.filter(|name| !name.is_empty())
.unwrap_or_else(|| "default".into());
(mode(&folder, &active).as_deref() == Some(FEDERATION))
.then(|| Override {
layer: profile_file(&folder, &active).display().to_string(),
key: format!("the `{FEDERATION}` profile `{active}`"),
})
.into_iter()
.collect()
}
pub(crate) fn organisation_pins(ctx: &Context) -> Vec<(String, Vec<String>)> {
managed_pins(ctx)
.unwrap_or_default()
.into_iter()
.filter_map(|layer| {
let json = serde_json::from_str::<Value>(&layer.text).ok()?;
let ids = match json.get("forceLoginOrgUUID")? {
Value::String(id) => vec![id.clone()],
Value::Array(ids) => ids
.iter()
.map(|id| id.as_str().map(str::to_owned))
.collect::<Option<Vec<_>>>()?,
_ => return None,
};
Some((layer.name, ids))
})
.collect()
}
fn login_method(layer: &Layer) -> Option<String> {
let json = serde_json::from_str::<Value>(&layer.text).ok()?;
let method = json.get("forceLoginMethod")?.as_str()?;
["claudeai", "console", "gateway"]
.contains(&method)
.then(|| method.to_owned())
}
pub(crate) fn console_pin(ctx: &Context) -> Option<String> {
let console = |layer: &Layer| login_method(layer).as_deref() == Some("console");
let Ok(taken) = managed_pins(ctx) else {
return managed(ctx)
.into_iter()
.find(console)
.map(|layer| layer.name);
};
if taken.iter().any(|layer| {
serde_json::from_str::<Value>(&layer.text).is_ok_and(|json| names_a_gateway(&json))
}) {
return None;
}
taken
.into_iter()
.rev()
.find(|layer| login_method(layer).is_some())
.filter(console)
.map(|layer| layer.name)
}
pub(crate) fn custom_oauth(ctx: &Context) -> bool {
if ctx.custom_oauth() {
return true;
}
managed(ctx)
.into_iter()
.chain(own(&claude::config_dir(ctx).join("settings.json")))
.any(|layer| {
serde_json::from_str::<Value>(&layer.text)
.ok()
.and_then(|json| {
json.get("env")?
.get("CLAUDE_CODE_CUSTOM_OAUTH_URL")?
.as_str()
.map(is_set)
})
.unwrap_or(false)
})
}
const OAUTH_TOKEN: (&str, &str) = (".oauth_token", "the OAuth token");
const API_KEY: (&str, &str) = (".api_key", "the API key");
const REMOTE_TOKEN_LIMIT: u64 = 65_536;
fn remote_tokens(ctx: &Context, files: &[(&str, &str)]) -> Vec<Override> {
let folders: Vec<String> = match ctx.os {
Os::Windows => ctx
.host()
.fixed_drives()
.into_iter()
.map(|drive| format!(r"{drive}:\home\claude\.claude\remote\"))
.collect(),
Os::MacOs | Os::Linux => vec!["/home/claude/.claude/remote/".into()],
};
folders
.iter()
.flat_map(|folder| {
files
.iter()
.map(move |(file, what)| (format!("{folder}{file}"), *what))
})
.filter(|(path, _)| {
matches!(
ctx.host()
.administered_file_up_to(Path::new(path), REMOTE_TOKEN_LIMIT),
Administered::Set(text) if !text.trim().is_empty()
)
})
.map(|(layer, what)| Override {
layer,
key: what.into(),
})
.collect()
}
pub(crate) fn overrides(ctx: &Context) -> Vec<Override> {
let mut found = layered(ctx, &claude::config_dir(ctx).join("settings.json"));
found.extend(profile(ctx));
found.extend(remote_tokens(ctx, &[OAUTH_TOKEN, API_KEY]));
found.extend(ctx.overriding_auth().iter().map(|key| Override {
layer: "the environment".into(),
key: key.clone(),
}));
found
}
pub(crate) struct EnvSetting {
pub(crate) layer: String,
pub(crate) value: Value,
pub(crate) managed: bool,
}
fn setting(os: Os, layer: &Layer, name: &str) -> Option<Value> {
let json = serde_json::from_str::<Value>(&layer.text).ok()?;
json.get("env")?
.as_object()?
.iter()
.find(|(key, _)| *key == name || os == Os::Windows && key.eq_ignore_ascii_case(name))
.map(|(_, value)| value.clone())
}
pub(crate) fn env_settings(ctx: &Context, name: &str) -> Result<Vec<EnvSetting>, String> {
let managed = managed_taken(ctx)?.into_iter().map(|layer| (layer, true));
let own = own(&claude::config_dir(ctx).join("settings.json")).map(|layer| (layer, false));
Ok(managed
.chain(own)
.filter_map(|(layer, managed)| {
Some(EnvSetting {
value: setting(ctx.os, &layer, name)?,
layer: layer.name,
managed,
})
})
.collect())
}
pub(crate) fn status_line_command(ctx: &Context) -> Option<String> {
managed(ctx)
.into_iter()
.chain(own(&claude::config_dir(ctx).join("settings.json")))
.find_map(|layer| {
serde_json::from_str::<Value>(&layer.text)
.ok()?
.get("statusLine")?
.get("command")?
.as_str()
.map(str::to_owned)
})
}
pub(crate) fn overrides_of_a_run_in(ctx: &Context, config: &Path) -> Vec<Override> {
let mut found = layered(ctx, &config.join("settings.json"));
found.extend(remote_tokens(ctx, &[API_KEY]));
found
}
#[cfg(test)]
#[allow(
clippy::disallowed_methods,
reason = "a test sets up its scratch files as a person or a tool would"
)]
pub(crate) mod tests_support {
use super::*;
pub(crate) fn home() -> (Context, PathBuf, tempfile::TempDir) {
let scratch = tempfile::tempdir().expect("a scratch home");
let config = scratch.path().join(".claude");
std::fs::create_dir_all(&config).expect("a config dir");
let ctx = Context::new(scratch.path().to_path_buf())
.with_claude_config_dir(config.to_string_lossy().into_owned());
(ctx, config, scratch)
}
pub(crate) fn write(path: &Path, value: Value) {
std::fs::write(path, value.to_string()).expect("written");
}
}
#[cfg(test)]
#[allow(
clippy::disallowed_methods,
reason = "a test sets up its scratch files as a person or a tool would"
)]
mod tests {
use super::tests_support::*;
use super::*;
use serde_json::json;
#[test]
fn the_status_line_command_is_read_from_the_persons_settings() {
let (ctx, config, _scratch) = home();
assert_eq!(status_line_command(&ctx), None);
write(
&config.join("settings.json"),
json!({"statusLine": {"type": "command", "command": "pitboard statusline"}}),
);
assert_eq!(
status_line_command(&ctx).as_deref(),
Some("pitboard statusline")
);
write(&config.join("settings.json"), json!({"statusLine": {}}));
assert_eq!(status_line_command(&ctx), None);
}
#[test]
fn a_settings_file_that_starts_with_a_byte_order_mark_is_read() {
let (ctx, config, _s) = home();
let mut bytes = vec![0xEF, 0xBB, 0xBF];
bytes.extend(
json!({
"env": {"ANTHROPIC_API_KEY": "sk-ant-something"},
"statusLine": {"type": "command", "command": "pitboard statusline"},
})
.to_string()
.into_bytes(),
);
std::fs::write(config.join("settings.json"), bytes).expect("written");
assert_eq!(overrides(&ctx).len(), 1);
assert_eq!(
status_line_command(&ctx).as_deref(),
Some("pitboard statusline")
);
}
#[test]
fn an_ordinary_machine_has_nothing_in_the_way() {
let (ctx, config, _s) = home();
write(&config.join("settings.json"), json!({"theme": "dark"}));
assert_eq!(overrides(&ctx), Vec::new());
}
#[test]
fn a_settings_file_that_sets_a_key_is_found_where_the_environment_would_not_be() {
let (ctx, config, _s) = home();
write(
&config.join("settings.json"),
json!({"env": {"ANTHROPIC_API_KEY": "sk-ant-something"}}),
);
let found = overrides(&ctx);
assert_eq!(found.len(), 1, "{found:?}");
assert_eq!(found[0].key, "env.ANTHROPIC_API_KEY");
assert!(found[0].layer.ends_with("settings.json"));
}
#[test]
fn a_helper_that_prints_a_key_is_an_override_whatever_it_prints() {
let (ctx, config, _s) = home();
write(
&config.join("settings.json"),
json!({"apiKeyHelper": "/usr/local/bin/get-key"}),
);
assert_eq!(overrides(&ctx)[0].key, "apiKeyHelper");
}
#[test]
fn a_third_party_provider_is_an_override_too() {
let (ctx, config, _s) = home();
for name in ["CLAUDE_CODE_USE_BEDROCK", "CLAUDE_CODE_USE_MANTLE"] {
write(&config.join("settings.json"), json!({"env": {name: "1"}}));
assert_eq!(overrides(&ctx)[0].key, format!("env.{name}"));
}
}
#[test]
fn a_key_that_is_present_but_empty_sets_nothing() {
let (ctx, config, _s) = home();
write(
&config.join("settings.json"),
json!({
"apiKeyHelper": " ",
"env": {
"ANTHROPIC_API_KEY": "",
"CLAUDE_CODE_USE_BEDROCK": "0",
"CLAUDE_CODE_USE_VERTEX": "false",
},
}),
);
assert_eq!(overrides(&ctx), Vec::new());
}
#[test]
fn a_settings_file_that_is_not_json_is_not_a_reason_to_refuse_anything() {
let (ctx, config, _s) = home();
std::fs::write(config.join("settings.json"), "{ not json").expect("written");
assert_eq!(overrides(&ctx), Vec::new());
}
}
#[cfg(test)]
mod custom_oauth_tests {
use super::tests_support::*;
use super::*;
use serde_json::json;
#[test]
fn a_custom_endpoint_in_a_settings_file_is_found_the_way_the_environment_one_is() {
let (ctx, config, _s) = home();
assert!(!custom_oauth(&ctx));
write(
&config.join("settings.json"),
json!({"env": {"CLAUDE_CODE_CUSTOM_OAUTH_URL": "https://oauth.example"}}),
);
assert!(custom_oauth(&ctx));
}
}
#[cfg(test)]
mod managed_tests {
use super::*;
use crate::context::Environment;
use crate::host::memory::MemoryHost;
use serde_json::json;
use std::sync::Arc;
fn on(os: Os, memory: &Arc<MemoryHost>) -> (Context, tempfile::TempDir) {
let scratch = tempfile::tempdir().expect("a scratch home");
let home = scratch.path().to_string_lossy().into_owned();
let config = scratch
.path()
.join(".claude")
.to_string_lossy()
.into_owned();
let env = Environment::on(
os,
[
("HOME", home.as_str()),
("USERPROFILE", home.as_str()),
("CLAUDE_CONFIG_DIR", config.as_str()),
],
);
let ctx = Context::for_command_line(&env).with_memory_stores(Arc::clone(memory));
(ctx, scratch)
}
fn said(found: &[Override]) -> Vec<(String, String)> {
found
.iter()
.map(|o| (o.layer.clone(), o.key.clone()))
.collect()
}
#[test]
fn managed_settings_are_read_where_claude_code_keeps_them_on_each_system() {
for (os, dir) in [
(Os::MacOs, "/Library/Application Support/ClaudeCode"),
(Os::Linux, "/etc/claude-code"),
(Os::Windows, r"C:\Program Files\ClaudeCode"),
] {
let memory = MemoryHost::new();
let dir = PathBuf::from(dir);
let (file, drop_ins) = (
dir.join("managed-settings.json"),
dir.join("managed-settings.d"),
);
memory.administers(
&file,
&json!({"env": {"ANTHROPIC_API_KEY": "sk-ant-x"}}).to_string(),
);
memory.administers(
drop_ins.join("20-helper.json"),
&json!({"apiKeyHelper": "/opt/key"}).to_string(),
);
memory.administers(
drop_ins.join("10-oauth.json"),
&json!({"env": {"CLAUDE_CODE_CUSTOM_OAUTH_URL": "https://oauth.example"}})
.to_string(),
);
memory.administers(
drop_ins.join("30-notes.txt"),
&json!({"apiKeyHelper": "/opt/other"}).to_string(),
);
let (ctx, scratch) = on(os, &memory);
let expected = [
(
file.display().to_string(),
"env.ANTHROPIC_API_KEY".to_string(),
),
(
drop_ins.join("20-helper.json").display().to_string(),
"apiKeyHelper".to_string(),
),
];
assert_eq!(said(&overrides(&ctx)), expected, "{os:?}");
assert!(custom_oauth(&ctx), "{os:?}");
let run = scratch.path().join("warm").join("config");
assert_eq!(said(&overrides_of_a_run_in(&ctx, &run)), expected, "{os:?}");
}
}
#[test]
fn windows_policies_are_read_as_claude_code_reads_them() {
let memory = MemoryHost::new();
let user = format!(r"HKCU\{POLICIES}\{POLICY}");
let machine = format!(r"HKLM\{POLICIES}\{POLICY}");
memory.sets_policy(
Hive::User,
POLICIES,
POLICY,
&json!({"env": {"CLAUDE_CODE_USE_BEDROCK": "1"}}).to_string(),
);
let (ctx, _scratch) = on(Os::Windows, &memory);
assert_eq!(
said(&overrides(&ctx)),
[(user.clone(), "env.CLAUDE_CODE_USE_BEDROCK".to_string())]
);
memory.sets_policy(
Hive::Machine,
POLICIES,
POLICY,
&json!({"managedSourcesBehavior": "merge"}).to_string(),
);
assert_eq!(
said(&overrides(&ctx)),
[(user, "env.CLAUDE_CODE_USE_BEDROCK".to_string())],
"one that says only how the sources compose keeps nothing out"
);
memory.sets_policy(
Hive::Machine,
POLICIES,
POLICY,
&json!({"apiKeyHelper": "C:\\key.cmd"}).to_string(),
);
assert_eq!(
said(&overrides(&ctx)),
[(machine, "apiKeyHelper".to_string())]
);
let (mac, _scratch) = on(Os::MacOs, &memory);
assert_eq!(overrides(&mac), Vec::new(), "macOS has no registry");
}
#[test]
fn an_unreadable_machine_policy_still_lets_hkcu_be_read() {
let memory = MemoryHost::new();
let user = format!(r"HKCU\{POLICIES}\{POLICY}");
memory.policy_unreadable(Hive::Machine, POLICIES, POLICY, "access denied");
memory.sets_policy(
Hive::User,
POLICIES,
POLICY,
&json!({"apiKeyHelper": "C:\\key.cmd"}).to_string(),
);
let (ctx, _scratch) = on(Os::Windows, &memory);
assert_eq!(said(&overrides(&ctx)), [(user, "apiKeyHelper".to_string())]);
}
#[test]
fn a_token_in_claude_codes_remote_files_comes_before_the_stored_login() {
for os in [Os::MacOs, Os::Linux] {
let memory = MemoryHost::new();
memory.administers("/home/claude/.claude/remote/.oauth_token", "a token\n");
memory.administers("/home/claude/.claude/remote/.api_key", " \n");
let (ctx, _scratch) = on(os, &memory);
assert_eq!(
said(&overrides(&ctx)),
[(
"/home/claude/.claude/remote/.oauth_token".to_string(),
"the OAuth token".to_string()
)],
"{os:?}"
);
assert_eq!(
overrides(&ctx)[0].to_string(),
"the OAuth token in /home/claude/.claude/remote/.oauth_token"
);
}
}
#[test]
fn a_remote_token_file_over_claude_codes_limit_holds_no_token() {
let key = "/home/claude/.claude/remote/.api_key";
let memory = MemoryHost::new();
memory.administers(key, &"k".repeat(65_536));
let (ctx, _scratch) = on(Os::Linux, &memory);
assert_eq!(
said(&overrides(&ctx)),
[(key.to_string(), "the API key".to_string())]
);
memory.administers(key, &"k".repeat(65_537));
assert_eq!(overrides(&ctx), Vec::new());
}
#[test]
fn a_warm_ups_run_takes_the_api_key_in_claude_codes_remote_file() {
for (os, folder) in [
(Os::MacOs, "/home/claude/.claude/remote/"),
(Os::Linux, "/home/claude/.claude/remote/"),
(Os::Windows, r"C:\home\claude\.claude\remote\"),
] {
let memory = MemoryHost::new();
memory.administers(format!("{folder}.oauth_token"), "a token");
let (ctx, scratch) = on(os, &memory);
let run = scratch.path().join("warm").join("config");
assert_eq!(overrides_of_a_run_in(&ctx, &run), Vec::new(), "{os:?}");
memory.administers(format!("{folder}.api_key"), "sk-ant-x");
assert_eq!(
said(&overrides_of_a_run_in(&ctx, &run)),
[(format!("{folder}.api_key"), "the API key".to_string())],
"{os:?}"
);
}
}
#[test]
fn on_windows_a_remote_token_file_is_at_a_drives_root() {
let memory = MemoryHost::new();
memory.administers(r"C:\home\claude\.claude\remote\.api_key", "sk-ant-x");
memory.administers("/home/claude/.claude/remote/.oauth_token", "a token");
let (ctx, _scratch) = on(Os::Windows, &memory);
assert_eq!(
said(&overrides(&ctx)),
[(
r"C:\home\claude\.claude\remote\.api_key".to_string(),
"the API key".to_string()
)]
);
memory.has_fixed_drives(&['C', 'D']);
memory.administers(r"D:\home\claude\.claude\remote\.oauth_token", "a token");
assert_eq!(
said(&overrides(&ctx)),
[
(
r"C:\home\claude\.claude\remote\.api_key".to_string(),
"the API key".to_string()
),
(
r"D:\home\claude\.claude\remote\.oauth_token".to_string(),
"the OAuth token".to_string()
),
]
);
}
#[test]
#[allow(
clippy::disallowed_methods,
reason = "a test sets up its scratch files as a person or a tool would"
)]
fn managed_settings_that_require_the_gateway_sign_in_override_the_login() {
for (os, dir) in [
(Os::MacOs, "/Library/Application Support/ClaudeCode"),
(Os::Linux, "/etc/claude-code"),
(Os::Windows, r"C:\Program Files\ClaudeCode"),
] {
let file = PathBuf::from(dir).join("managed-settings.json");
let memory = MemoryHost::new();
let (ctx, scratch) = on(os, &memory);
let own = scratch.path().join(".claude").join("settings.json");
std::fs::create_dir_all(own.parent().expect("its folder")).expect("a config dir");
std::fs::write(
&own,
json!({"forceLoginMethod": "gateway", "forceLoginGatewayUrl": "https://gw.example"})
.to_string(),
)
.expect("written");
memory.administers(&file, &json!({"forceLoginMethod": "claudeai"}).to_string());
assert_eq!(overrides(&ctx), Vec::new(), "{os:?}");
let run = scratch.path().join("warm").join("config");
for (set, key) in [
(json!({"forceLoginMethod": "gateway"}), "forceLoginMethod"),
(
json!({"forceLoginGatewayUrl": "https://gw.example"}),
"forceLoginGatewayUrl",
),
] {
memory.administers(&file, &set.to_string());
let expected = [(file.display().to_string(), key.to_string())];
assert_eq!(said(&overrides(&ctx)), expected, "{os:?}");
assert_eq!(said(&overrides_of_a_run_in(&ctx, &run)), expected, "{os:?}");
}
}
}
#[test]
#[allow(
clippy::disallowed_methods,
reason = "a test sets up its scratch files as a person or a tool would"
)]
fn a_managed_organisation_pin_is_read_as_one_or_a_list() {
let memory = MemoryHost::new();
let (ctx, scratch) = on(Os::Linux, &memory);
let own = scratch.path().join(".claude").join("settings.json");
std::fs::create_dir_all(own.parent().expect("its folder")).expect("a config dir");
std::fs::write(&own, json!({"forceLoginOrgUUID": "org-own"}).to_string()).expect("written");
assert_eq!(organisation_pins(&ctx), Vec::new());
let dir = PathBuf::from("/etc/claude-code");
let (file, drop_in) = (
dir.join("managed-settings.json"),
dir.join("managed-settings.d").join("10-org.json"),
);
memory.administers(&file, &json!({"forceLoginOrgUUID": "org-a"}).to_string());
memory.administers(
&drop_in,
&json!({"forceLoginOrgUUID": ["org-b", "org-c"]}).to_string(),
);
assert_eq!(
organisation_pins(&ctx),
[
(file.display().to_string(), vec!["org-a".to_string()]),
(
drop_in.display().to_string(),
vec!["org-b".to_string(), "org-c".to_string()]
),
]
);
}
#[test]
fn a_managed_console_pin_is_read_from_the_sources_a_session_takes() {
let memory = MemoryHost::new();
let (ctx, _scratch) = on(Os::MacOs, &memory);
let dir = PathBuf::from("/Library/Application Support/ClaudeCode");
let (file, drop_in) = (
dir.join("managed-settings.json"),
dir.join("managed-settings.d").join("10-login.json"),
);
assert_eq!(console_pin(&ctx), None);
for method in ["claudeai", "gateway"] {
memory.administers(&drop_in, &json!({"forceLoginMethod": method}).to_string());
assert_eq!(console_pin(&ctx), None, "{method}");
}
memory.administers(
&drop_in,
&json!({"forceLoginMethod": "console"}).to_string(),
);
assert_eq!(console_pin(&ctx), Some(drop_in.display().to_string()));
memory.administers(&file, &json!({"forceLoginMethod": "gateway"}).to_string());
assert_eq!(console_pin(&ctx), Some(drop_in.display().to_string()));
memory.administers(
&file,
&json!({"forceLoginGatewayUrl": "https://gw.example"}).to_string(),
);
assert_eq!(console_pin(&ctx), None, "a gateway named is taken first");
memory.administers(&file, &json!({"forceLoginMethod": "console"}).to_string());
memory.administers(
&drop_in,
&json!({"forceLoginMethod": "claudeai"}).to_string(),
);
assert_eq!(
console_pin(&ctx),
None,
"a later file overrides an earlier one"
);
memory.administers(&drop_in, &json!({"forceLoginMethod": "x"}).to_string());
assert_eq!(
console_pin(&ctx),
Some(file.display().to_string()),
"a method Claude Code does not know is dropped"
);
let plist =
PathBuf::from("/Library/Managed Preferences").join("com.anthropic.claudecode.plist");
memory.administers(&plist, &json!({"forceLoginMethod": "claudeai"}).to_string());
assert_eq!(
console_pin(&ctx),
None,
"the plist is taken over the folder"
);
memory.administers(
&plist,
&json!({"managedSourcesBehavior": "merge", "model": "x"}).to_string(),
);
assert_eq!(
console_pin(&ctx),
None,
"merged in, the folder keeps no login pin"
);
}
#[test]
fn where_a_managed_source_is_unreadable_any_readable_console_pin_is_taken() {
let memory = MemoryHost::new();
let (ctx, _scratch) = on(Os::MacOs, &memory);
let dir = PathBuf::from("/Library/Application Support/ClaudeCode");
let file = dir.join("managed-settings.json");
memory.administers_unreadably(
dir.join("managed-settings.d").join("10-login.json"),
"permission denied",
);
memory.administers(&file, &json!({"forceLoginMethod": "console"}).to_string());
assert_eq!(console_pin(&ctx), Some(file.display().to_string()));
}
#[test]
fn macos_managed_preferences_are_taken_over_the_folder_unless_they_merge() {
let memory = MemoryHost::new();
let plist =
PathBuf::from("/Library/Managed Preferences").join("com.anthropic.claudecode.plist");
let file =
PathBuf::from("/Library/Application Support/ClaudeCode").join("managed-settings.json");
let pins = |ctx: &Context| -> Vec<String> {
organisation_pins(ctx)
.into_iter()
.map(|(layer, _)| layer)
.collect()
};
memory.administers(&file, &json!({"forceLoginOrgUUID": "org-file"}).to_string());
memory.administers(
&plist,
&json!({"forceLoginOrgUUID": "org-mdm", "apiKeyHelper": "/opt/key"}).to_string(),
);
let (mac, _scratch) = on(Os::MacOs, &memory);
assert_eq!(pins(&mac), [plist.display().to_string()]);
assert_eq!(
said(&overrides(&mac)),
[(plist.display().to_string(), "apiKeyHelper".to_string())]
);
let (linux, _scratch) = on(Os::Linux, &memory);
assert_eq!(overrides(&linux), Vec::new(), "only macOS has them");
memory.administers(
&plist,
&json!({"forceLoginOrgUUID": "org-mdm", "managedSourcesBehavior": "merge"}).to_string(),
);
assert_eq!(
pins(&mac),
[plist.display().to_string()],
"merged in, the folder keeps no login pin (managed_login_pins)"
);
memory.administers(
&plist,
&json!({"managedSourcesBehavior": "merge"}).to_string(),
);
assert_eq!(
pins(&mac),
[file.display().to_string()],
"no policy is not taken"
);
}
#[test]
fn the_persons_managed_preferences_come_before_the_devices() {
let memory = MemoryHost::new();
let paths = preferences(Some("dana".into()));
let [person, device] = [&paths[0], &paths[1]];
assert_eq!(
person,
Path::new("/Library/Managed Preferences/dana/com.anthropic.claudecode.plist")
);
let (ctx, _scratch) = on(Os::MacOs, &memory);
let taken = |ctx: &Context| plist_taken(ctx, &paths).map(|plist| plist.map(|l| l.name));
memory.administers(device, &json!({"forceLoginOrgUUID": "org-d"}).to_string());
assert_eq!(taken(&ctx), Ok(Some(device.display().to_string())));
memory.administers(person, &json!({"forceLoginOrgUUID": "org-p"}).to_string());
assert_eq!(taken(&ctx), Ok(Some(person.display().to_string())));
memory.administers(person, "{}");
assert_eq!(taken(&ctx), Ok(None), "the first read is the one");
memory.administers_unreadably(person, "holds a date");
assert!(taken(&ctx).is_err());
}
#[test]
fn a_managed_file_keeps_the_persons_policy_out() {
let memory = MemoryHost::new();
memory.sets_policy(
Hive::User,
POLICIES,
POLICY,
&json!({"apiKeyHelper": "C:\\key.cmd"}).to_string(),
);
memory.administers(
PathBuf::from(r"C:\Program Files\ClaudeCode").join("managed-settings.json"),
&json!({"permissions": {"deny": ["WebFetch"]}}).to_string(),
);
let (ctx, _scratch) = on(Os::Windows, &memory);
assert_eq!(overrides(&ctx), Vec::new());
}
}
#[cfg(test)]
#[allow(
clippy::disallowed_methods,
reason = "a test sets up its scratch files as a person or a tool would"
)]
mod profile_tests {
use super::*;
use crate::context::Environment;
use serde_json::json;
fn on(os: Os, scratch: &Path, set: &[(&str, &str)]) -> Context {
let home = scratch.to_string_lossy().into_owned();
let config = scratch.join(".claude").to_string_lossy().into_owned();
let mut pairs = vec![
("HOME", home.as_str()),
("USERPROFILE", home.as_str()),
("CLAUDE_CONFIG_DIR", config.as_str()),
];
pairs.extend_from_slice(set);
Context::for_command_line(&Environment::on(os, pairs))
}
fn profile(folder: &Path, name: &str, mode: &str) -> PathBuf {
let path = folder.join("configs").join(format!("{name}.json"));
std::fs::create_dir_all(path.parent().expect("its folder")).expect("a folder");
std::fs::write(&path, json!({"authentication": {"type": mode}}).to_string())
.expect("written");
path
}
fn signed_in(folder: &Path, name: &str) {
let path = folder.join("credentials").join(format!("{name}.json"));
std::fs::create_dir_all(path.parent().expect("its folder")).expect("a folder");
std::fs::write(path, json!({"refresh_token": "not-a-token"}).to_string()).expect("written");
}
fn said(ctx: &Context) -> Vec<String> {
overrides(ctx).iter().map(ToString::to_string).collect()
}
#[test]
fn the_active_profile_overrides_the_login_where_it_federates() {
let scratch = tempfile::tempdir().expect("a scratch home");
let folder = scratch.path().join(".config").join("anthropic");
let ctx = on(Os::Linux, scratch.path(), &[]);
assert_eq!(said(&ctx), Vec::<String>::new());
let default = profile(&folder, "default", "oidc_federation");
assert_eq!(
said(&ctx),
[format!(
"the `oidc_federation` profile `default` in {}",
default.display()
)]
);
std::fs::write(folder.join("active_config"), "work\n").expect("written");
profile(&folder, "work", "user_oauth");
signed_in(&folder, "work");
assert_eq!(said(&ctx), Vec::<String>::new());
}
#[test]
fn a_named_profile_overrides_the_login_where_it_is_there() {
let scratch = tempfile::tempdir().expect("a scratch home");
let folder = scratch.path().join(".config").join("anthropic");
let named = [
("ANTHROPIC_PROFILE", " work "),
("ANTHROPIC_FEDERATION_RULE_ID", "rule"),
("ANTHROPIC_ORGANIZATION_ID", "org"),
];
let ctx = on(Os::MacOs, scratch.path(), &named);
profile(&folder, "default", "oidc_federation");
profile(&folder, "work", "user_oauth");
assert_eq!(said(&ctx), Vec::<String>::new());
signed_in(&folder, "work");
assert_eq!(said(&ctx), ["ANTHROPIC_PROFILE in the environment"]);
}
#[test]
fn a_profiles_credentials_file_is_never_read() {
let scratch = tempfile::tempdir().expect("a scratch home");
let folder = scratch.path().join(".config").join("anthropic");
let ctx = on(Os::Linux, scratch.path(), &[("ANTHROPIC_PROFILE", "work")]);
profile(&folder, "work", "user_oauth");
signed_in(&folder, "work");
let credentials = folder.join("credentials").join("work.json");
std::fs::write(&credentials, b"\xff\xfe not text").expect("written");
assert_eq!(said(&ctx), ["ANTHROPIC_PROFILE in the environment"]);
std::fs::write(&credentials, "").expect("emptied");
assert_eq!(said(&ctx), Vec::<String>::new());
}
#[test]
fn a_federation_the_environment_sets_overrides_the_login() {
let scratch = tempfile::tempdir().expect("a scratch home");
let pair = [
("ANTHROPIC_FEDERATION_RULE_ID", "rule"),
("ANTHROPIC_ORGANIZATION_ID", "org"),
];
assert_eq!(
said(&on(Os::Linux, scratch.path(), &pair)),
["ANTHROPIC_FEDERATION_RULE_ID and ANTHROPIC_ORGANIZATION_ID in the environment"]
);
assert_eq!(
said(&on(Os::Linux, scratch.path(), &pair[..1])),
Vec::<String>::new()
);
assert_eq!(
said(&on(
Os::Linux,
scratch.path(),
&[pair[0], ("ANTHROPIC_ORGANIZATION_ID", " ")]
)),
Vec::<String>::new()
);
}
fn own_settings(scratch: &Path, env: Value) -> PathBuf {
let path = scratch.join(".claude").join("settings.json");
std::fs::create_dir_all(path.parent().expect("its folder")).expect("a folder");
std::fs::write(&path, json!({ "env": env }).to_string()).expect("written");
path
}
#[test]
fn a_profile_a_settings_file_names_is_taken_over_the_environments() {
let scratch = tempfile::tempdir().expect("a scratch home");
let folder = scratch.path().join(".config").join("anthropic");
let ctx = on(Os::Linux, scratch.path(), &[("ANTHROPIC_PROFILE", "home")]);
profile(&folder, "home", "user_oauth");
profile(&folder, "work", "oidc_federation");
let settings = own_settings(scratch.path(), json!({"ANTHROPIC_PROFILE": " work "}));
assert_eq!(
said(&ctx),
[format!("env.ANTHROPIC_PROFILE in {}", settings.display())]
);
own_settings(scratch.path(), json!({"anthropic_profile": "work"}));
assert_eq!(
said(&ctx),
Vec::<String>::new(),
"another variable off Windows"
);
own_settings(scratch.path(), json!({"ANTHROPIC_PROFILE": ""}));
let default = profile(&folder, "default", "oidc_federation");
assert_eq!(
said(&ctx),
[format!(
"the `oidc_federation` profile `default` in {}",
default.display()
)],
"an empty one unsets the environment's"
);
}
#[test]
fn a_federation_a_settings_file_sets_overrides_the_login() {
let scratch = tempfile::tempdir().expect("a scratch home");
let both = json!({"ANTHROPIC_FEDERATION_RULE_ID": "rule", "ANTHROPIC_ORGANIZATION_ID": 7});
let settings = own_settings(scratch.path(), both);
let ctx = on(Os::MacOs, scratch.path(), &[]);
assert_eq!(
said(&ctx),
[format!(
"env.ANTHROPIC_FEDERATION_RULE_ID and env.ANTHROPIC_ORGANIZATION_ID in {}",
settings.display()
)]
);
own_settings(scratch.path(), json!({"ANTHROPIC_ORGANIZATION_ID": "org"}));
let ctx = on(
Os::MacOs,
scratch.path(),
&[("ANTHROPIC_FEDERATION_RULE_ID", "rule")],
);
assert_eq!(
said(&ctx),
[
"ANTHROPIC_FEDERATION_RULE_ID in the environment".to_string(),
format!("env.ANTHROPIC_ORGANIZATION_ID in {}", settings.display()),
]
);
}
#[test]
fn a_profile_the_config_file_names_is_taken_below_the_settings() {
let scratch = tempfile::tempdir().expect("a scratch home");
let folder = scratch.path().join(".config").join("anthropic");
profile(&folder, "home", "user_oauth");
profile(&folder, "work", "oidc_federation");
let ctx = on(Os::Linux, scratch.path(), &[("ANTHROPIC_PROFILE", "home")]);
let config = crate::provider::claude::paths::config_file(&ctx);
std::fs::create_dir_all(config.parent().expect("its folder")).expect("a folder");
let env = json!({"env": {"ANTHROPIC_PROFILE": "work"}});
std::fs::write(&config, format!("\u{feff}{env}")).expect("written");
assert_eq!(
said(&ctx),
[format!("env.ANTHROPIC_PROFILE in {}", config.display())]
);
own_settings(scratch.path(), json!({"ANTHROPIC_PROFILE": "home"}));
assert_eq!(said(&ctx), Vec::<String>::new());
}
#[test]
fn a_profile_the_persons_settings_name_is_taken_beside_an_unreadable_managed_source() {
let memory = crate::host::memory::MemoryHost::new();
memory.administers_unreadably("/etc/claude-code/managed-settings.json", "denied");
let scratch = tempfile::tempdir().expect("a scratch home");
let ctx = on(Os::Linux, scratch.path(), &[]).with_memory_stores(memory);
profile(
&scratch.path().join(".config").join("anthropic"),
"work",
"oidc_federation",
);
let settings = own_settings(scratch.path(), json!({"ANTHROPIC_PROFILE": "work"}));
assert_eq!(
said(&ctx),
[format!("env.ANTHROPIC_PROFILE in {}", settings.display())]
);
}
#[test]
fn the_profile_folder_a_settings_file_names_is_looked_in() {
let scratch = tempfile::tempdir().expect("a scratch home");
let elsewhere = scratch.path().join("elsewhere");
own_settings(
scratch.path(),
json!({"ANTHROPIC_CONFIG_DIR": elsewhere.to_string_lossy()}),
);
let path = profile(&elsewhere, "default", "oidc_federation");
assert_eq!(
said(&on(Os::Linux, scratch.path(), &[])),
[format!(
"the `oidc_federation` profile `default` in {}",
path.display()
)]
);
}
#[test]
fn profiles_are_where_claude_code_looks_for_them_on_each_system() {
let scratch = tempfile::tempdir().expect("a scratch home");
let elsewhere = scratch.path().join("elsewhere");
let named = elsewhere.to_string_lossy().into_owned();
let roaming = scratch.path().join("Roaming");
let app_data = roaming.to_string_lossy().into_owned();
for (ctx, folder) in [
(
on(Os::Linux, scratch.path(), &[("XDG_CONFIG_HOME", &named)]),
elsewhere.join("anthropic"),
),
(
on(
Os::MacOs,
scratch.path(),
&[
("ANTHROPIC_CONFIG_DIR", &named),
("XDG_CONFIG_HOME", "/xdg"),
],
),
elsewhere.clone(),
),
(
on(Os::Windows, scratch.path(), &[("APPDATA", &app_data)]),
roaming.join("Anthropic"),
),
(
on(Os::Windows, scratch.path(), &[]),
scratch
.path()
.join("AppData")
.join("Roaming")
.join("Anthropic"),
),
] {
let path = profile(&folder, "default", "oidc_federation");
assert_eq!(
said(&ctx),
[format!(
"the `oidc_federation` profile `default` in {}",
path.display()
)],
"{folder:?}"
);
std::fs::remove_file(path).expect("removed");
}
}
}