Documentation
¶
Overview ¶
Package settings loads and merges Claude Code settings files.
Priority order (later overrides earlier):
- ~/.claude/settings.json (user global)
- <project>/.claude/settings.json (project shared)
- <project>/.claude/settings.local.json (project local, gitignored)
Mirrors src/utils/config.ts and src/utils/settings/settings.ts.
Index ¶
- func ApplyEnv(env map[string]string) func()
- func ApproveMcpjsonServer(name, choice string) error
- func ClaudeDir() string
- func RemovePlugin(pluginID string) error
- func SaveOutputStyle(name string) error
- func SaveRawKey(key string, value interface{}) error
- func SetPluginEnabled(pluginID string, enabled bool) error
- func UserSettingsPath() string
- type Hook
- type HookMatcher
- type HooksSettings
- type Merged
- type Permissions
- type Settings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyEnv ¶
ApplyEnv sets all key=value pairs from env into the process environment. Returns a cleanup function that restores the previous values. The caller must call cleanup when the tool invocation is complete. Mirrors the env injection behavior from src/utils/settings/settings.ts. Dangerous shell-execution keys (apiKeyHelper etc.) are skipped silently.
func ApproveMcpjsonServer ¶
ApproveMcpjsonServer records an approval decision for a project-scope MCP server. Choices: "yes" → add to enabledMcpjsonServers; "yes_all" → set enableAllProjectMcpServers=true and add to enabled; "no" → add to disabledMcpjsonServers. Idempotent; preserves all other settings keys.
func ClaudeDir ¶
func ClaudeDir() string
ClaudeDir returns the resolved configuration directory. Exported for use by other packages (memdir, session, etc.) that need the home path.
func RemovePlugin ¶
RemovePlugin removes a plugin from enabledPlugins in the user settings file.
func SaveOutputStyle ¶
SaveOutputStyle persists the active output style name to the user settings file.
func SaveRawKey ¶
SaveRawKey persists an arbitrary key/value to the user settings file using raw-map preservation so no other fields are disturbed.
func SetPluginEnabled ¶
SetPluginEnabled sets enabledPlugins[pluginID] in the user settings file.
func UserSettingsPath ¶
func UserSettingsPath() string
UserSettingsPath returns the path to the user-global settings file.
Types ¶
type Hook ¶
type Hook struct {
// Common fields
Type string `json:"type"` // "command" | "http" | "prompt" | "agent"
StatusMessage string `json:"statusMessage,omitempty"` // spinner text while running
If string `json:"if,omitempty"` // permission rule to gate firing
TimeoutSecs int `json:"timeout,omitempty"` // per-hook timeout override (seconds)
Once bool `json:"once,omitempty"` // remove after first execution
Async bool `json:"async,omitempty"` // fire-and-forget (non-blocking)
// type="command"
Command string `json:"command,omitempty"` // shell command
// type="http"
URL string `json:"url,omitempty"` // POST target
Headers map[string]string `json:"headers,omitempty"` // extra headers
AllowedEnvVars []string `json:"allowedEnvVars,omitempty"` // vars to interpolate in headers
// type="prompt" | "agent"
Prompt string `json:"prompt,omitempty"` // LLM prompt (may contain $ARGUMENTS)
Model string `json:"model,omitempty"` // model override
}
Hook is one hook entry. Type determines which fields are used. Mirrors src/schemas/hooks.ts (BashCommandHookSchema, HttpHookSchema, PromptHookSchema, AgentHookSchema).
type HookMatcher ¶
type HookMatcher struct {
Matcher string `json:"matcher"` // tool name or glob, "" = all
Hooks []Hook `json:"hooks"`
}
HookMatcher is a matcher + hooks pair.
type HooksSettings ¶
type HooksSettings struct {
PreToolUse []HookMatcher `json:"PreToolUse"`
PostToolUse []HookMatcher `json:"PostToolUse"`
SessionStart []HookMatcher `json:"SessionStart"`
Stop []HookMatcher `json:"Stop"`
}
HooksSettings is the hooks section.
type Merged ¶
type Merged struct {
// Allow is the combined allow list (user + project + local).
Allow []string
// Deny is the combined deny list.
Deny []string
// Ask is the combined ask list.
Ask []string
// DefaultMode is the effective default permission mode.
DefaultMode string
// Hooks is the merged hooks configuration.
Hooks HooksSettings
// Env is the merged environment map.
Env map[string]string
// AdditionalDirs is the merged set of additional allowed dirs.
AdditionalDirs []string
// Model is the preferred model override from settings (last layer wins).
Model string
// OutputStyle is the active output style name (last layer wins).
OutputStyle string
// Theme is the active palette name (last layer wins).
Theme string
// ThemeOverrides is the per-field color override map (last layer wins).
ThemeOverrides map[string]string
// Themes is the merged custom theme map (last layer wins per name).
Themes map[string]map[string]string
// OnboardingComplete is true once any layer sets it.
OnboardingComplete bool
// MCP project-scope approval gate. Last layer wins.
EnabledMcpjsonServers []string
DisabledMcpjsonServers []string
EnableAllProjectMcpServers bool
}
Merged is the result of loading and merging all settings layers.
type Permissions ¶
type Permissions struct {
Allow []string `json:"allow"`
Deny []string `json:"deny"`
Ask []string `json:"ask"`
DefaultMode string `json:"defaultMode"`
AdditionalDirs []string `json:"additionalDirectories"`
}
Permissions is the permissions section of a settings file.
type Settings ¶
type Settings struct {
Permissions Permissions `json:"permissions"`
Hooks HooksSettings `json:"hooks"`
// Env holds extra environment variables for tool execution.
Env map[string]string `json:"env"`
// EnabledPlugins mirrors the real Claude Code enabledPlugins field.
// Key is "pluginName@marketplace", value is true/false.
EnabledPlugins map[string]bool `json:"enabledPlugins,omitempty"`
// OnboardingComplete is set to true after the first-run welcome screen
// is dismissed. Mirrors CC's projectOnboardingState gate so returning
// users skip the welcome.
OnboardingComplete bool `json:"onboardingComplete,omitempty"`
// MCP project-scope approval gate (mirrors CC's MCPServerApprovalDialog).
// A server loaded from .mcp.json is allowed to connect only if its name
// is in EnabledMcpjsonServers OR EnableAllProjectMcpServers is true.
// Names in DisabledMcpjsonServers are never connected.
EnabledMcpjsonServers []string `json:"enabledMcpjsonServers,omitempty"`
DisabledMcpjsonServers []string `json:"disabledMcpjsonServers,omitempty"`
EnableAllProjectMcpServers bool `json:"enableAllProjectMcpServers,omitempty"`
// Model is the preferred model name (e.g. "claude-opus-4-7").
Model string `json:"model,omitempty"`
// OutputStyle is the active output style name, persisted across sessions.
OutputStyle string `json:"outputStyle,omitempty"`
// Theme is the active palette name (dark|light|dark-daltonized|
// light-daltonized|dark-ansi|light-ansi). Matches Claude Code's
// THEME_NAMES so settings.json values are interchangeable.
Theme string `json:"theme,omitempty"`
// ThemeOverrides applies per-field color tweaks on top of the named
// theme. Keys are lowercase Palette field names (e.g. "accent",
// "success"); values are #RRGGBB hex or ANSI 0-15 codes.
// conduit-only — Claude Code ignores this field.
ThemeOverrides map[string]string `json:"themeOverrides,omitempty"`
// Themes is a map of custom theme name → field map (same shape as
// themeOverrides). Lets users define entirely new themes selectable
// via /theme. conduit-only.
Themes map[string]map[string]string `json:"themes,omitempty"`
}
Settings is the parsed content of one settings file.