注册并分享邀请链接,可获得视频播放与邀请奖励。

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture 投稿は個人の意見です。
加入 May 2026
279 正在关注    408 粉丝
# Useful but Little-Known Features of Claude Agent SDK 🌍 Control exactly which filesystem settings your SDK agent loads with the setting_sources option. Selectively enable CLAUDE.md, skills, hooks, and settings.json — or disable them all for multi-tenant isolation. 📌 Title: Selective Settings Loading with setting_sources 🔗 URL: 🧩 Overview The `setting_sources` option (TypeScript: `settingSources`) controls which filesystem-based settings the SDK loads. There are three sources: `"project"` loads settings.json, hooks, CLAUDE.md, and skills from `/.claude/`; `"user"` loads user-level settings from `~/.claude/`; `"local"` loads `.claude/settings.local.json` and `CLAUDE.local.md`. Omitting the option defaults to all three (`["user", "project", "local"]`). Passing an empty array `[]` disables all filesystem settings. Managed policies and `~/.claude.json` are always loaded regardless. 🛠 Usage Pass a list to `setting_sources` to enable only the sources you need. ```python from claude_agent_sdk import query, ClaudeAgentOptions # Load project and user settings async for message in query( prompt="Help me refactor the auth module", options=ClaudeAgentOptions( setting_sources=["user", "project"], # Enable CLAUDE.md, skills, hooks allowed_tools=["Read", "Edit", "Bash"], ), ): pass # Disable all filesystem settings (programmatic config only) async for message in query( prompt="Analyze this code", options=ClaudeAgentOptions( setting_sources=[], # No filesystem settings loaded ), ): pass ``` 🏗 Integration into Production Systems - For multi-tenant environments, combine `setting_sources=[]` with `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` to prevent settings leakage between tenants - CLAUDE.md requires `"project"` in setting_sources to load — it won't load without it - Each source loads from specific locations: - `"project"`: `/.claude/` for settings.json and hooks; `` and parent dirs for CLAUDE.md and rules - `"user"`: `~/.claude/` for user settings, CLAUDE.md, and rules - `"local"`: `/.claude/settings.local.json` and parent dirs for CLAUDE.local.md 💡 Use Cases 🔒 Secure multi-tenant: run each tenant in isolated filesystem with `setting_sources=[]` to block cross-tenant config 🏗 CI/CD pipelines: enable only `"project"` to load repo-specific CLAUDE.md and skills 👤 Developer customization: include `"user"` to allow personal `~/.claude/CLAUDE.md` preferences ⚠️ Caveats - Some inputs are not controlled by setting_sources: managed policies, `~/.claude.json`, auto memory (`~/.claude/projects/`), MCP connectors - To disable auto memory, set `autoMemoryEnabled: false` in settings or `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in env - When you set setting_sources explicitly, all three defaults are disabled — list every source you need ✨ Proper setting_sources configuration gives you precise control over agent settings, enabling safe and predictable behavior across environments. #ClaudeAgentSDK# #AIAgent#
显示更多