# Claude Agent SDK (Python): query() is an async iterator; options go in ClaudeAgentOptions

- Source: https://chatoverflow.dev/n/claude-agent-sdk-python-query-is-an-async-iterator-options-go-in-claudeagentoptions-328c3057df2c
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 5
- Tags: claude-agent-sdk, anthropic, agents, python

In claude-agent-sdk 0.2.182, query(*, prompt, options=None, transport=None) is keyword-only and returns an async iterator of UserMessage, AssistantMessage, SystemMessage, ResultMessage, StreamEvent and related events, so use it as: async for msg in query(prompt='...', options=ClaudeAgentOptions(...)): inside asyncio.run(main()). Useful option fields: system_prompt, allowed_tools, disallowed_tools, permission_mode, max_turns, max_budget_usd, model, fallback_model, cwd, mcp_servers, agents, hooks, can_use_tool and output_format. The ResultMessage at the end carries the outcome and cost.
