Skip to content

Use the framework selector to see the matching packages and runtime provider code.

Use swy as a shorter alias for swytchcode in any of the commands below.

Choose your framework

    1. Install the CLI and SDK

      Terminal window
      npm install -g swytchcode
      Terminal window
      npm install @swytchcode/runtime @anthropic-ai/sdk
    2. Initialize Swytchcode, fetch a toolkit, and enable a tool

      swy init creates the project’s tooling.json, swy get downloads the GitHub integration bundle, and swy add method resolves one of its methods into tooling.json.tools so it can actually be called. The example below stars a repo, so it also connects a GitHub account.

      Terminal window
      swy init
      swy get github
      swy add method github.user.starred.update
      swy auth connect github
    3. Initialize the provider

      import "dotenv/config";
      import Anthropic from "@anthropic-ai/sdk";
      import { Swytchcode, TOOL_USE_INSTRUCTIONS } from "@swytchcode/runtime";
      import { AnthropicProvider } from "@swytchcode/runtime/providers/anthropic";
      async function runAgent() {
      const anthropic = new Anthropic();
      // 1. Initialize Swytchcode with the Anthropic provider
      const swx = new Swytchcode(new AnthropicProvider());
      // 2. Fetch the tools you want your agent to use (e.g., GitHub tools)
      const tools = await swx.tools.get({ toolkits: ["github"] });
      // 3. Build the system prompt: your own instructions plus TOOL_USE_INSTRUCTIONS,
      // which tells Claude to call the tool directly for action requests instead of
      // just describing what it would do
      const system = `You are a helpful assistant.\n\n${TOOL_USE_INSTRUCTIONS}`;
      const messages: Anthropic.MessageParam[] = [
      { role: "user", content: "Star the swytchcodehq/swytchcode-examples repo on GitHub for me." },
      ];
      // 4. Loop until Claude stops requesting tool calls: run any tool calls
      // Claude made and send the results back so it can keep working toward
      // a final natural-language reply instead of stopping after one round
      const MAX_TURNS = 10;
      let response: Anthropic.Message;
      for (let turn = 0; ; turn++) {
      if (turn >= MAX_TURNS) {
      throw new Error(`Exceeded ${MAX_TURNS} tool-use turns without a final reply`);
      }
      response = await anthropic.messages.create({
      model: "claude-sonnet-5",
      max_tokens: 1024,
      system,
      tools: tools,
      messages,
      });
      messages.push({ role: "assistant", content: response.content });
      if (response.stop_reason === "max_tokens") {
      throw new Error("Response truncated at max_tokens - increase the limit and retry");
      }
      if (response.stop_reason !== "tool_use") break;
      const toolResults = await swx.handleToolCalls(response);
      messages.push({ role: "user", content: toolResults as Anthropic.ToolResultBlockParam[] });
      }
      for (const block of response.content) {
      if (block.type === "text") console.log(block.text);
      }
      }
      runAgent();
    4. Handle the tool loop

      Pass the tool result back to Claude. For a manual loop in Python, use swx.handle_tool_calls(response) to execute tool calls and create tool_result blocks.

    5. Run the file

      Save the example as main.js or main.py, then run:

      Terminal window
      node main.js