anthropics / anthropics/claude-code-action

Dynamically selecting the model that claude-code-action should run with

Abierto
#394 1 comentario 2 reacciones 0 asignados Ver en GitHub
enhancement p3
Lenguaje dominante
TypeScript
Estrellas
8.9k
Forks
2.1k
Merge medio
3 d 9 h
PR fusionados (30 d)
10

Descripción

Hi 👋 thanks a lot for this great project - it's a really nice use case to be able to run Claude Code in a repository!

Is there a way to dynamically select the model that Claude Code should use by specifying it in the comment? For example like so:

```
@claude opus please fix this bug
```

I've tried the following configuration but without success:

```yml
name: Claude Code

on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
issues:
types: [opened, assigned]
pull_request_review:
types: [submitted]

jobs:
claude:
if: |
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
runs-on: ubuntu-latest
needs: install-dependencies
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
actions: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Parse model from comment
id: parse-model
run: |
COMMENT_BODY="${{ github.event.comment.body || github.event.review.body || github.event.issue.body || github.event.issue.title }}"

# Simple syntax: @claude opus @claude sonnet
if echo "$COMMENT_BODY" | grep -qi "\b@claude\s+opus\b"; then
MODEL="claude-opus-4-20250514"
echo "model=$MODEL" >> $GITHUB_OUTPUT
echo "Using model: $MODEL"
elif echo "$COMMENT_BODY" | grep -qi "\b@claude\s+sonnet\b"; then
MODEL="claude-sonnet-4-20250514"
echo "model=$MODEL" >> $GITHUB_OUTPUT
echo "Using model: $MODEL"
fi

- name: Run Claude Code
id: claude
uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}

model: ${{ steps.parse-model.outputs.model }}

additional_permissions: |
actions: read

claude_env: |
ANTHROPIC_BASE_URL: ${{ vars.ANTHROPIC_BASE_URL }}
```

When I then comment and see Claude Code running in GH, it defaults back to Sonnet:

Image

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.