Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

claude agent sdk

Sushmithamallesh0fb9ab7f1c82
diff --git a/fern/pages/src/tool-router/quickstart.mdx b/fern/pages/src/tool-router/quickstart.mdx
index 3a4f3cce5..2acf8032c 100644
--- a/fern/pages/src/tool-router/quickstart.mdx
+++ b/fern/pages/src/tool-router/quickstart.mdx
@@ -68,6 +68,40 @@ When the agent needs authentication, it will prompt the user with a link to conn
</Step>
</Steps>
+</Tab>
+
+<Tab title="Claude Agent SDK">
+
+<Steps>
+<Step title="Install">
+<CodeGroup>
+```bash title="Python" for="python"
+pip install composio claude-agent-sdk
+```
+```bash title="TypeScript" for="typescript"
+npm install @composio/core @anthropic-ai/claude-agent-sdk
+```
+</CodeGroup>
+</Step>
+
+<Step title="Create session and run agent">
+[Sessions](/tool-router/users-and-sessions) are ephemeral, user-scoped and manage connections and tools for that user.
+
+<Info>
+- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).
+- Set your `ANTHROPIC_API_KEY` environment variable with your [Anthropic API key](https://platform.claude.com/settings/keys).
+- `userId` is your user's unique identifier. See [User Management](/docs/user-management) for details.
+</Info>
+
+When the agent needs authentication, it will prompt the user with a link to connect their account. If you want to customise the authentication flow and have more control over the user experience, see [Manual Authentication](/tool-router/manually-authenticating-users).
+
+<CodeGroup>
+<SnippetCode src="fern/snippets/tool-router/python/quickstart-claude.py" title="Python" for="python" />
+<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-claude.ts" title="TypeScript" for="typescript" />
+</CodeGroup>
+</Step>
+</Steps>
+
</Tab>
</Tabs>
diff --git a/fern/snippets/tool-router/python/quickstart-claude.py b/fern/snippets/tool-router/python/quickstart-claude.py
new file mode 100644
index 000000000..0421d3ff5
--- /dev/null
+++ b/fern/snippets/tool-router/python/quickstart-claude.py
@@ -0,0 +1,52 @@
+import asyncio
+from claude_agent_sdk.client import ClaudeSDKClient
+from claude_agent_sdk.types import (
+ ClaudeAgentOptions,
+ ResultMessage,
+ AssistantMessage,
+ TextBlock,
+ ToolUseBlock
+)
+from composio import Composio
+import os
+
+# Initialize Composio and create a Tool Router session
+composio = Composio(api_key=os.environ["COMPOSIO_API_KEY"])
+user_id = "user_123" # Your user's unique identifier
+session = composio.create(user_id=user_id)
+
+# Configure Claude with Composio MCP server
+options = ClaudeAgentOptions(
+ system_prompt="You are a helpful assistant with access to external tools. Always use the available tools to complete user requests instead of just explaining how to do them.",
+ mcp_servers={
+ "composio": {
+ "type": "http",
+ "url": session.mcp.url,
+ "headers": {"x-api-key": os.environ["COMPOSIO_API_KEY"]},
+ }
+ },
+ permission_mode="bypassPermissions",
+)
+
+
+async def main():
+ async with ClaudeSDKClient(options) as client:
+ while True:
+ user_input = input("You: ").strip()
+ if user_input.lower() in ("quit", "exit"):
+ break
+
+ await client.query(user_input)
+ async for msg in client.receive_response():
+ if isinstance(msg, AssistantMessage):
+ for block in msg.content:
+ if isinstance(block, ToolUseBlock):
+ print(f"[🔧 Using tool: {block.name}]")
+ elif isinstance(block, TextBlock):
+ print(block.text, end="")
+ elif isinstance(msg, ResultMessage) and msg.result:
+ print(f"\n{msg.result}\n")
+
+
+if __name__ == "__main__":
+ asyncio.run(main())
\ No newline at end of file
diff --git a/fern/snippets/tool-router/typescript/quickstart-claude.ts b/fern/snippets/tool-router/typescript/quickstart-claude.ts
new file mode 100644
index 000000000..0e5df0b8c
--- /dev/null
+++ b/fern/snippets/tool-router/typescript/quickstart-claude.ts
@@ -0,0 +1,49 @@
+import { query, type Options } from "@anthropic-ai/claude-agent-sdk";
+import { Composio } from "@composio/core";
+import { createInterface } from "readline/promises";
+
+const composioApiKey = process.env.COMPOSIO_API_KEY!;
+const userId = "user_123"; // Your user's unique identifier
+
+const composio = new Composio({ apiKey: composioApiKey });
+const session = await composio.create(userId);
+
+const options: Options = {
+ systemPrompt: "You are a helpful assistant with access to external tools. Always use the available tools to complete user requests instead of just explaining how to do them.",
+ mcpServers: {
+ composio: {
+ type: "http",
+ url: session.mcp.url,
+ headers: { "x-api-key": composioApiKey }
+ },
+ },
+ permissionMode: "bypassPermissions",
+ allowDangerouslySkipPermissions: true,
+};
+
+const rl = createInterface({ input: process.stdin, output: process.stdout });
+
+console.log("Chat with Claude (type 'quit' to exit)\n");
+
+while (true) {
+ const input = (await rl.question("You: ")).trim();
+ if (input.toLowerCase() === "quit" || input.toLowerCase() === "exit") break;
+
+ process.stdout.write("Claude: ");
+ for await (const msg of query({ prompt: input, options })) {
+ if (msg.type === "assistant") {
+ for (const block of msg.message.content) {
+ if (block.type === "tool_use") {
+ console.log(`\n[🔧 Using tool: ${block.name}]`);
+ } else if (block.type === "text") {
+ process.stdout.write(block.text);
+ }
+ }
+ } else if (msg.type === "result" && msg.subtype === "success") {
+ console.log(`\n[Tool Result: ${msg.result}]`);
+ }
+ }
+ console.log();
+}
+
+rl.close();
\ No newline at end of file