name: CLI Version Check
on:
schedule:
- cron: '0 0 * * 1' workflow_dispatch:
concurrency:
group: cli-version-check
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
jobs:
detect-version:
name: Detect CLI version change
runs-on: ubuntu-latest
outputs:
version_changed: ${{ steps.compare.outputs.changed }}
new_version: ${{ steps.compare.outputs.new_version }}
old_version: ${{ steps.compare.outputs.old_version }}
steps:
- uses: actions/checkout@v6
with:
ref: develop
- name: Get latest CLI version from npm
id: npm
run: |
NEW_VERSION=$(npm view @anthropic-ai/claude-code version)
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
- name: Compare versions
id: compare
run: |
OLD_VERSION=$(cat .claude-cli-version)
NEW_VERSION="${{ steps.npm.outputs.version }}"
if [ "$OLD_VERSION" = "$NEW_VERSION" ]; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
echo "old_version=$OLD_VERSION" >> "$GITHUB_OUTPUT"
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
run-tests:
name: Run tests against new CLI version
needs: detect-version
if: needs.detect-version.outputs.version_changed == 'true'
runs-on: ubuntu-latest
outputs:
tests_failed: ${{ steps.test-result.outputs.failed }}
test_log: ${{ steps.test-result.outputs.log }}
steps:
- uses: actions/checkout@v6
with:
ref: develop
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- name: Install new CLI version
run: npm install -g @anthropic-ai/claude-code@${{ needs.detect-version.outputs.new_version }}
- name: Run tests, clippy, and E2E tests
id: test-result
env:
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
run: |
LOG_FILE=$(mktemp)
FAILED=false
echo "=== cargo test ===" >> "$LOG_FILE"
if ! cargo test 2>&1 | tee -a "$LOG_FILE"; then
FAILED=true
fi
echo "" >> "$LOG_FILE"
echo "=== cargo clippy ===" >> "$LOG_FILE"
if ! cargo clippy -- -D warnings 2>&1 | tee -a "$LOG_FILE"; then
FAILED=true
fi
echo "" >> "$LOG_FILE"
echo "=== cargo test (E2E) ===" >> "$LOG_FILE"
if ! cargo test -- --ignored 2>&1 | tee -a "$LOG_FILE"; then
FAILED=true
fi
echo "failed=$FAILED" >> "$GITHUB_OUTPUT"
# Truncate log to fit in output (max ~1MB)
LOG=$(head -c 500000 "$LOG_FILE")
{
echo "log<<TESTLOG_EOF"
echo "$LOG"
echo "TESTLOG_EOF"
} >> "$GITHUB_OUTPUT"
fix-tests:
name: Create test fix PR
needs: [detect-version, run-tests]
if: needs.run-tests.outputs.tests_failed == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v6
with:
ref: develop
- uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
prompt: |
Claude CLI has been upgraded from ${{ needs.detect-version.outputs.old_version }} to ${{ needs.detect-version.outputs.new_version }}.
The test suite failed. Here are the logs:
```
${{ needs.run-tests.outputs.test_log }}
```
Your task:
1. Read docs/claude-cli.md for the "Updating for New CLI Versions" checklist
2. Analyze the test failures and fix the code
3. Run `cargo test` and `cargo clippy -- -D warnings` to verify fixes
4. Create a PR targeting `develop` from branch `cli-upgrade/${{ needs.detect-version.outputs.new_version }}/test-fix`
PR title: "fix: resolve test failures for CLI v${{ needs.detect-version.outputs.new_version }}"
Reference issue #7 in the PR body.
claude_args: "--allowedTools Bash,Read,Edit,Write,Glob,Grep"
check-options:
name: Check CLI option changes
needs: detect-version
if: needs.detect-version.outputs.version_changed == 'true'
runs-on: ubuntu-latest
outputs:
options_changed: ${{ steps.diff.outputs.changed }}
options_diff: ${{ steps.diff.outputs.diff }}
steps:
- uses: actions/checkout@v6
with:
ref: develop
- name: Install new CLI version
run: npm install -g @anthropic-ai/claude-code@${{ needs.detect-version.outputs.new_version }}
- name: Capture and diff help output
id: diff
run: |
# Capture new help output, stripping ANSI escape sequences
claude --help 2>/dev/null | sed 's/\x1b\[[^a-zA-Z]*[a-zA-Z]//g' > /tmp/claude-help-new.txt
if diff .claude-cli-help-output /tmp/claude-help-new.txt > /tmp/help-diff.txt 2>&1; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
DIFF=$(head -c 500000 /tmp/help-diff.txt)
{
echo "diff<<HELPDIFF_EOF"
echo "$DIFF"
echo "HELPDIFF_EOF"
} >> "$GITHUB_OUTPUT"
update-options:
name: Create option update PR(s)
needs: [detect-version, check-options]
if: needs.check-options.outputs.options_changed == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v6
with:
ref: develop
- uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
prompt: |
Claude CLI has been upgraded from ${{ needs.detect-version.outputs.old_version }} to ${{ needs.detect-version.outputs.new_version }}.
The `--help` output has changed. Here is the diff:
```
${{ needs.check-options.outputs.options_diff }}
```
Your task:
1. Read docs/claude-cli.md — especially the "CLI Option Support Status" tables
(Supported / Known Unsupported / Interactive-Only / Managed Internally)
2. Analyze the diff and determine whether changes affect existing options or add new ones
3. For EXISTING option changes (renamed, removed, behavior changed):
- Update relevant code in src/ and docs/claude-cli.md
- Create a PR targeting `develop` from branch `cli-upgrade/${{ needs.detect-version.outputs.new_version }}/option-changes`
- PR title: "fix: update for CLI v${{ needs.detect-version.outputs.new_version }} option changes"
4. For NEW options only (additions that don't affect existing functionality):
- Classify them into the appropriate table in docs/claude-cli.md
- Create a PR targeting `develop` from branch `cli-upgrade/${{ needs.detect-version.outputs.new_version }}/new-options`
- PR title: "docs: add new CLI v${{ needs.detect-version.outputs.new_version }} options"
5. If both types exist, create two separate PRs
6. Run `cargo test` and `cargo clippy -- -D warnings` to verify any code changes
Reference issue #7 in all PR bodies.
claude_args: "--allowedTools Bash,Read,Edit,Write,Glob,Grep"
version-bump:
name: Create version bump PR
needs: [detect-version, run-tests, check-options]
if: |
always() &&
needs.detect-version.outputs.version_changed == 'true' &&
needs.detect-version.result == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: develop
- name: Install new CLI version
run: npm install -g @anthropic-ai/claude-code@${{ needs.detect-version.outputs.new_version }}
- name: Update version files
run: |
NEW_VERSION="${{ needs.detect-version.outputs.new_version }}"
echo "$NEW_VERSION" > .claude-cli-version
claude --help 2>/dev/null | sed 's/\x1b\[[^a-zA-Z]*[a-zA-Z]//g' > .claude-cli-help-output
sed -i "s/TESTED_CLI_VERSION: &str = \".*\"/TESTED_CLI_VERSION: \&str = \"$NEW_VERSION\"/" src/lib.rs
sed -i "s/<!-- cli-version -->.*<!-- \/cli-version -->/<!-- cli-version -->**v$NEW_VERSION**<!-- \/cli-version -->/" README.md
- name: Create PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH="cli-upgrade/${{ needs.detect-version.outputs.new_version }}/version-bump"
# Check if branch already exists
if git ls-remote --exit-code origin "refs/heads/$BRANCH" > /dev/null 2>&1; then
echo "Branch $BRANCH already exists, skipping"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH"
git add .claude-cli-version .claude-cli-help-output src/lib.rs README.md
git commit -m "chore: bump tracked CLI version to ${{ needs.detect-version.outputs.new_version }}"
git push origin "$BRANCH"
gh pr create \
--base develop \
--head "$BRANCH" \
--title "chore: bump tracked CLI version to ${{ needs.detect-version.outputs.new_version }}" \
--body "$(cat <<'PRBODY'
## Summary
- Update `.claude-cli-version` to ${{ needs.detect-version.outputs.new_version }}
- Update `.claude-cli-help-output` with new `--help` output
- Update `TESTED_CLI_VERSION` in `src/lib.rs`
- Update version in `README.md`
> **Note:** If `test-fix` or `option-changes` PRs exist for this version, merge them before this PR.
Ref #7
PRBODY
)"