Skip to content

Conversation

@vibhor1997a
Copy link
Contributor

Add support for pull_request_target event

Summary

This PR adds support for the pull_request_target GitHub event, enabling Claude Code to work with forked repositories and external contributions while maintaining proper
security boundaries.

Problem

Users reported that Claude Code failed when triggered by pull_request_target events with the error:
Error: Prepare step failed with error: Unsupported event type: pull_request_target

This prevented usage with:

  • Dependabot PRs (which require write permissions)
  • External contributor workflows
  • Forked repository contributions that need elevated permissions

Solution

  • Event Support: Added pull_request_target as a supported GitHub event type
  • Type Safety: Extended type definitions to include PullRequestTargetEvent
  • Context Detection: Updated PR detection logic to recognize pull_request_target as PR context
  • Payload Compatibility: Leveraged identical payload structure between pull_request and pull_request_target events

Changes

Core Changes

  • src/github/context.ts: Added pull_request_target case to context parsing
  • src/create-prompt/index.ts: Added pull_request_target event handling
  • src/create-prompt/types.ts: Added PullRequestTargetEvent type definition
  • action.yml: Updated IS_PR detection to include pull_request_target

Documentation

  • docs/custom-automations.md: Updated supported events list

Testing

  • test/create-prompt.test.ts: Added test cases for pull_request_target event
  • test/pull-request-target.test.ts: Comprehensive test suite (373 lines) covering:
  • Event type detection
  • Context parsing
  • Prompt generation
  • Commit signing modes
  • Custom instructions handling
  • Variable substitution

Security Considerations

The pull_request_target event runs in the context of the base repository with write permissions, making it suitable for:

  • ✅ Automated reviews of external contributions
  • ✅ Dependabot PR processing with write access
  • ✅ Fork-based workflows requiring elevated permissions

The implementation maintains security by using the same validation and permission checks as regular pull_request events.

Test Plan

  • Unit tests for all new functionality
  • Integration tests with mock GitHub contexts
  • Type checking passes with new event definitions
  • Backward compatibility with existing pull_request workflows
  • Documentation updated to reflect new capabilities

Compatibility

This change is fully backward compatible - existing pull_request workflows continue to work unchanged, while pull_request_target workflows now gain Claude Code support.

Closes #347


🤖 Generated with Claude Code

…flows

Add pull_request_target event support to enable Claude Code usage with forked
repositories while maintaining proper security boundaries. This resolves issues
with dependabot PRs and external contributions that require write permissions.

Changes:
- Add pull_request_target to supported GitHub events in context parsing
- Update type definitions to include PullRequestTargetEvent
- Modify IS_PR calculation to detect pull_request_target as PR context
- Add comprehensive test coverage for pull_request_target workflows
- Update documentation to reflect pull_request_target support

The pull_request_target event provides the same payload structure as
pull_request but runs with write permissions from the base repository,
making it ideal for secure automation of external contributions.

Fixes anthropics#347
@ashwin-ant
Copy link
Collaborator

Thank you!

@ashwin-ant ashwin-ant merged commit bd70a3e into anthropics:main Sep 22, 2025
4 of 14 checks passed
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.

Can't use action in workflow triggered by pull_request_target

2 participants