anthropics / anthropics/claude-code-action
Claude action does not run PreToolUse
- 主要言語
- TypeScript
- スター
- 8.9k
- フォーク
- 2.1k
- 平均マージ
- 3日 9時間
- マージ済み PR(30日)
- 10
説明
**Describe the bug**
I created a pre-commit hook that will try to build the app before committing. It works fine locally. When Claude tries to commit but the build is broken it will get the error code 2, fix what needs to be fixed and try again. I added the same hook to the claude action but apparently it just ignores it.
**To Reproduce**
Use the yml file bellow. I'm not posting the contents of `pre-commit.sh`, but I tested this hook locally and it works. It also prints some lines to terminal so I know it is being executed, but I can't see them in the gh action.
So with this setting I asked claude to edit something in a file and it was still able to commit even when pre-commit.sh would return 2.
**Workflow yml file**
```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
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
actions: read # Required for Claude to read CI results on PRs
packages: read # Required only for pnpm install
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: "18.18"
cache: "pnpm"
- run: pnpm install
- name: Run Claude Code
id: claude
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
# This is an optional setting that allows Claude to read CI results on PRs
additional_permissions: |
actions: read
claude_args: "--allowed-tools Bash(gh pr:*)"
settings: |
{
"permissions": {
"deny": [
"Read(./**/.env)",
]
},
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "jq -r '.tool_input.file_path' | { read file_path; if echo \"$file_path\" | grep -q '\\.ts$'; then pnpm exec prettier --write \"$file_path\"; fi; }"
}
]
}
],
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "cmd=$(jq -r '.tool_input.command'); \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/pre-commit.sh \\\"$cmd\\\""
}
]
}
]
}
}
```
**API Provider**
[x] Anthropic First-Party API (default)
[ ] AWS Bedrock
[ ] GCP Vertex
コントリビューションガイド
評価
この issue はまだ評価されていません。