[BUG] Claude Code GitHub Actions integration gets stuck in an infinite loop when a Stop hook fails
Environment
- Platform (select one):
- [ ] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [x] Other: Claude Max $100/month
- Claude CLI version: 1.0.52
- Operating System:
sw_vers
ProductName: macOS
ProductVersion: 15.5
BuildVersion: 24F74
- Terminal: Claude Code Termainal App Within VSC
Bug Description
Claude Code GitHub Actions integration gets stuck in an infinite loop when a Stop hook fails with a syntax error. The failing hook continuously triggers and generates repeated "Stop hook feedback" messages, preventing the GitHub Action from completing successfully.
~~~json
{
"type": "user",
"message": {
"role": "user",
"content": [
{
"type": "text",
"text": "Stop hook feedback:\n- [terminal-notifier -title 'Claude Code' -subtitle 'Session Complete' -message \"Finished working in $(basename \"$PWD\")\" -sound default -timeout 10]: /var/lib/gems/3.2.0/gems/terminal-notifier-2.0.0/vendor/terminal-notifier/terminal-notifier.app/Contents/MacOS/terminal-notifier: 1: Syntax error: \"(\" unexpected\n"
}
]
},
"parent_tool_use_id": null,
"session_id": "bf3677b9-66d3-xxx"
}
{
"type": "assistant",
"message": {
"id": "msg_xxx",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-4-20250514",
"content": [
{
"type": "thinking",
"thinking": "The user keeps getting the same terminal notification hook error message repeated over and over. This seems to be some kind of loop or repeated execution of a hook that's failing. \n\nAt this point, I should just acknowledge it very briefly since I've already explained what the issue is in my earlier responses. The user likely needs to fix their Claude Code hooks configuration, but the repeated messages suggest this might be some kind of system issue or loop that's beyond what I can help with through these brief acknowledgments.\n\nI should keep my response very short since this is just a recurring system notification.",
"signature": "XYZ"
}
],
"stop_reason": null,
"stop_sequence": null,
"usage": {
"input_tokens": 0,
"cache_creation_input_tokens": 116,
"cache_read_input_tokens": 37975,
"output_tokens": 4,
"service_tier": "standard"
}
},
~~~
Steps to Reproduce
- Configure a Stop hook in user-level settings.json with a command containing shell syntax that fails in the GitHub Actions environment:
``json``
{
"model": "sonnet",
"hooks": {
"Stop": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "terminal-notifier -title 'Claude Code' -subtitle 'Session Complete' -message \"Finished working in $(basename \"$PWD\")\" -sound default -timeout 10"
}
]
}
]
}
}
- Install Claude Code GitHub App using
/install-github-app - Trigger a GitHub Action that uses Claude Code via a PR request
- Observe the action logs showing repeated hook failure messages and never finishes
Expected Behavior
- Hook failures should be logged but not cause infinite loops
- GitHub Actions should complete even when hooks fail
- There should be a mechanism to prevent recursive hook execution
- Hook errors should be handled gracefully without blocking the main workflow
Actual Behavior
- The GitHub Action gets stuck in a loop repeatedly executing the failing Stop hook
- Action logs show continuous "Stop hook feedback" messages with the same syntax error
- The workflow cannot complete successfully
- Error message:
/var/lib/gems/3.2.0/gems/terminal-notifier-2.0.0/vendor/terminal-notifier/terminal-notifier.app/Contents/MacOS/terminal-notifier: 1: Syntax error: "(" unexpected
Additional Context
The issue occurs because:
- The
$(basename "$PWD")shell command syntax is not compatible with the GitHub Actions environment - The
terminal-notifiercommand is designed for macOS desktop notifications and doesn't work in CI environments - There's no circuit breaker to prevent failed hooks from continuously re-executing
- User-level hooks are being applied in GitHub Actions context where they may not be appropriate
Suggested fixes:
- Add hook execution limits/circuit breakers
- Provide environment detection to skip desktop-specific hooks in CI
- Better error handling for hook failures
- Documentation about hook compatibility with GitHub Actions
Workaround: Remove or modify the Stop hook configuration to be compatible with CI environments.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗