Your first query
The simplest way to interact with Claude is using thequery() function. Here’s a complete working example:
The
query() function is an async function that returns an AsyncIterator of response messages.Understanding the response
To extract specific content from Claude’s responses, check the message type and content blocks:Configuring with options
Customize Claude’s behavior usingClaudeAgentOptions:
Using tools
Enable Claude to perform actions like reading and writing files:Auto-accepting tool usage
Setting the working directory
Specify a working directory for file operations:Complete example
Here’s a complete example combining multiple concepts:Next steps
Client API
Build interactive, bidirectional conversations
Custom tools
Create your own tools for Claude to use
Hooks
Add custom logic to the agent loop
Error handling
Handle errors gracefully in your application