--- title: CLI | Stainless description: Generate production-ready command line tools from your OpenAPI specification --- CLI is fully supported. The Stainless CLI generator creates command line tools from your OpenAPI specification. Generated CLIs include automatic pagination, interactive TUI explorer, and man pages. The CLI wraps your [Go SDK](/docs/targets/go/index.md) with command line argument parsing. **Example repositories:** - [stainless-api/stainless-api-cli](https://github.com/stainless-api/stainless-api-cli) ## Considerations A CLI tool lets your users interact with your API from the terminal and integrate it into shell scripts and automation workflows. CLI tools are particularly valuable for developer-focused APIs and CI/CD integrations. Before generating a CLI tool, be aware of the following requirements: **Go SDK dependency** The CLI generator creates a wrapper around your [Go SDK](/docs/targets/go/index.md), so Go must be included as one of your SDK targets and you must have a [public-facing repository](/docs/guides/publish#link-production-repos/index.md) for your Go SDK. **Argument structure limitations** Command line interfaces have limitations when passing deeply nested structures as arguments. The generator creates ergonomic flags, but you may need to provide deeply nested parameters in JSON or YAML format. ## Configuration To generate a CLI tool, add the `cli` target to your [Stainless configuration file](/docs/reference/config/#cli/index.md). The CLI generator creates a wrapper around your Go SDK, so you’ll need to enable both targets: ``` targets: go: package_name: github.com/my-company/my-sdk-go production_repo: my-org/my-sdk-go cli: binary_name: my-tool production_repo: my-org/my-tool edition: cli.2025-10-08 ``` For a complete list of configuration options, see the [CLI target reference](/docs/reference/config#cli/index.md). ## Usage ### Prerequisites for local testing To test or install the CLI locally, you need [Go](https://go.dev/doc/install) version 1.22 or later installed. Verify your installation: Terminal window ``` go version # go version go1.22.0 darwin/arm64 ``` **Understanding where Go installs binaries** When you run `go install`, the binary is placed in your Go bin directory: - **Default location**: `$HOME/go/bin` (or `$GOPATH/bin` if GOPATH is set) - **Check your path**: Run `go env GOPATH` to see the base directory If commands aren’t found after installation, add the Go bin directory to your PATH: Terminal window ``` # Add to your shell profile (.zshrc, .bashrc, etc.) export PATH="$PATH:$(go env GOPATH)/bin" ``` ### Test locally To test your CLI tool before release: 1. Clone your CLI staging repository 2. Navigate to the repository directory 3. Run the CLI using the provided script: Terminal window ``` ./scripts/run [resource] [command] [flags] ``` For example, to test an endpoint: Terminal window ``` ./scripts/run people retrieve --id 123 ``` **Installing locally** To build and install the CLI to your Go bin directory: Terminal window ``` go install ./cmd/my-tool ``` After installation, run the CLI directly: Terminal window ``` my-tool --version ``` If you get “command not found”, ensure your Go bin directory is in your PATH. See [Prerequisites for local testing](#prerequisites-for-local-testing) above. ### Basic usage The basic structure of your command line tool follows this format: Terminal window ``` my-tool [resource [sub-resource...]] method-name --method-arg value ``` For example, if your Stainless configuration has the following resources: ``` resources: $client: methods: current_status: get /status people: methods: retrieve: get /person/{id} create: post /person list: get /people ``` Then your generated CLI tool can be used like this: Terminal window ``` my-tool current-status # Output: {"status": "Up and running!"} my-tool people create --job "President" \ --name.full-name "Abraham Lincoln" \ --name.nickname "Abe Lincoln" my-tool people retrieve --id 123 my-tool people list ``` Note that method names like `current-status` and flags like `--full-name` use `kebab-case`, which is conventional for command line tools. ### Argument parsing Get help for any command using the `--help` flag: Terminal window ``` # General help my-tool --help # Help for a specific endpoint my-tool people create --help ``` You can also pipe JSON or YAML data as body parameters: Terminal window ``` my-tool people create < **Settings** > **Developer Settings** > **Personal Access Tokens** > **Fine-grained tokens** > **Generate new token**. 2. Choose your organization as the resource owner. 3. Set “No expiration” to avoid regular renewal (recommended), or choose an expiration date. 4. Choose “Only select repositories” and select the homebrew repository you created. 5. Add permissions for “Contents” and “Pull requests” with read and write access. 6. Generate the token and save it securely. Add the token to your production repo 1. In your CLI tool’s production repository, navigate to **Secrets and variables** > **Actions** > **New repository secret**. The URL should look like `https://github.com///settings/secrets/actions/new`. 2. Add a new secret named `HOMEBREW_TAP_GITHUB_TOKEN` with your token. Update your Stainless config Update the [Stainless config](/docs/reference/config#cli/index.md) and save: ``` targets: cli: publish: homebrew: tap_repo: your-org/homebrew-tools homepage: https://example.com description: The official CLI for YourOrg. ``` Install and use Once published, users can install your CLI using: Terminal window ``` brew tap your-org/tools brew install your-tool # or more concise: brew install your-org/tools/your-tool ```