Skip to main content

Module settings

Module settings 

Source
Expand description

Read-side access to Claude Code’s on-disk settings files.

Claude Code reads up to four JSON files in increasing order of precedence (later layers override earlier ones):

  1. ~/.claude/settings.json – user defaults
  2. ~/.claude/settings.local.json – user-private overrides
  3. <project>/.claude/settings.json – project-shared (checked into version control)
  4. <project>/.claude/settings.local.json – project-private overrides (typically gitignored)

Plus a managed (enterprise) layer that lives outside these paths and isn’t covered here.

This module reads each layer as opaque serde_json::Value and returns them side-by-side, without merging. Claude Code’s merge semantics are non-trivial and not fully documented (some object fields deep-merge, some arrays concatenate, some replace), and reproducing them here would risk diverging from the binary’s actual behavior in subtle ways. Callers who want an “effective” view can apply their own merge with full knowledge of which source produced which value – the per-layer split makes that attribution possible.

§What’s in a settings file

Field names worth knowing (not exhaustive; survives unknown keys since values are kept as raw JSON):

  • env – environment variables passed to spawned claude subprocesses. Often contains secrets (ANTHROPIC_API_KEY, tokens, etc.). Use redact_env_values before forwarding to a less-trusted consumer.
  • permissions{ allow: [...], deny: [...] } Bash-pattern and tool-name allow/deny lists.
  • hooks – map keyed by hook event (PreToolUse, PostToolUse, UserPromptSubmit, etc.); values are arrays of shell-command hook configs.
  • statusLine – statusline command config.
  • enabledPlugins – map of plugin keys to enabled state.
  • enableAllProjectMcpServers, enabledMcpjsonServers – MCP server gates.

§Example

use claude_wrapper::settings::SettingsLoader;

let layers = SettingsLoader::home()?
    .project_root("/path/to/repo")
    .load()?;

if let Some(user) = &layers.user {
    println!("user settings present: {} top-level keys",
        user.as_object().map(|o| o.len()).unwrap_or(0));
}

Structs§

Settings
Parsed settings layers as returned by SettingsLoader::load.
SettingsLoader
Builder/loader for the settings layers.
SettingsPaths
Absolute paths the loader would read, regardless of which files exist. Returned alongside Settings so diagnostics can show “the project layer would come from <path>” even when the file isn’t there.

Enums§

SettingsLayer
One of the four settings layers Claude Code can read.

Functions§

redact_env_values
Replace every value under the top-level env object with "<redacted>", keeping the keys visible. Safe to call on any JSON value, including non-objects and objects without an env field. Other top-level keys (permissions, hooks, etc.) are left untouched.