登録して招待リンクを共有すると、動画再生報酬と紹介報酬を獲得できます。

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 🌍 You don't have to write your system prompt from scratch. The claude_code preset with append lets you keep all built-in safety and tool guidance while adding your own instructions on top. Plus, excludeDynamicSections enables cross-machine prompt cache sharing for fleet deployments. 📌 Title: System Prompt Preset + Append Pattern 🔗 URL: 🧩 Overview The Claude Agent SDK offers three starting points for system prompts: (1) minimal default (when `systemPrompt` is unset — covers tool calling only), (2) `claude_code` preset (the full Claude Code CLI prompt), and (3) custom string (complete control). The most powerful pattern is the `claude_code` preset combined with `append`: it preserves the preset's tool usage instructions, security and safety rules, and coding conventions, while letting you add custom instructions at the end. Importantly, CLAUDE.md content is injected into the conversation, not the system prompt, so it works with any system prompt configuration. 🛠 Usage Pass a dict to `system_prompt` with the preset and append fields. Optionally enable `exclude_dynamic_sections` for cache sharing. ```python from claude_agent_sdk import query, ClaudeAgentOptions # Preset + append: keep all defaults, add custom instructions async for message in query( prompt="Help me write a Python function to calculate fibonacci numbers", options=ClaudeAgentOptions( system_prompt={ "type": "preset", "preset": "claude_code", "append": "Always include detailed docstrings and type hints in Python code.", } ), ): pass # process messages # Enable cross-session cache sharing async for message in query( prompt="Triage the open issues in this repo", options=ClaudeAgentOptions( system_prompt={ "type": "preset", "preset": "claude_code", "append": "You operate Acme's internal triage workflow.", "exclude_dynamic_sections": True, # Move env context to user message }, ), ): pass ``` 🏗 Integration into Production Systems - Use `claude_code` preset + `append` as the default for coding agents, eliminating the need to reimplement security rules and tool guidance - Set `exclude_dynamic_sections: True` to move working directory, OS, and shell info from the system prompt to the user message, enabling prompt cache sharing across machines - CLAUDE.md loads automatically when `setting_sources` includes `"project"`, functioning independently of the system prompt choice 💡 Use Cases 🏢 Internal coding standards: maintain preset safety while appending company-specific conventions 🌐 Fleet cost reduction: share prompt cache across all machines with excludeDynamicSections 🤖 Specialized agents: use custom string for non-coding agents (data analysis, support bots) where the coding preset is irrelevant ⚠️ Caveats - Custom string prompts require you to provide your own tool guidance and safety instructions - `excludeDynamicSections` moves environment context to the user message, which carries marginally less weight than system prompt placement - The SDK default (no `systemPrompt`) differs from the CLI default; explicitly set the preset when migrating from `claude -p` ✨ The preset + append pattern is the lowest-risk way to customize agent behavior without breaking safe defaults. #ClaudeAgentSDK# #AIAgent#
もっと見る