> ## Documentation Index
> Fetch the complete documentation index at: https://bazel-codex-issue-374-local-flag-cheatsheet.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Bazel flag cheat sheet

Navigating Bazel's extensive list of command line flags can be a challenge.
This page focuses on the most crucial flags you'll need to know.

<aside class="tip">
  <b>Tip:</b> Select a flag name below to navigate to its entry in the
  command line reference.
</aside>

<h2 id="useful-command">
  Useful general options
</h2>

The following flags are meant to be set explicitly on the command line.

<a id="flag-config" />

<ResponseField name="--config">
  [See --config in the command-line reference](https://bazel.build/reference/command-line-reference#flag--config)

  You can organize flags in a <strong>.bazelrc</strong> file into configurations,
  like ones for debugging or release builds. Additional configuration groups can
  be selected with <code>--config=<strong>\<group></strong></code>.
</ResponseField>

<a id="flag-keep-going" />

<ResponseField name="--keep_going">
  [See --keep\_going in the command-line reference](https://bazel.build/reference/command-line-reference#flag--keep_going)

  Bazel should try as much as possible to continue with build and test execution.
  By default, Bazel fails eagerly.
</ResponseField>

<a id="flag-remote-download-outputs" />

<ResponseField name="--remote_download_outputs">
  [See --remote\_download\_outputs in the command-line reference](https://bazel.build/reference/command-line-reference#flag--remote_download_outputs)

  When using remote execution or caching (both disk and remote), you can signal to
  Bazel that you
  want to download <strong>all</strong> (intermediate) build artifacts as follows:

  <pre class="prettyprint lang-sh">
    \--remote\_download\_outputs=<strong>all</strong>
  </pre>

  By default, Bazel only downloads top-level artifacts, such as the final binary,
  and intermediate artifacts that are necessary for local actions.
</ResponseField>

<a id="flag-stamp" />

<ResponseField name="--stamp">
  [See --stamp in the command-line reference](https://bazel.build/reference/command-line-reference#flag--stamp)

  Adds build info (user, timestamp) to binaries.

  <aside class="note">
    <b>Note:</b> Because this increases build time, it's only intended for release
    builds.
  </aside>
</ResponseField>

<h2 id="uncover-build">
  Uncover Build & Test Issues
</h2>

The following flags can help you better understand Bazel build or test errors.

<a id="flag-announce-rc" />

<ResponseField name="--announce_rc">
  [See --announce\_rc in the command-line reference](https://bazel.build/reference/command-line-reference#flag--announce_rc)

  Shows which flags are implicitly set through user-defined,
  machine-defined, or project-defined <strong>.bazelrc</strong> files.
</ResponseField>

<a id="flag-auto-output-filter" />

<ResponseField name="--auto_output_filter">
  [See --auto\_output\_filter in the command-line reference](https://bazel.build/reference/command-line-reference#flag--auto_output_filter)

  By default, Bazel tries to prevent log spam and does only print compiler
  warnings and Starlark debug output for packages and subpackages requested on the
  command line. To disable all filtering, set
  <code>--auto\_output\_filter=<strong>none</strong></code>.
</ResponseField>

<a id="flag-sandbox-debug" />

<ResponseField name="--sandbox_debug">
  [See --sandbox\_debug in the command-line reference](https://bazel.build/reference/command-line-reference#flag--sandbox_debug)

  Lets you drill into sandboxing errors. For details on why Bazel sandboxes
  builds by default and what gets sandboxed, see our
  <a href="https://bazel.build/docs/sandboxing">sandboxing documentation</a>.

  <aside class="tip">
    <b>Tip:</b> If you think the error might be caused by sandboxing,
    try turning sandboxing off temporarily.

    <p>To do this, add <code>--spawn\_strategy=<strong>local</strong></code>
    to your command.</p>
  </aside>
</ResponseField>

<a id="flag-subcommands" />

<ResponseField name="--subcommands (-s)">
  [See --subcommands (-s) in the command-line reference](https://bazel.build/reference/command-line-reference#flag--subcommands)

  Displays a comprehensive list of every command that Bazel runs during a build,
  regardless of whether it succeeds or fails
</ResponseField>

<h2 id="startup">
  Startup
</h2>

Caution: Startup flags need to be passed before the command and cause
a server restart. Toggle these flags with caution.

<a id="flag-bazelrc" />

<ResponseField name="--bazelrc">
  [See --bazelrc in the command-line reference](https://bazel.build/reference/command-line-reference#flag--bazelrc)

  You can specify default Bazel options in <strong>.bazelrc</strong> files. If
  multiple <strong>.bazelrc</strong> files exist, you can select which
  <strong>.bazelrc</strong> file is used by adding <code>--bazelrc=<strong>\<path to
  the .bazelrc file></strong></code>.

  <aside class="tip">
    <b>Tip:</b> <code>--bazelrc=<strong>dev/null</strong></code> disables the
    search for <strong>.bazelrc</strong> files.

    <p>This is ideal for scenarios where you want to ensure a clean build
    environment, such as release builds, and prevent any unintended configuration
    changes from <strong>.bazelrc</strong> files</p>
  </aside>
</ResponseField>

<a id="flag-host-jvm-args" />

<ResponseField name="--host_jvm_args">
  [See --host\_jvm\_args in the command-line reference](https://bazel.build/docs/user-manual#host-jvm-args)

  Limits the amount of RAM the Bazel server uses.

  For example, the following limits the Bazel heap size to <strong>3</strong>GB:

  <pre class="prettyprint lang-sh">
    \--host\_jvm\_args=<strong>-Xmx3g</strong>
  </pre>

  <aside class="note">
    <b>Note:</b> <code>-Xmx</code> is used to set the maximum heap size for the
    Java Virtual Machine (JVM). The heap is the area of memory where objects are
    allocated. The correct format for this option is <code>-Xmx\<size></code>
    , where <code>\<size></code> is the maximum heap size, specified with a
    unit such as:

    <ul>
      <li>m for megabytes</li>
      <li>g for gigabytes</li>
      <li>k for kilobytes</li>
    </ul>
  </aside>
</ResponseField>

<a id="flag-output-base" />

<ResponseField name="--output_base">
  [See --output\_base in the command-line reference](https://bazel.build/reference/command-line-reference#flag--output_base)

  Controls Bazel's output tree. Bazel doesn't store build outputs, including logs,
  within the source tree itself. Instead, it uses a distinct output tree for this
  purpose.

  <aside class="tip">
    <b>Tip:</b> Using multiple output bases in one Bazel workspace lets you run
    multiple Bazel servers concurrently. This can be useful when trying to avoid
    analysis thrashing. For more information,
    see <a href="https://bazel.build/run/scripts#output-base-option">Choosing the output base</a>.
  </aside>
</ResponseField>

<h2 id="bazel-tests">
  Bazel tests
</h2>

The following flags are related to Bazel test

<a id="flag-java-debug" />

<ResponseField name="--java_debug">
  [See --java\_debug in the command-line reference](https://bazel.build/reference/command-line-reference#flag--java_debug)

  Causes Java tests to wait for a debugger connection before being executed.
</ResponseField>

<a id="flag-runs-per-test" />

<ResponseField name="--runs_per_test">
  [See --runs\_per\_test in the command-line reference](https://bazel.build/reference/command-line-reference#flag--runs_per_test)

  The number of times to run tests. For example, to run tests N times, add
  <code>--runs\_per\_test=<strong>N</strong></code>. This can be useful to debug
  flaky tests and see whether a fix causes a test to pass consistently.
</ResponseField>

<a id="flag-test-filter" />

<ResponseField name="--test_filter">
  [See --test\_filter in the command-line reference](https://bazel.build/reference/command-line-reference#flag--test_filter)

  This flag is particularly useful when iterating on a single test method, such as
  when a change you made breaks a test. Instead of re-running
  all the test methods in the test suite, you can focus solely on the specific
  test(s) that failed. This allows for faster feedback and more efficient
  debugging. This flag is often used in conjunction with
  <code>--test\_output=<strong>streamed</strong></code> for real-time test output.
</ResponseField>

<a id="flag-test-output" />

<ResponseField name="--test_output">
  [See --test\_output in the command-line reference](https://bazel.build/reference/command-line-reference#flag--test_output)

  Specifies the output mode. By default, Bazel captures test output in
  local log files. When iterating on a broken test, you typically want to use
  <code>--test\_output=<strong>streamed</strong></code> to see the test output in
  real time.
</ResponseField>

<h2 id="bazel-run">
  Bazel run
</h2>

The following flags are related to Bazel run.

<a id="flag-run-under" />

<ResponseField name="--run_under">
  [See --run\_under in the command-line reference](https://bazel.build/reference/command-line-reference#flag--run_under)

  Changes how executables are invoked. For example <code>--run\_under=<strong>"strace -c"</strong></code> is
  commonly used for debugging.
</ResponseField>

<h2 id="user-specific-bazelrc">
  User-specific bazelrc options
</h2>

The following flags are related to user-specific **.bazelrc**
options.

<a id="flag-disk-cache" />

<ResponseField name="--disk_cache">
  [See --disk\_cache in the command-line reference](https://bazel.build/reference/command-line-reference#flag--disk_cache)

  A path to a directory where Bazel can read and write actions and action outputs.
  If the directory doesn't exist, it will be created.

  You can share build artifacts between multiple branches or workspaces and speed
  up Bazel builds by adding
  <code>--disk\_cache=<strong>\<path></strong></code> to your command.
</ResponseField>

<a id="flag-jobs" />

<ResponseField name="--jobs">
  [See --jobs in the command-line reference](https://bazel.build/reference/command-line-reference#flag--jobs)

  The number of concurrent jobs to run.

  This is typically only required when using remote execution where a remote build
  cluster executes more jobs than you have cores locally.
</ResponseField>

<a id="flag-local-resources" />

<ResponseField name="--local_resources">
  [See --local\_resources in the command-line reference](https://bazel.build/reference/command-line-reference#flag--local_resources)

  Limits how much CPU or RAM is consumed by locally running actions.

  <aside class="note">
    <b>Note:</b> This has no impact on the amount of CPU or RAM that the Bazel
    server itself consumes for tasks like analysis and build orchestration.
  </aside>
</ResponseField>

<a id="flag-sandbox-base" />

<ResponseField name="--sandbox_base">
  [See --sandbox\_base in the command-line reference](https://bazel.build/reference/command-line-reference#flag--sandbox_base)

  Lets the sandbox create its sandbox directories underneath this path. By
  default, Bazel executes local actions sandboxed which adds some overhead to the
  build.

  <aside class="tip">
    <b>Tip:</b> Specify a path on tmpfs, for example <code>/run/shm</code>, to
    possibly improve performance a lot when your build or tests have many input
    files.
  </aside>
</ResponseField>

<h2 id="project-specific-bazelrc">
  Project-specific bazelrc options
</h2>

The following flags are related to project-specific <strong>.bazelrc</strong>
options.

<a id="flag-flaky-test-attempts" />

<ResponseField name="--flaky_test_attempts">
  [See --flaky\_test\_attempts in the command-line reference](https://bazel.build/reference/command-line-reference#flag--flaky_test_attempts)

  Retry each test up to the specified number of times in case of any
  test failure. This is especially useful on Continuous Integration. Tests that
  require more than one attempt to pass are marked as <strong>FLAKY</strong> in
  the test summary.
</ResponseField>

<a id="flag-remote-cache" />

<ResponseField name="--remote_cache">
  [See --remote\_cache in the command-line reference](https://bazel.build/reference/command-line-reference#flag--remote_cache)

  A URI of a caching endpoint. Setting up remote caching can be a great way to
  speed up Bazel builds. It can be combined with a local disk cache.
</ResponseField>

<a id="flag-remote-download-regex" />

<ResponseField name="--remote_download_regex">
  [See --remote\_download\_regex in the command-line reference](https://bazel.build/reference/command-line-reference#flag--remote_download_regex)

  Force remote build outputs whose path matches this pattern to be downloaded,
  irrespective of the <code>--remote\_download\_outputs</code> setting. Multiple
  patterns may be specified by repeating this flag.
</ResponseField>

<a id="flag-remote-executor" />

<ResponseField name="--remote_executor">
  [See --remote\_executor in the command-line reference](https://bazel.build/reference/command-line-reference#flag--remote_executor)

  <code>HOST</code> or <code>HOST:PORT</code> of a remote execution endpoint. Pass this if you are using
  a remote execution service. You'll often need to Add
  <code>--remote\_instance\_name=<strong>\<name></strong></code>.
</ResponseField>

<a id="flag-remote-instance-name" />

<ResponseField name="--remote_instance_name">
  [See --remote\_instance\_name in the command-line reference](https://bazel.build/reference/command-line-reference#flag--remote_instance_name)

  The value to pass as <code>instance\_name</code> in the remote execution API.
</ResponseField>

<a id="flag-show-timestamps" />

<ResponseField name="--show_timestamps">
  [See --show\_timestamps in the command-line reference](https://bazel.build/docs/user-manual#show-timestamps)

  If specified, a timestamp is added to each message generated by Bazel specifying
  the time at which the message was displayed. This is useful on CI systems to
  quickly understand what step took how long.
</ResponseField>

<a id="flag-spawn-strategy" />

<ResponseField name="--spawn_strategy">
  [See --spawn\_strategy in the command-line reference](https://bazel.build/reference/command-line-reference#flag--spawn_strategy)

  Even with remote execution, running some build actions locally might be faster.
  This depends on factors like your build cluster's capacity, network speed, and
  network delays.

  <aside class="tip">
    <b>Tip:</b> To run actions both locally and remotely and accept
    the faster result add <code>--spawn\_strategy=<strong>dynamic</strong></code>
    to your build command.
  </aside>
</ResponseField>
