$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
Claude CodeadvancedNew

Agent SDK Setup

Share

Build custom agents with Claude Agent SDK

Works with OpenClaude

You are a backend engineer setting up the Claude Agent SDK to build custom autonomous agents. The user wants to initialize a project, configure the SDK, and create a working agent that can interact with tools.

What to check first

  • Verify Node.js version 18+ is installed: node --version
  • Check your Anthropic API key is set: echo $ANTHROPIC_API_KEY (should output your key, not be empty)
  • Confirm you have npm or yarn available: npm --version

Steps

  1. Create a new project directory and initialize npm: mkdir my-agent && cd my-agent && npm init -y
  2. Install the Anthropic SDK: npm install @anthropic-ai/sdk
  3. Create an agent.js file and import the Anthropic client with require("@anthropic-ai/sdk")
  4. Initialize the Anthropic client using your API key from environment variables
  5. Define tool schemas using the tools parameter — each tool needs name, description, and input_schema with JSON Schema format
  6. Create the agentic loop using messages.create() with model: "claude-3-5-sonnet-20241022" and max_tokens: 4096
  7. Check the response stop_reason — if it's "tool_use", process tool calls from content array
  8. Execute the actual tool function based on the tool name, then add results back to messages with role: "user" and content containing a tool_result block
  9. Continue looping until stop_reason is "end_turn"

Code

const Anthropic = require("@anthropic-ai/sdk");

const client = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

// Define tools the agent can use
const tools = [
  {
    name: "get_weather",
    description: "Get the current weather for a location",
    input_schema: {
      type: "object",
      properties: {
        location: {
          type: "string",
          description: "City name",
        },
      },
      required: ["location"],
    },
  },
  {
    name: "calculate",
    description: "Perform mathematical calculations",
    input_schema: {
      type: "object",
      properties: {
        expression: {
          type: "string",
          description: "Math expression to evaluate",
        },
      },
      required: ["expression"],
    },
  },
];

// Simulated tool implementations
function executeToolCall(toolName, toolInput) {
  if (toolName === "get_weather") {
    return `Weather in ${toolInput.location}: 72°F, Sunny`;
  } else if (toolName === "calculate") {
    return `Result: ${eval(toolInput.expression)}`;
  }
  return "Unknown tool";
}

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryClaude Code
Difficultyadvanced
Version1.0.0
AuthorClaude Skills Hub
claude-codeagentsdk

Install command:

curl -o ~/.claude/skills/claude-agent-sdk.md https://claude-skills-hub.vercel.app/skills/claude-code/claude-agent-sdk.md

Related Claude Code Skills

Other Claude Code skills in the same category — free to download.

Want a Claude Code skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.