/buildkite:buildkite-cachefrom buildkite
Configures Buildkite Cache for file-based dependency caching between builds, covering .buildkite/cache.yml format, cache keys, fallbacks, and buildkite-agent cache save/restore commands.
Ships in buildkite. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Buildkite Cache is file-based caching built into the agent: buildkite-agent cache save and buildkite-agent cache restore archive and restore directories between builds, keyed by a structured cache key defined in .buildkite/cache.yml. This skill covers the configuration format, cache key and fallback semantics, the CLI commands, and storage setup.
Preview feature. Buildkite Cache is in preview and subject to change. On Buildkite hosted agents it works with zero storage configuration. For self-hosted agents the feature is opt-in — contact Buildkite support to enable it for the organization, and provide a cache store (see Storage below).
For the
cacheBuildkite plugin, the pipeline-levelcache:key, and hosted agent cache volumes, see the buildkite-pipelines skill. Those are separate caching mechanisms; Buildkite Cache does not read the pipelinecache:attribute.
Define caches in .buildkite/cache.yml at the repository root:
caches:
- name: node
cache_key:
- node
- { agent: os }
- { agent: arch, fallback_limit: true }
- { checksum: package-lock.json }
target_paths:
- ~/.npm
Call the commands inside a job step — nothing runs automatically:
steps:
- label: ":nodejs: Test"
command: |
buildkite-agent cache restore
npm ci
buildkite-agent cache save
npm test
The cache holds npm's download cache (~/.npm), not node_modules — npm ci deletes node_modules before installing, so caching it directly is wasted work. The ~/.npm path is POSIX-only: on Windows agents npm caches to %LocalAppData%\npm-cache, so ~/.npm never exists and save fails — set npm_config_cache to a fixed path and cache that path instead. On the first build, restore reports a miss, npm ci downloads everything, and save uploads the populated ~/.npm. On later builds with an unchanged lockfile, restore is an exact hit and npm ci installs from the local cache without re-downloading. When the lockfile changes, the fallback_limit on arch lets restore fall back to the newest node + os + arch cache, so only new or changed packages are downloaded — then save uploads a fresh entry under the new checksum. The same principle applies to any tool that rebuilds its target from scratch: cache the tool's download or package cache, and cache an install directory like node_modules only when the install step preserves it.
Run cache save immediately after the step that produces the cached paths. Save checks for an existing entry first and skips the upload when the key already exists, so calling it on every build is cheap.
The commands read .buildkite/cache.yml or .buildkite/cache.yaml (exactly one must exist — two is an error), or an explicit path from --cache-config-file / BUILDKITE_CACHE_CONFIG_FILE.
Each entry under caches: defines one named cache:
| Field | Required | Constraints |
|---|---|---|
name | yes | Letters, numbers, and underscores only (^[a-zA-Z0-9_]+$) |
cache_key | yes | Ordered, non-empty list of key parts; at most one part may set fallback_limit: true |
target_paths | yes | Non-empty set of files or directories to cache; order-insensitive, no duplicates; must not be ~, ., or / themselves |
cache_key is an ordered list. Each part is one of:
| Part | Resolves to |
|---|---|
some-literal | The literal string itself — use for a version prefix like v1 |
{ agent: os } | Agent operating system (linux, darwin, windows) |
{ agent: arch } | Agent CPU architecture (amd64, arm64) |
{ agent: branch } | BUILDKITE_BRANCH |
{ agent: pipeline } | BUILDKITE_PIPELINE_SLUG |
{ agent: step } | BUILDKITE_STEP_KEY (falls back to BUILDKITE_STEP_ID) |
{ env: SOME_VAR } | Value of the environment variable; missing resolves to empty string |
{ checksum: package-lock.json } | SHA-256 over the matched file contents |
{ checksum: [go.sum, "**/go.mod"] } | One combined SHA-256 over all files matched by the paths and globs |
Checksum paths are resolved relative to the working directory and support *, **, and ? globs. All matched files are deduplicated, sorted, and hashed into a single digest, so the part changes when any matched file changes. A literal (non-glob) path must exist and be a regular file; a checksum whose patterns match no files at all is an error.
Include { agent: os } and { agent: arch } in any cache holding compiled or platform-specific content (native node modules, Go build caches, gems with extensions). Omit them only for caches that are genuinely platform-independent.
target_paths may be relative to the working directory, absolute, or ~-prefixed (home directory). Archives store paths relative to portable anchors, so a cache saved under one checkout directory or home directory restores correctly under another. At save time every target path must exist. At restore time each target path is deleted and replaced by the cached content — never point target_paths at a directory containing uncached work.
A cache entry is addressed by its target_paths set plus the resolved cache_key values, scoped to the registry. Registry policies can add further scopes (branch, build, or pipeline) to an entry's address and control which scope candidates restore considers — so identical paths and key values can intentionally miss across branches or pipelines under a scoped policy. Restore looks up entries in two stages:
fallback_limit: true. Every part up to and including the marked part stays mandatory; every part after it becomes optional. The newest entry matching the mandatory prefix is restored. Reported as fallback used.With no fallback_limit, every part is mandatory and only exact matches restore. Restore reports one of three outcomes per cache: hit, fallback used, or miss. A miss is not an error and does not fail the build.
Place the volatile part (usually the checksum) last, after the fallback_limit marker:
cache_key:
- v1 # bump to invalidate all previous entries
- { agent: os }
- { agent: arch, fallback_limit: true }
- { checksum: Gemfile.lock }
This restores an exact match when the lockfile is unchanged, and otherwise the newest v1 + os + arch entry as a warm starting point. Because save skips existing entries, the entry saved under an unchanged key stays as-is; a changed checksum produces a new entry.
To invalidate caches after a toolchain change that the checksum does not capture, bump a literal version part (v1 → v2). Old entries expire automatically after a few days without exact-match restores.
Both commands process every cache defined in the config file by default, in parallel, and print a collapsed --- :package: group in the job log.
# Restore all caches defined in .buildkite/cache.yml
buildkite-agent cache restore
# Save only specific caches
buildkite-agent cache save --name node --name gems
Shared flags:
| Flag | Default | Environment variable | Description |
|---|---|---|---|
--name | all caches | BUILDKITE_CACHE_NAMES | Cache name to process; repeatable |
--registry | ~ | BUILDKITE_AGENT_CACHE_REGISTRY | Cache registry slug; ~ selects the cluster's default registry |
--cache-store-url | — | BUILDKITE_AGENT_CACHE_STORE_URL | Blob store URL, e.g. s3://my-cache-bucket |
--cache-config-file | .buildkite/cache.yml or .buildkite/cache.yaml | BUILDKITE_CACHE_CONFIG_FILE | Path to the cache configuration file |
--concurrency | 2 | BUILDKITE_CACHE_CONCURRENCY | Number of caches processed in parallel; currently applies only to save — restore ignores it and uses one worker per CPU |
Behavioral guarantees to rely on:
Because nothing invokes these commands automatically, the standard placements are inline in the command step (as in Quick Start) or in repository pre-command / pre-exit hooks for pipelines with many steps sharing the same caches. A pre-exit hook also runs after failed steps, and because save skips existing entries, saving a partially built path can poison the key until it expires — guard hook saves with the command's exit status:
#!/bin/bash
# .buildkite/hooks/pre-exit
if [ "${BUILDKITE_COMMAND_EXIT_STATUS:-1}" -eq 0 ]; then
buildkite-agent cache save
fi
Cache entry metadata lives in a cache registry in Buildkite; the archived bytes live in a cache store. Registries are scoped to a cluster, and the default registry slug ~ resolves to the cluster's default registry — most setups never need --registry.
Hosted agents: zero configuration. The registry and cache store are provided; buildkite-agent cache save/restore work out of the box.
Self-hosted agents: after Buildkite support enables the feature, provide a store with BUILDKITE_AGENT_CACHE_STORE_URL (typically as an agent environment variable or in an environment hook):
#!/bin/bash
# .buildkite/hooks/environment (or agent-level environment configuration)
export BUILDKITE_AGENT_CACHE_STORE_URL="s3://my-cache-bucket/buildkite?region=us-east-1"
Uploads and downloads go directly between the agent and the bucket using ambient credentials (the AWS default credential chain — instance profile, IRSA, or environment variables). Buildkite never receives the cached bytes and issues no storage credentials. Grant agents s3:GetObject and s3:PutObject on the bucket (these also authorize the self-copy the agent performs to refresh object timestamps). file:///some/path URLs work for local testing. Blob lifecycle in the bucket is the operator's responsibility — add an S3 lifecycle rule keyed on last-modified time. The agent refreshes last-modified on restore to keep hot blobs alive, but the refresh is best-effort: failures are ignored and objects over S3's 5 GB CopyObject limit cannot be refreshed, so a lifecycle rule can still expire a regularly restored large cache. Size lifecycle windows generously.
Registries carry save and restore policies controlling which jobs may write or read entries — for example, restricting saves to default-branch builds while allowing restores from any branch. Policies can also scope entries by branch, build, or pipeline, adding those dimensions to the entry address, so a scoped registry can intentionally miss on identical paths and keys saved from a different branch or pipeline. Policies are configured on the registry in Buildkite, not in .buildkite/cache.yml. Entries expire automatically after a few days without an exact-match restore; exact-match restores refresh the expiry.
| Mistake | What happens | Fix |
|---|---|---|
Cache name with hyphens (node-modules) | Validation error — names allow only letters, numbers, and underscores | Use node_modules or node |
Both .buildkite/cache.yml and .buildkite/cache.yaml exist | Error: "found multiple cache configuration files" | Keep exactly one |
Running cache save before the target path exists | Save fails — every target_paths entry must exist at save time | Run save after the install/build step that creates the path |
Expecting cache save to update an existing entry | Save skips silently ("Cache already exists"); stale content persists | Make content changes flow into the key via a checksum part, or bump a literal version part |
Expecting the pipeline-level cache: key or cache plugin to drive these commands | Nothing happens — they are separate systems; the commands read only .buildkite/cache.yml | Define caches in .buildkite/cache.yml and invoke buildkite-agent cache restore/save explicitly |
No fallback_limit on any key part | Any lockfile change is a total miss and a full cold install | Set fallback_limit: true on the last stable part (usually arch) so the checksum becomes optional for fallback |
| Failing the step when restore reports a miss | Builds break on cold caches, which are normal | Treat a miss as a slow path, never an error; write steps to work from empty |
Caching platform-specific content without { agent: os }/{ agent: arch } in the key | A cache saved on linux/amd64 restores onto darwin/arm64 and breaks the build | Include os and arch parts for any compiled or native content |
references/configuration-reference.md — Complete key-part semantics, checksum globbing rules, store URL options (S3 query parameters), environment variables, and save/restore lifecycle detailsexamples/cache.yml — Multi-language cache configuration (Node.js, Ruby, Go) with fallbacksWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
7 skills in this plugin
/buildkite-agent-runtimeThis skill should be used when the user asks to "add an annotation", "upload artifacts from a step", "share data between steps", "upload pipeline dynamically", "request an OIDC token inside a step", "acquire a distributed lock", "get or update a step attribute", "redact a secret from logs", "retrieve a cluster secret at runtime", or "debug environment variables in hooks". Also use when the user mentions buildkite-agent annotate, buildkite-agent artifact upload/download, buildkite-agent meta-data set/get, buildkite-agent pipeline upload, buildkite-agent oidc request-token, buildkite-agent step, buildkite-agent lock, buildkite-agent env, buildkite-agent secret get, buildkite-agent redactor add, buildkite-agent tool sign/keygen, buildkite:webhook, raw webhook payloads, or any buildkite-agent subcommand used inside a running job step.
/buildkite-apiThis skill should be used when the user asks to "call the Buildkite API", "use the REST API", "write a GraphQL query", "set up webhooks", "automate Buildkite", "integrate with Buildkite programmatically", "write a script that calls Buildkite", "handle webhook events", "paginate API results", or "authenticate with the Buildkite API". Also use when the user mentions api.buildkite.com, graphql.buildkite.com, Buildkite REST endpoints, GraphQL mutations, webhook payloads, API tokens, or asks about programmatic access to Buildkite data.
/buildkite-cliThis skill should be used when the user asks to "trigger a build", "check build status", "watch a build", "view build logs", "rebuild a build", "cancel a build", "list builds", "list jobs", "unblock a job", "download artifacts", "manage secrets", "create a pipeline", "list pipelines", "review my Buildkite environment", "find unnecessary builds", "review retry effectiveness", "optimize Buildkite workflows", "validate a pipeline", "copy a pipeline", "run a local agent", or "interact with Buildkite from the command line". Also use when the user mentions bk commands, bk build, bk job, bk pipeline, bk secret, bk artifacts, bk cluster, bk queue, bk package, bk agent, bk auth, bk config, bk use, bk browse, bk api, bk skill, or asks about Buildkite CLI installation, authentication, terminal-based Buildkite workflows, or command-line CI/CD operations.
/buildkite-migrationThis skill should be used when the user asks to "migrate to Buildkite", "convert pipelines from Jenkins", "convert GitHub Actions workflows", "convert CircleCI config", "convert Bitbucket Pipelines", "convert GitLab CI", "migrate CI/CD to Buildkite", "switch from Jenkins to Buildkite", "move from GitHub Actions", "plan a CI migration", "convert my CI config", "bk pipeline convert", or "what's the Buildkite equivalent of". Also use when the user mentions migration planning, CI conversion, pipeline conversion, converting workflows, or asks about translating CI/CD configuration from another provider to Buildkite.
/buildkite-pipelinesThis skill should be used when the user asks to "write a pipeline", "add caching", "make this build faster", "show test failures in the build page", "add annotations", "only run tests when code changes", "set up dynamic pipelines", "add retry", "parallel steps", "matrix build", "add plugins", or "work with artifacts in pipeline YAML". Also use when the user mentions .buildkite/ directory, pipeline.yml, buildkite-agent pipeline upload, step types (command, wait, block, trigger, group, input), if_changed, notify, concurrency, dynamic pipeline quotas, pipeline upload limits, or asks about Buildkite CI configuration.
/buildkite-preflightRuns Buildkite CI builds against changes in the local working tree. Use when asked to run preflight or run CI.Other plugins' skills for the same job
npx claudepluginhub buildkite/skills --plugin buildkite