Home › LLM apps & agents › Claude Agent SDK CLAUDE.md

Claude Agent SDK CLAUDE.md

CLAUDE.md for building agents with the Claude Agent SDK (Python/TypeScript): options, tools, permissions, and hooks.

Claude Code (CLAUDE.md)LLM apps & agents

How to use

Save this as CLAUDE.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

CLAUDE.mdDownload  
# CLAUDE.md: Claude Agent SDK app

## Packages
- Python: `claude-agent-sdk` (`from claude_agent_sdk import query, ClaudeSDKClient, ClaudeAgentOptions`). TypeScript: `@anthropic-ai/claude-agent-sdk`. Pin the version; it releases often, so check the changelog before upgrading.
- `ANTHROPIC_API_KEY` (or the configured cloud provider credentials) from env only.

## Building the agent
- One-shot tasks use `query(prompt=..., options=...)`; multi-turn sessions use `ClaudeSDKClient` as an async context manager.
- Configure everything through `ClaudeAgentOptions`: `system_prompt`, `allowed_tools` (explicit list), `disallowed_tools`, `permission_mode`, `cwd`, `max_turns`, `mcp_servers`. Keep options in one `agent/config.py`.
- Least privilege: start with read-only tools (`Read`, `Grep`, `Glob`). Add `Edit`/`Write`/`Bash` only if the task needs them, and scope `cwd` to a workspace directory.
- Never use a bypass-all permission mode in production. Use a `can_use_tool` callback or `PreToolUse` hooks to block dangerous commands (`rm -rf`, `git push`, network writes) and to require approval.
- Custom tools: define with `@tool(name, description, schema)` and expose via `create_sdk_mcp_server(...)`; refer to them as `mcp__<server>__<tool>` in `allowed_tools`.
- Use subagents (`agents=` option) for focused subtasks with their own tools and prompts.

## Handling output
- Iterate messages; handle `AssistantMessage`, tool use, and the final `ResultMessage` (cost, usage, errors). Log `total_cost_usd` and turn counts.
- Catch SDK errors (`CLINotFoundError`, `ProcessError`) and fail clearly.

## Tests
Unit-test tool functions and hooks directly; run full-agent tests only behind a flag (`RUN_AGENT_E2E=1`) because they cost money.

More: all LLM apps & agents rules · all Claude Code (CLAUDE.md) rules

Related rules

CrewAI multi-agent AGENTS.md

AGENTS.md for CrewAI 1.x projects: YAML agents and tasks, crews and flows, tools, and cost-aware runs.

AGENTS.mdLLM apps & agents

LangGraph agent rules

Cursor rules for building agents with LangGraph in Python: typed state, nodes, tools, checkpointers, and tests.

CursorLLM apps & agents

LLM app (Python) AGENTS.md

AGENTS.md for Python apps that call LLM APIs (OpenAI, Anthropic, Gemini): prompts, structured output, evals, and cost.

AGENTS.mdLLM apps & agents

OpenAI Agents SDK rules

Cursor rules for the OpenAI Agents SDK (Python 0.2x): agents, function tools, handoffs, guardrails, sessions, and tracing.

CursorLLM apps & agents

Vercel AI SDK rules

Cursor rules for the Vercel AI SDK 5 in TypeScript: streamText, structured output, tools, and useChat UIs.

CursorLLM apps & agents

MCP server (Python) CLAUDE.md

CLAUDE.md for building Model Context Protocol servers in Python with the official SDK (FastMCP), tools, and tests.

Claude Code (CLAUDE.md)MCP servers

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.