# Optimize Bazel Builds for Large Monorepos

Large Bazel repositories often suffer from slow, inconsistent builds. This skill guides profiling, caching, remote execution, rules, and configuration improvements.

## Install

```bash
npx skillstore add sickn33/bazel-build-optimization
```

## Metadata

- Status: approved
- Slug: sickn33-bazel-build-optimization
- Skillstore revision: r2
- Version status: missing
- Tree hash: 6e4b70c7e4730f2ac9940c1b7012eb0a646eb3f2736bf693e36e6541950aa73b
- Author: sickn33
- GitHub username: sickn33
- License: MIT
- Repository: https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/bazel-build-optimization
- Ref: 5a26d1d61d694db29af9b138c661c1981076d9df
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands, network, filesystem
- Quality score: 70
- Public page: https://skillstore.pages.dev/skills/sickn33-bazel-build-optimization
- Manifest: https://skillstore.pages.dev/api/skills/sickn33-bazel-build-optimization/manifest

## Capabilities

- Explains Bazel workspace, package, target, label, rule, and aspect concepts.
- Provides configuration patterns for local caching, remote caching, remote execution, CI, testing, and coverage.
- Drafts BUILD targets for TypeScript and Python libraries, tests, and binaries.
- Shows dependency queries, reverse dependency analysis, graph generation, and target filtering.
- Guides build profiling with action logs, memory profiles, and Bazel profile analysis.
- Provides a Starlark pattern for implementing a custom Docker image rule.

## Use Cases

- Reduce Developer Build Times: Review profiles and configuration to identify slow actions, improve target granularity, and increase cache reuse.
- Standardize Monorepo Targets: Create consistent TypeScript and Python BUILD patterns with clear dependencies, tests, and visibility.
- Scale Continuous Integration: Plan remote caching, remote execution, build event reporting, and CI-specific Bazel settings.

## Prompt Templates

### Review Basic Configuration

```
Review this Bazel configuration for correctness and simple performance improvements. Explain each recommendation and provide verification steps.
```

### Create Library Targets

```
Design Bazel targets for this library, its tests, and dependencies. Use explicit visibility and explain all repository-specific assumptions.
```

### Diagnose Slow Builds

```
Analyze these Bazel profile results and execution logs. Rank bottlenecks, recommend changes, and define measurements that confirm each improvement.
```

### Design Remote Execution

```
Design a secure remote execution rollout for this monorepo. Cover platforms, toolchains, caching, authentication, immutable images, capacity, observability, and rollback.
```

## Limitations

- Examples contain placeholder checksums, endpoints, project names, and image references that require replacement.
- The skill does not inspect a repository or measure build performance without access to project files and command output.
- Remote cache and execution settings require provider-specific authentication, capacity planning, and security review.
- Some dependency examples use older WORKSPACE patterns and may require migration to current Bazel modules.

## Best Practices

- Measure a stable baseline before changing configuration, target boundaries, or execution strategy.
- Pin dependencies, toolchains, and remote worker images with immutable versions or digests.
- Test changes on representative workloads and compare clean, incremental, local, and remote builds.

## Anti Patterns

- Do not enable high remote concurrency before validating service capacity, quotas, and cost controls.
- Do not copy placeholder endpoints, checksums, labels, or credentials into production configuration.
- Do not optimize only clean builds when developers primarily depend on incremental performance.

## Security Audit

- Audited at: 2026-08-14T10:18:09.157\+00:00
- Summary: All 32 static findings are false positives caused by Markdown formatting, examples, trusted documentation links, cache paths, and a Bazel mnemonic. One medium semantic risk remains: the remote execution template uses a mutable latest container tag, which can change without review.

## Stats

- Views: 109
- Downloads: 11
- Favorites: 0
- Popularity score: 0
