Skip to content

feat: add opt-in cache_claude_code input to reuse the Claude Code binary across runs - #1939

Open
dolphin9712 wants to merge 1 commit into
anthropics:mainfrom
dolphin9712:feat/cache-claude-code
Open

dolphin9712 wants to merge 1 commit into
anthropics:mainfrom
dolphin9712:feat/cache-claude-code

Conversation

@dolphin9712

Copy link
Copy Markdown

Problem

Every run downloads the Claude Code native binary (~280 MB) with install.sh. On our 1-core self-hosted runners this took 15–25 s per run (up to ~47 s), before Claude starts. The only way to skip it today is path_to_claude_code_executable, which needs a custom runner image.

Change

New opt-in input cache_claude_code (default "false"):

  1. Read the pinned version from src/entrypoints/run.ts, so a version bump changes the cache key with no extra edit (a test fails if that line's format changes).
  2. actions/cache/restore the binary at ~/.local/share/claude/versions/<version>.
  3. Use it only if its SHA-256 matches the release manifest (same check as install.sh, including musl detection) and claude --version reports the pinned version. Otherwise discard it and install as usual.
  4. Pass it to run.ts through PATH_TO_CLAUDE_CODE_EXECUTABLE as a fallback; a user-provided path_to_claude_code_executable still wins.
  5. actions/cache/save only on a cache miss.

Restore and save are separate steps and an existing key is never saved again, which avoids the duplicate-save 409 retries that led to disabling setup-bun's cache (#1259, #1580). Every cache step is continue-on-error, so a cache problem falls back to the normal install.

Testing

  • test/claude-code-cache.test.ts runs the step scripts from action.yml with the same bash flags as a composite step: version lookup, a matching binary, checksum mismatch, version mismatch and an unreachable manifest.
  • bun test, bun run typecheck and bun run format:check pass.
  • The same restore/verify/save flow, run on self-hosted 1-core runners: install 15.8–25 s → restore 4–5 s. A checksum mismatch fell back to install.sh as expected.

…ary across runs

Restore the binary that install.sh would download with actions/cache/restore,
use it only if it matches the release manifest checksum and the pinned version,
and save it with actions/cache/save only on a cache miss.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant