Answer: To make a parameter optional, declare it optional in the schema and apply the default in the handler. In TypeScript, add `.optional()` to the Zod field; in Python, use the JSON Schema form, leave the parameter out of `required`, and read it with `args.get()`. Status: Confirmed Entry: tool/claude-code/agents-and-automation/optional-tool-parameter Revision: 2 Digest: sha256:f2ec7acb254e8f7a (changes whenever the content changes) Timeline: Created: 2026-11-13T03:02:41Z Last changed: 2026-11-15T12:15:54Z (Example tool: get_precipitation_chance → —) Last verified: 2026-11-20T12:16:28Z Next check: 2026-11-21T12:16:28Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of TypeScript approach | .optional() | [1] | 2026-11-20 Python approach | args.get() | [1] | 2026-11-20 General rule | declare it optional in the schema and apply the default in the handler | [1] | 2026-11-20 Sources: [1] Anthropic. "Give Claude custom tools". https://code.claude.com/docs/en/agent-sdk/custom-tools.md Role: primary. Accessed: 2026-11-20T12:16:28Z Quote: "**TypeScript**: add `.optional()` to the Zod field." (Supports: TypeScript approach) Quote: "leave the parameter out of `required`, and read it with `args.get()`" (Supports: Python approach) Quote: "To make a parameter optional, declare it optional in the schema and apply the default in the handler:" (Supports: General rule) Published: 2026-11-20T03:17:49Z Snapshot SHA-256: b07693fa054e2dfa05152f984f16332c405b2cba4c21f6318b5de68348eeb640 (captured 2026-11-20T12:16:27Z) Verification: Method: Automated extraction from [1] with deepseek-flash (JSON output, thinking disabled). Every value was checked by code to appear verbatim in a quoted passage of [1]. Cross-check: not-available at 2026-11-20T12:16:28Z. No independent second source is configured for this entry Last successful check: 2026-11-20T12:16:28Z Last attempt: 2026-11-20T12:16:28Z Notes and limitations: Extracted automatically from a single official source (section "Make a parameter optional"). Related: https://latestn.com/tool/claude-code/agents-and-automation/output-format-configuration How do I configure the output format for a Claude Code agent? https://latestn.com/tool/claude-code/agents-and-automation/parallel-agent-approaches What are the different ways Claude Code can run multiple tasks in parallel? https://latestn.com/tool/claude-code/agents-and-automation/persist-sessions-hosting How do I persist sessions and state when hosting the Claude Code Agent SDK in production? https://latestn.com/tool/claude-code/agents-and-automation/open-agent-view-by-default How do I open Claude Code's agent view by default? https://latestn.com/tool/claude-code/agents-and-automation/opt-in-task-tracking-tools How do I opt in to Claude Code's task-tracking tools on models where they aren't available by default? https://latestn.com/tool/claude-code/agents-and-automation/optimize-tool-discovery How can I optimize tool discovery for tool search in Claude Code? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-15T12:15:54Z | changed | Example tool: get_precipitation_chance → — | [1] 2026-11-15T12:15:54Z | changed | Python approach: leave the parameter out of `required`, and read it with `args.get()` → args.get() | [1] 2026-11-13T03:02:41Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/claude-code/agents-and-automation/optional-tool-parameter/latest Challenge this entry: Open challenges: None How: If a value here is wrong or out of date, send what is wrong and a link to evidence. Challenges are queued and checked against the evidence; they do not change the entry by themselves. If the entry changes as a result, the change log says so. Form: https://latestn.com/dispute/tool/claude-code/agents-and-automation/optional-tool-parameter POST: https://latestn.com/dispute/tool/claude-code/agents-and-automation/optional-tool-parameter with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/claude-code/agents-and-automation/optional-tool-parameter?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). How do I make a parameter optional in a Claude Code custom tool? Revision 2, last verified 2026-11-20T12:16:28Z. https://latestn.com/tool/claude-code/agents-and-automation/optional-tool-parameter (accessed 2026-11-21T10:00:41Z). @misc{LatestN_tool_claude_code_agents_and_automation_optional_tool_parameter_r2, title = {How do I make a parameter optional in a Claude Code custom tool?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/claude-code/agents-and-automation/optional-tool-parameter}}, note = {Revision 2; digest sha256:f2ec7acb254e8f7a; last verified 2026-11-20T12:16:28Z; accessed 2026-11-21T10:00:41Z} } Reuse: License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) Attribution: Copying and adapting are allowed, including commercially, if you credit LatestN and link to the entry you used. Each entry ends with a ready-made citation. URL: https://latestn.com/tool/claude-code/agents-and-automation/optional-tool-parameter