...
March 16, 2026 · View on GitHub
Contributing to documentation
The documentation for this SDK lives at platform.claude.com/docs/en/api/sdks/ruby. To suggest changes, open an issue.
Setting up the environment
This repository contains a .ruby-version file, which should work with either rbenv or asdf with the ruby plugin.
Please follow the instructions for your preferred version manager to install the Ruby version specified in the .ruby-version file.
To set up the repository, run:
$ ./scripts/bootstrap
This will install all the required dependencies.
Modifying/Adding code
Most of the SDK is generated code. Modifications to code will be persisted between generations, but may result in merge conflicts between manual patches and changes from the generator. The generator will never modify the contents of lib/anthropic/helpers/ and examples/ directory.
Adding and running examples
All files in the examples/ directory are not modified by the generator and can be freely edited or added to.
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative "../lib/anthropic"
# ...
$ chmod +x './examples/<your-example>.rb'
# run the example against your api
$ ruby './examples/<your-example>.rb'
Using the repository from source
If you’d like to use the repository from source, you can either install from git or reference a cloned repository:
To install via git in your Gemfile:
gem "anthropic", git: "https://github.com/anthropics/anthropic-sdk-ruby"
Alternatively, reference local copy of the repo:
$ git clone -- 'https://github.com/anthropics/anthropic-sdk-ruby' '<path-to-repo>'
gem "anthropic", path: "<path-to-repo>"
Running commands
Running rake by itself will show all runnable commands.
$ bundle exec rake
Running tests
Most tests require you to set up a mock server against the OpenAPI spec to run the tests.
$ ./scripts/mock
$ bundle exec rake test
Linting and formatting
This repository uses rubocop for linting and formatting of *.rb files; And syntax_tree is used for formatting of both *.rbi and *.rbs files.
There are two separate type checkers supported by this library: sorbet and steep are used for verifying *.rbi and *.rbs files respectively.
To lint and typecheck:
$ bundle exec rake lint
To format and fix all lint issues automatically:
$ bundle exec rake format
Editor Support
Ruby LSP
Ruby LSP has quite good support for go to definition, but not auto-completion.
This can be installed along side Solargraph.
Solargraph
Solargraph has quite good support for auto-completion, but not go to definition.
This can be installed along side Ruby LSP.
Sorbet
Sorbet should mostly work out of the box when editing this library directly. However, there are a some caveats due to the colocation of *.rb and *.rbi files in the same project. These issues should not otherwise manifest when this library is used as a dependency.
-
For go to definition usages, sorbet might get confused and may not always navigate to the correct location.
-
For each generic type in
*.rbifiles, a spurious "Duplicate type member" error is present.
Documentation Preview
To preview the documentation, run:
$ bundle exec rake docs:preview [PORT=8808]