Get startedGet started for free

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.

This exercise is part of the course

Claude Code in Action

View Course

Exercise instructions

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

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions

# package.json before the SDK runs
print("BEFORE:\n" + open("package.json").read())


async def main():
    # The SDK is read-only by default; allow the Edit tool so Claude can write
    options = ____

    # Pass the options so the permission takes effect
    async for message in query(
        prompt='Add a "description" field to package.json.',
        options=____,
    ):
        print(message)


asyncio.run(main())

# package.json after the SDK runs - the description now appears
print("AFTER:\n" + open("package.json").read())
Edit and Run Code