> For the complete documentation index, see [llms.txt](https://docs.reflag.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.reflag.com/guides/use-reflag-in-your-cli.md).

# Use Reflag in your CLI

High-level guide to flagging features in your CLI

### If you use API token for auth

First, create an endpoint in your backend for the CLI to call:

```
POST /get-flags
Authorization: Bearer <APIKEY>
```

The endpoint will take the API key and use it to look up the associated user.

Then, use the [API Reference](/api/public-api/public-api-reference.md) to get enabled flags for the authenticated user. Return the flags to the CLI:

```
{
  flags: ['flag1', 'flag2']
}
```

Finally, check for access with a simple:

```tsx
/function isFlagEnabled(flag: string) {
    return flags.contains('myflag');
}
```

### If you use API token for auth AND Node.js

First, create an endpoint in your backend for the CLI to call:

```
POST /get-flags
Authorization: Bearer <APIKEY>
```

The endpoint will take the API key and use it to look up the associated user.

Use the [Node.js SDK](/supported-languages/node-sdk.md) get enabled flags for the authenticated user.

```jsx
import { ReflagClient } from "@reflag/node-sdk";

// configure the client
const boundClient = reflagClient.bindClient({
  user: {
    id: "c1_u1",
    name: "John Doe"
  },
  company: {
    id: "c1",
    name: "Acme, Inc."
  },
});

// get flags
const flags = boundClient.getFlags();
```

Finally, check for access with a simple:

```tsx
if(flags['myflag'].isEnabled) {
    //feature access
}
```

### If you use OAuth for auth

Use [Node.js SDK](/supported-languages/node-sdk.md) or [API Reference](/api/public-api/public-api-reference.md) to get flags for the authenticated user.

In Node, configure the SDK like so:

```jsx
import { ReflagClient } from "@reflag/node-sdk";

// configure the client
const boundClient = reflagClient.bindClient({
  user: {
    id: "c1_u1",
    name: "John Doe"
  },
  company: {
    id: "c1",
    name: "Acme, Inc."
  },
});
```

Check access for individual flag:

```jsx
const { isEnabled } = boundClient.getFlag("myflag");

if (isEnabled) {
    //feature access
}    
```

Or get all flags:

```jsx
const flags = boundClient.getFlags();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.reflag.com/guides/use-reflag-in-your-cli.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
