---
source: https://iinventedlight.com/library/notes/bazel-visibility.md
title: "Restrict which packages may depend on a Bazel target"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (Bazel docs); Apache-2.0 (Bazel source); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Bazel docs, Visibility; Bazel source, RuleVisibility.java. Apache-2.0; Apache-2.0."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: Bazel target visibility"
tags: [bazel, visibility, packages, build]
client: Librarian
sources:
  - id: S1
    title: "Visibility"
    publisher: Bazel docs
    url: https://bazel.build/concepts/visibility
    accessed: 2026-11-19
    license: "Apache-2.0"
  - id: S2
    title: "RuleVisibility.java"
    publisher: Bazel source
    url: https://raw.githubusercontent.com/bazelbuild/bazel/master/src/main/java/com/google/devtools/build/lib/packages/RuleVisibility.java
    accessed: 2026-11-19
    license: "Apache-2.0"
---
# Restrict which packages may depend on a Bazel target
**Answer:** Target visibility controls who may depend on your target. The depending target uses your label inside an attribute such as `deps`. In Bazel source, a RuleVisibility specifies which other rules can depend on a specified rule.

## Specifications

All rule targets have a `visibility` attribute that takes a list of labels. Visibility is set by listing the allowed packages. Listing a package does not, by itself, mean its subpackages are also allowed.

During prototyping, target visibility enforcement can be disabled with `--check_visibility=false`. Do not use that flag for production usage in submitted code.

| visibility | labels |
|---|---|
| `//visibility:public` | `//visibility:public` |
| `//visibility:private` | `//visibility:private` |
| `//friend:__pkg__` | `//friend:__pkg__` |
| `//friend:__subpackages__` | `//friend:__subpackages__` |
| `package_group` | `package_group` |

## Location

Two targets in the same location can depend on each other. A target may also grant visibility to another location. Without symbolic macros, location just means package.

`RuleVisibility` returns the list of all labels comprising this visibility. This includes labels that are not loadable, such as `//visibility:public` and `//foo:__pkg__`.

## See also

- [bazel-select](https://iinventedlight.com/library/notes/bazel-select/)
- [bazel-sandboxing](https://iinventedlight.com/library/notes/bazel-sandboxing/)

## Claims

- id: C1
  claim: Target visibility controls who may depend on a target, including via attributes such as deps.
  source: S1
  evidence: "**Target visibility** controls who may depend on your target"

- id: C2
  claim: The visibility attribute is a list of labels, and allowing a package does not automatically allow its subpackages.
  source: S1
  evidence: "Allowing a package does not necessarily mean that"

- id: C3
  claim: In Bazel source, RuleVisibility specifies which other rules can depend on a specified rule.
  source: S2
  evidence: "A RuleVisibility specifies which other rules can depend on a specified rule."

## Sources

- [S1] Visibility. Bazel docs. https://bazel.build/concepts/visibility . License: Apache-2.0. Accessed 2026-11-19.

- [S2] RuleVisibility.java. Bazel source. https://raw.githubusercontent.com/bazelbuild/bazel/master/src/main/java/com/google/devtools/build/lib/packages/RuleVisibility.java . License: Apache-2.0. Accessed 2026-11-19.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Bazel docs, Visibility; Bazel source, RuleVisibility.java. Apache-2.0; Apache-2.0. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
