General commands
These commands apply to every Fern project, whether it publishes docs, SDKs, or both. They create and validate a project, authenticate the CLI, manage your organization’s API keys, update your API definition, and set the CLI version your organization runs. Each one accepts the global options.
Detailed command documentation
fern init
Use fern init to initialize a new Fern workspace in the current folder.
Setup wizard
Run fern init with no flags in a terminal to start the setup wizard (Fern CLI 5.226.0 or later). The wizard scans the repo (the same scan as fern detect), asks whether to set up SDKs, Docs, a CLI, or a combination, then runs these steps, asking before each one:
- Set up Fern: Checks your organization name and creates the organization if the name is free. Then creates the
fern/folder from your API spec and a docs site from Fern’s docs starter, with your company’s logo, favicon, and accent color. The wizard shows the brand it found and asks before using it. - Set up your coding agent: Adds the Fern and
fern-docsskills, and optionally connects Fern’s MCP server. - Preview and publish your docs: Creates a preview link, then asks whether to publish.
- Generate your SDKs: Generates the SDK targets, and the CLI if you picked it, that the wizard added to
sdk-config.yml(orgenerators.ymlin older projects).
When you aren’t logged in, the first step asks whether to log in, continue without an account (see --guest), or skip. Each step is also available as a standalone command: fern detect, fern org check, fern org create, fern docs brand, fern docs url check, and fern agent setup.
The wizard always runs the installed CLI, even in projects whose fern.config.json pins an older version, and pins new projects to the latest CLI release. With any flag other than --guest, or outside a terminal (CI, scripts, coding agents), fern init skips the wizard and creates the project directly. By default, you’ll see the IMDb API example.
When initializing with OpenAPI, your project structure will look like this:
openapi
Use --openapi to initialize a project from an OpenAPI specification:
grpc
Use --grpc to initialize a sample gRPC service and a generators.yml that generates a C# SDK. See gRPC.
proto
Use --proto to initialize from your own .proto file or a directory of them. The files are copied into fern/proto/.
--grpc and --proto cannot be combined with each other or with --openapi, --fern-definition, --docs, --mintlify, or --readme.
docs
By adding --docs, you’ll also get a sample documentation website for your API with an API Reference section.
The file added will contain:
To publish the API docs, run fern generate --docs.
template
Use --template with --docs to start from Fern’s docs starter, the template the Fern Dashboard onboarding uses. Pick a layout: stacked, side-by-side, or minimal. Requires Fern CLI 5.226.0 or later.
The CLI downloads the starter on first use and caches it in ~/.fern/docs-starter. If the download fails, it creates the basic --docs site instead. Run fern docs brand afterward to apply your company’s logo and colors.
guest
Use --guest to run the setup wizard without a Fern account. The wizard publishes your docs to a temporary site and generates your SDKs with fern generate --guest, then prints the link that claims both into your organization and the session’s expiry.
--guest works only on its own, in a terminal. In scripts and coding agents, run fern init --organization <name> and then fern generate --guest.
mintlify
By adding --mintlify PATH_TO_MINT_CONFIG, the CLI will automatically convert your Mintlify docs folder into a Fern docs site, based on the mint.json file.
The CLI will create a fern/ folder with the following structure:
readme
The fern init command supports importing Readme generated docs sites. This requires having a local chromium browser instance installed.
You can ensure this is installed by installing the fern cli from source, following the instructions here.
By adding --readme URL_TO_README_DOCS_SITE, the CLI will automatically convert the Readme generated docs site into a Fern docs site.
The CLI will create a fern/ folder with the following structure:
For more information on getting started, check out our Quickstart Guide
fern detect
Use fern detect to see what Fern finds in the current folder: API specs, frameworks, docs tools, coding agents, the package manager, an existing Fern project, and the installed Fern CLI version. The setup wizard runs the same scan to plan its steps. Requires Fern CLI 5.226.0 or later.
json
Use --json to print the full scan result as JSON.
fern agent setup
Use fern agent setup (Fern CLI 5.226.0 or later) to give the repo’s coding agents Fern’s instructions. It adds the Fern skill (fern/SKILL.md) to each detected agent’s project skills folder, and leaves existing copies alone:
When no agent is detected, it adds the skill for Claude Code, Cursor, and Codex. If the repo has a docs site (fern/docs.yml), it also installs the fern-docs skill.
mcp
Use --mcp to also connect Fern’s MCP server to your coding agents, as fern mcp install does. This logs you in to Fern if you aren’t already.
skip-skill
Use --skip-skill to skip the fern-docs skill and add only the Fern skill.
fern export
Use fern export to generate an OpenAPI spec for your API. This is useful when you’ve defined your API in a format other than OpenAPI (such as the Fern Definition) and need to export it for integration with other tools or services.
The path argument is the output file to write. Use a .yml or .json extension to choose the format of the generated spec.
api
Use --api to specify which API to export when you have multiple APIs defined in your fern/apis/ folder.
indent
Use --indent to set the indentation size, in spaces, of the generated spec.
audience
Use --audience to export only the endpoints, webhooks, and environments tagged for an audience, along with the types they reference. This produces a filtered spec, such as a public-only spec without internal endpoints. Tag API elements with audiences in the Fern Definition or x-fern-audiences in OpenAPI. Without --audience, the full API is exported.
Repeat the flag to export the union of multiple audiences:
fern check
The --broken-links and --strict-broken-links flags are deprecated. Use the broken-links validation rule in docs.yml instead.
Use fern check to validate your API definition and Fern configuration, including fern.config.json, sdk-config.yml, and docs.yml. It checks for broken links, invalid API examples, configuration errors, and more. When all checks pass, the command produces no output.
Most fern check rules — including broken-links — validate against the navigation tree built from your local config and do not crawl your live deployed site or follow external URLs. The exception is the missing-redirects rule, which compares your local navigation against the previously published state and therefore requires fern login or FERN_TOKEN.
You can configure the severity of the validation rules run by fern check in your docs.yml file using the check.rules property.
To check links on a published site, use fern docs link check or the link checker in the Fern Dashboard instead.
api
Use --api <api> to specify which API you’d like to check.
warnings
Use --warnings to log warnings in addition to errors.
Usage in a GitHub Action
fern upgrade
Use fern upgrade to upgrade your compiler version in fern.config.json to the
latest version. It also upgrades generators in a legacy generators.yml to their minimum-compatible versions.
When your organization sets a CLI version policy, fern upgrade writes the highest version the policy allows rather than the latest published version. A --version below the organization’s minimum is raised to the minimum.
version
Use --version to upgrade to a specific published version of the fern-api package instead of the latest release. The version must be ahead of the version in fern.config.json. Use fern downgrade to move to an older version.
from
Use --from to set the version that migrations run from. Fern infers this from fern.config.json and git history. Pass it when that inference is wrong, such as after fern.config.json was edited by hand.
yes
Use --yes (-y) to answer yes to every migration prompt, for non-interactive environments like CI.
fern downgrade
Use fern downgrade to set the CLI version in fern.config.json to an older version. It rewrites the version field only: generator versions in generators.yml are left alone, and no migrations are reversed.
A CLI version policy doesn’t block the downgrade, but it does override it: the new version is written to fern.config.json, and subsequent commands still run the minimum required by your organization.
fern login
Use fern login to login to the Fern CLI via GitHub or Google. Logging in allows you
join GitHub organizations, gain permissions, and contribute to projects.
By default, fern login opens a browser for GitHub, Google, or Postman authentication. Two alternative flows are available:
device-code
Use --device-code to login via device code authorization in environments where a browser cannot open automatically (e.g., SSH sessions or containers).
Use --email to login via enterprise SSO. Pass the email address associated with your organization’s SSO provider.
To enable CI/CD, use fern token.
fern logout
Use fern logout to log out of the Fern CLI. This will clear your authentication
credentials and revoke access to your GitHub organizations and permissions.
After logging out, you’ll need to run fern login again to access protected features.
fern whoami
Use fern whoami to see which credential the CLI acts as in the current directory. Running it before generating or publishing confirms which account or API key a permission error applies to.
The report shows which login is in use:
- Organization token: a
FERN_TOKENenvironment variable is set. It takes precedence over a saved login. - User login: a credential saved by
fern login, shown with the account’s email (or username) and user ID. If Fern can’t verify the saved login, for example because it expired, the report says so and suggests runningfern loginagain. - Not logged in: neither a
FERN_TOKENnor a saved login is present.
If the repo has a guest session saved by fern generate --guest, the report also shows its session ID, organization, and expiry, plus the claim link while the session is live. An expired guest session is replaced by the next fern generate --guest run.
fern whoami always runs on the installed CLI, even in projects whose fern.config.json pins an older CLI version.
json
Use --json to print the report as a JSON object, for scripts and CI checks. The login.kind field is user, user-unverified, organization-token, or none. The guestSession field is present only when the repo has a saved guest session, and never includes the session token.
fern claim
Use fern claim to keep the work published from a guest session. Run it after fern login in the repo that ran fern generate --guest. By default it turns the guest organization into your own, or pass --org to move the work into an organization you administer.
fern claim moves the session’s docs site and SDK builds into the organization and removes the temporary-site banner and guest expiry. --docs-url gives the site a <slug>.docs.buildwithfern.com address, and --sdk-name names the SDK. When docs.yml has a single instance, its URL is set to the claimed site. If a move fails, the guest session is kept, so running fern claim again retries the move. See Try Fern as a guest for the full guest workflow.
The claim link printed by fern generate --guest does the same from the Fern Dashboard.
fern token
Use fern token to generate an API key for authenticating the Fern CLI in CI/CD environments. The API key is specific to your organization defined in fern.config.json and doesn’t expire. The key appears in fern org token list and on the API keys page in the Dashboard, and can be revoked from either. To name the key or manage existing keys, use the fern org token commands.
Generating an API key requires the Admin role in the organization. Members with the Editor or Viewer role receive a Failed to create token because you do not have the required permissions error and need an Admin to generate the key for them.
See Publishing your docs for instructions on using this API key in automated publishing workflows.
fern api update
Pulls the latest OpenAPI spec from the specified origin in generators.yml and
updates the local spec. Alternatively, you can automate this process by setting up a GitHub Action.
api
Use --api to specify the API to update if there are multiple specs with a defined origin in generators.yml. If you don’t specify an API, all OpenAPI specs with an origin will be updated.
fern api enrich
Use fern api enrich to convert examples from an overrides file, such as manually authored x-fern-examples or an ai_examples_override.yml file, into portable OpenAPI examples that any OpenAPI-compatible tool can consume.
The command merges examples from an overrides file into native OpenAPI example fields and strips the x-fern-examples keys from the output. When an endpoint has multiple examples, each is stored as a named entry under the plural examples field.
The command requires two flags:
-f(or--file) — the overrides file containingx-fern-examples(e.g.,ai_examples_override.yml).-o(or--output) — the path for the enriched output file. Supports.ymland.jsonextensions.
Each x-fern-examples field is mapped to its standard OpenAPI location:
path-parameters→parameters[].example(wherein: path)query-parameters→parameters[].example(wherein: query)headers→parameters[].example(wherein: header)request→requestBody.content.*.exampleresponse.body→responses.<status>.content.*.example
fern org check
Use fern org check to see whether an organization name belongs to you, is free, or belongs to another team. When another team owns it, the CLI suggests free alternatives. Organization names use lowercase letters, numbers, and hyphens. Requires Fern CLI 5.226.0 or later and fern login.
json
Use --json to output { "organization": ..., "status": ..., "suggestions": [...] }. status is mine, available, taken, or unknown (the check couldn’t run).
fern org create
Use fern org create to create a Fern organization, with you as its first member. If you already belong to the organization, the command says so and changes nothing. If another team owns the name, it fails and suggests free names. Requires Fern CLI 5.226.0 or later and fern login.
json
Use --json to output { "organization": ..., "created": true }. created is false when you already belong to the organization.
fern org get
Use fern org get to view your organization’s CLI version policy.
json
Use --json to output the raw cliVersionMin and cliVersionMax fields instead of a one-line description.
org
Use --org to override the organization ID from fern.config.json.
fern org set cli-version
Use fern org set cli-version to constrain the Fern CLI version used by every project in your organization. Requires an organization admin.
Each bound is an exact published version of the fern-api package.
org
Use --org to override the organization ID from fern.config.json.
fern org unset cli-version
Use fern org unset cli-version to remove your organization’s CLI version policy. Requires an organization admin.
Both bounds are removed by default. Pass --min or --max to clear one end and keep the other.
fern org token list
Use fern org token list to list your organization’s API keys, including revoked and expired keys. Each row shows the key’s name, token ID, status, creator, creation time, and last use. The secret value isn’t included, because it’s shown only once, at creation.
The fern org token commands require a user session from fern login. They reject an organization API key set as FERN_TOKEN, so unset FERN_TOKEN before running them. Any member of the organization can list keys.
json
Use --json to output the keys as a JSON array with ISO 8601 timestamps.
csv
Use --csv to export the keys as CSV, for example to audit them in a spreadsheet. The columns are Name, Token ID, Status, Created by, Created at, and Last used at.
org
Use --org to override the organization ID from fern.config.json.
fern org token create
Use fern org token create to create an organization API key for CI/CD. Requires the Admin role.
The CLI prints the token ID and the secret. The secret is shown only once, so store it immediately (for example as a FERN_TOKEN secret in your CI/CD provider). Only the secret goes to stdout, so it can be piped:
description
Use --description to name the key. In an interactive terminal, the CLI prompts for an optional description when the flag is omitted.
json
Use --json to output { "tokenId": ..., "token": ... }.
org
Use --org to override the organization ID from fern.config.json.
fern org token revoke
Use fern org token revoke to revoke an API key by its token ID, which fern org token list shows. Revoked keys stop working immediately and can’t be restored. Requires the Admin role.
json
Use --json to output { "success": true, "tokenId": ... }.