1. Learn
  2. /
  3. 课程
  4. /
  5. Claude Code in Action

Connected

道练习

Grant the SDK a tool

By default, the Agent SDK is read-only: Claude can read and search, but it cannot change your files. To let it make edits, you create a ClaudeAgentOptions object listing the tools you want to allow and pass it to query().

A package.json is in your working directory. Complete the script so the SDK is allowed to use the Edit tool and asks Claude to add a description. The script prints package.json before and after, so you can watch the edit happen.

说明

100 XP
  • Create options by calling ClaudeAgentOptions() with allowed_tools set to a list containing "Edit".
  • Pass your options object to query() using the options argument.