> ## Documentation Index
> Fetch the complete documentation index at: https://site.aspect.build/llms.txt
> Use this file to discover all available pages before exploring further.

# Command-line flags

> Learn how Bazel command-line flags work, including short forms, negation, the bare -- separator, and how .bazelrc files manage flag configuration across builds.

Bazel has hundreds of command-line flags that control build behavior. Even experts regularly discover flags they didn’t know existed.

In this section, you'll learn how to use flags effectively, and how to manage them using `.bazelrc` configuration files.

## Basic flag syntax

Flags are passed to Bazel commands like any command-line program, using double-hyphens such as this:

```bash theme={null}
`bazel build --jobs=10 my_target`
```

To distinguish between flags passed to Bazel itself and arguments passed to a program Bazel runs, or to exclude a target from a target pattern, use a bare -- to separate them:

```bash theme={null}
 bazel run --stamp //my:target -- --some_argument
 bazel build -- //app:all -//app:not-this-one
```

The bare `--` marks the boundary where Bazel stops interpreting flags and treats everything that follows as either program arguments or target patterns.

## Flag syntax shortcuts

### Short form

Some flags have a single-letter short form using a single hyphen:

```bash theme={null}
#Long form
bazel build --compilation_mode opt

#Short form
bazel build -c opt
```

### Flag negation

Boolean flags can be negated by adding `no` as a prefix:

```bash theme={null}
# Enable the flag
bazel build --experimental_merged_skyframe_analysis_execution

# Disable the flag
bazel build --noexperimental_merged_skyframe_analysis_execution
```

## Managing flags with `.bazelrc` files

Flags are stored in Unix-style RC files so you don't have to remember and type them repeatedly.

Storing your flag preferences in .bazelrc files allows you to:

* Set system-wide defaults in `/etc/bazel.bazelrc`.
* Share team configurations in `.bazelrc` at the repository root.
* Define personal preferences in `$HOME/.bazelrc`, these preferences apply to all your Bazel repositories.
* Define personal, project-specific preferences in a user.bazelrc file at the repository root, following [Bazel’s recommended best practices](https://bazel.build/configure/best-practices#bazelrc-file).

### Writing `.bazelrc` files

In `.bazelrc` files, each line begins with a command scope, followed by one or more flags.\
The command scope determines which Bazel commands receive the flag.

```text theme={null}
# applies only to `bazel build`
build --some_build_flag=1

# applies only to `bazel test`
test --some_test_flag=on
```

**Applying flags to all commands**

Use `common` to apply a flag to all commands that support it:

```text theme={null}
# applies to any command (use Bazel 6.4 or greater)
common --other_flag=yes
```

**Grouping flags with --config**

Flags can be grouped into named configurations and enabled using the --config flag:

```text theme={null}
# Create named configs
# applies only when --config=ci is set
common:ci --this_flag=only-on-CI
```

### Organizing `.bazelrc` files as projects grow

In a real project, flags get hard to organize, so we recommend that the `.bazelrc` file in your project imports from several rc files for convenience. Learn more [bazelrc-preset](https://github.com/bazel-contrib/bazelrc-preset.bzl).

A newly created project includes that preset at the start of the file:

```python theme={null}

import %workspace%/tools/preset.bazelrc

# ... Project Specific flags override presets

# ... finally the user can override anything above
try-import %workspace%/user.bazelrc
```

<Tip> The [Bazel flag registry,](https://registry.build/flag/bazel/) provides a nice interface for browsing flags, or sending a permalink to your coworker pointing them to a flag.</Tip>
