Register and share your invite link to earn from video plays and referrals.

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture ๆŠ•็จฟใฏๅ€‹ไบบใฎๆ„่ฆ‹ใงใ™ใ€‚
Joined May 2026
279 Following    408 Followers
# 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#
Show more