Skip to main content

ClaudeSettings

Struct ClaudeSettings 

Source
pub struct ClaudeSettings {
    pub env: BTreeMap<String, String>,
    pub other: BTreeMap<String, Value>,
}
Expand description

Claude settings manager for API configuration

Manages the Claude settings.json file to control Claude’s API configuration Handles environment variables and preserves other settings

Fields§

§env: BTreeMap<String, String>

Environment variables map (ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL, ANTHROPIC_MODEL, ANTHROPIC_SMALL_FAST_MODEL)

§other: BTreeMap<String, Value>

Other settings to preserve when modifying API configuration

Implementations§

Source§

impl ClaudeSettings

Source

pub fn load(custom_dir: Option<&str>) -> Result<Self>

Load Claude settings from disk

Reads the JSON file from the configured Claude settings directory Returns default empty settings if file doesn’t exist Creates the file with default structure if it doesn’t exist

§Arguments
  • custom_dir - Optional custom directory for Claude settings
§Errors

Returns error if file exists but cannot be read or parsed

Source

pub fn save(&self, custom_dir: Option<&str>) -> Result<()>

Save Claude settings to disk

Writes the current state to the configured Claude settings directory Creates the directory structure if it doesn’t exist Ensures the env field is properly serialized

§Arguments
  • custom_dir - Optional custom directory for Claude settings
§Errors

Returns error if directory cannot be created or file cannot be written

Source

pub fn switch_to_config(&mut self, config: &Configuration)

Switch to a specific API configuration

Updates the environment variables with the provided configuration Ensures env field exists before updating

§Arguments
  • config - Configuration containing token, URL, and optional model settings to apply
Source

pub fn remove_anthropic_env(&mut self)

Remove Anthropic environment variables

Clears all Anthropic-related environment variables from settings Used to reset to default Claude behavior

Source

pub fn switch_to_config_with_mode( &mut self, config: &Configuration, mode: StorageMode, custom_dir: Option<&str>, ) -> Result<()>

Switch to a specific API configuration with specified storage mode

Updates the settings.json file based on the storage mode:

  • Env mode: Launch Claude with environment variables (cleans settings.json)
  • Config mode: Write to env field in settings.json (settings file persistence)
§Arguments
  • config - Configuration containing token, URL, and optional model settings to apply
  • mode - Storage mode to use (Env or Config)
  • custom_dir - Optional custom directory for Claude settings
§Errors

Returns error if settings cannot be saved

Trait Implementations§

Source§

impl Clone for ClaudeSettings

Source§

fn clone(&self) -> ClaudeSettings

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for ClaudeSettings

Source§

fn default() -> ClaudeSettings

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ClaudeSettings

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ClaudeSettings

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,