spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

Merge pull request #794 from anthropics/ashwin/triageactionBrowse files
Add GitHub workflow for issue triage with available labels
Ashwin Bhat authored on Apr 15, 2025 · GitHub committed on Apr 15, 2025 parents 5eb232b + 1183388 · commit 16c5dff959c9
3 changed files+246 -0compared with 5eb232b
A.github/actions/claude-code-action/action.yml
A.github/actions/claude-issue-triage-action/action.yml
A.github/workflows/claude-issue-triage.yml
@@ -1,0 +1,136 @@
1+name: "Claude Code Action"
2+description: "Run Claude Code in GitHub Actions workflows"
3+
4+inputs:
5+ github_token:
6+ description: "GitHub token with repo and issues permissions"
7+ required: true
8+ anthropic_api_key:
9+ description: "Anthropic API key"
10+ required: true
11+ prompt:
12+ description: "The prompt to send to Claude Code"
13+ required: false
14+ default: ""
15+ prompt_file:
16+ description: "Path to a file containing the prompt to send to Claude Code"
17+ required: false
18+ default: ""
19+ allowed_tools:
20+ description: "Comma-separated list of allowed tools for Claude Code to use"
21+ required: false
22+ default: ""
23+ output_file:
24+ description: "File to save Claude Code output to (optional)"
25+ required: false
26+ default: ""
27+ timeout_minutes:
28+ description: "Timeout in minutes for Claude Code execution"
29+ required: false
30+ default: "10"
31+ install_github_mcp:
32+ description: "Whether to install the GitHub MCP server"
33+ required: false
34+ default: "false"
35+
36+runs:
37+ using: "composite"
38+ steps:
39+ - name: Install Claude Code
40+ shell: bash
41+ run: npm install -g @anthropic-ai/claude-code
42+
43+ - name: Install GitHub MCP Server
44+ if: inputs.install_github_mcp == 'true'
45+ shell: bash
46+ run: |
47+ claude mcp add-json github '{
48+ "command": "docker",
49+ "args": [
50+ "run",
51+ "-i",
52+ "--rm",
53+ "-e",
54+ "GITHUB_PERSONAL_ACCESS_TOKEN",
55+ "ghcr.io/github/github-mcp-server:sha-ff3036d"
56+ ],
57+ "env": {
58+ "GITHUB_PERSONAL_ACCESS_TOKEN": "${{ inputs.GITHUB_TOKEN }}"
59+ }
60+ }'
61+
62+ - name: Prepare Prompt File
63+ shell: bash
64+ id: prepare_prompt
65+ run: |
66+ # Check if either prompt or prompt_file is provided
67+ if [ -z "${{ inputs.prompt }}" ] && [ -z "${{ inputs.prompt_file }}" ]; then
68+ echo "::error::Neither 'prompt' nor 'prompt_file' was provided. At least one is required."
69+ exit 1
70+ fi
71+
72+ # Determine which prompt source to use
73+ if [ ! -z "${{ inputs.prompt_file }}" ]; then
74+ # Check if the prompt file exists
75+ if [ ! -f "${{ inputs.prompt_file }}" ]; then
76+ echo "::error::Prompt file '${{ inputs.prompt_file }}' does not exist."
77+ exit 1
78+ fi
79+
80+ # Use the provided prompt file
81+ PROMPT_PATH="${{ inputs.prompt_file }}"
82+ else
83+ mkdir -p /tmp/claude-action
84+ PROMPT_PATH="/tmp/claude-action/prompt.txt"
85+ echo "${{ inputs.prompt }}" > "$PROMPT_PATH"
86+ fi
87+
88+ # Verify the prompt file is not empty
89+ if [ ! -s "$PROMPT_PATH" ]; then
90+ echo "::error::Prompt is empty. Please provide a non-empty prompt."
91+ exit 1
92+ fi
93+
94+ # Save the prompt path for the next step
95+ echo "PROMPT_PATH=$PROMPT_PATH" >> $GITHUB_ENV
96+
97+ - name: Run Claude Code
98+ shell: bash
99+ id: run_claude
100+ run: |
101+ ALLOWED_TOOLS_ARG=""
102+ if [ ! -z "${{ inputs.allowed_tools }}" ]; then
103+ ALLOWED_TOOLS_ARG="--allowedTools ${{ inputs.allowed_tools }}"
104+ fi
105+
106+ # Set a timeout to ensure the command doesn't run indefinitely
107+ timeout_seconds=$((${{ inputs.timeout_minutes }} * 60))
108+
109+ if [ -z "${{ inputs.output_file }}" ]; then
110+ # Run Claude Code and output to console
111+ timeout $timeout_seconds claude \
112+ -p \
113+ --verbose \
114+ --output-format stream-json \
115+ "$(cat ${{ env.PROMPT_PATH }})" \
116+ ${{ inputs.allowed_tools != '' && format('--allowedTools "{0}"', inputs.allowed_tools) || '' }}
117+ else
118+ # Run Claude Code and tee output to console and file
119+ timeout $timeout_seconds claude \
120+ -p \
121+ --verbose \
122+ --output-format stream-json \
123+ "$(cat ${{ env.PROMPT_PATH }})" \
124+ ${{ inputs.allowed_tools != '' && format('--allowedTools "{0}"', inputs.allowed_tools) || '' }} | tee output.txt
125+
126+ # Process output.txt into JSON in a separate step
127+ jq -s '.' output.txt > output.json
128+
129+ # Extract the result from the last item in the array (system message)
130+ jq -r '.[-1].result' output.json > "${{ inputs.output_file }}"
131+
132+ echo "Complete output saved to output.json, final response saved to ${{ inputs.output_file }}"
133+ fi
134+ env:
135+ ANTHROPIC_API_KEY: ${{ inputs.anthropic_api_key }}
136+ GITHUB_TOKEN: ${{ inputs.github_token }}
@@ -1,0 +1,87 @@
1+name: "Claude Issue Triage Action"
2+description: "Automatically triage GitHub issues using Claude Code"
3+
4+inputs:
5+ timeout_minutes:
6+ description: "Timeout in minutes for execution"
7+ required: false
8+ default: "5"
9+ anthropic_api_key:
10+ description: "Anthropic API key"
11+ required: true
12+ github_token:
13+ description: "GitHub token with repo and issues permissions"
14+ required: true
15+
16+runs:
17+ using: "composite"
18+ steps:
19+ - name: Checkout repository code
20+ uses: actions/checkout@v4
21+ with:
22+ fetch-depth: 0
23+
24+ - name: Create prompt file
25+ shell: bash
26+ run: |
27+ mkdir -p /tmp/claude-prompts
28+ cat > /tmp/claude-prompts/claude-issue-triage-prompt.txt << 'EOF'
29+ You're an issue triage assistant for GitHub issues. Your task is to analyze the issue and select appropriate labels from the provided list.
30+
31+ IMPORTANT: Don't post any comments or messages to the issue. Your only action should be to apply labels.
32+
33+ Issue Information:
34+ - REPO: ${{ github.repository }}
35+ - ISSUE_NUMBER: ${{ github.event.issue.number }}
36+
37+ TASK OVERVIEW:
38+
39+ 1. First, fetch the list of labels available in this repository by running: `gh label list`. Run exactly this command with nothing else.
40+
41+ 2. Next, use the GitHub tools to get context about the issue:
42+ - You have access to these tools:
43+ - mcp__github__get_issue: Use this to retrieve the current issue's details including title, description, and existing labels
44+ - mcp__github__get_issue_comments: Use this to read any discussion or additional context provided in the comments
45+ - mcp__github__update_issue: Use this to apply labels to the issue (do not use this for commenting)
46+ - mcp__github__search_issues: Use this to find similar issues that might provide context for proper categorization and to identify potential duplicate issues
47+ - mcp__github__list_issues: Use this to understand patterns in how other issues are labeled
48+ - Start by using mcp__github__get_issue to get the issue details
49+
50+ 3. Analyze the issue content, considering:
51+ - The issue title and description
52+ - The type of issue (bug report, feature request, question, etc.)
53+ - Technical areas mentioned
54+ - Severity or priority indicators
55+ - User impact
56+ - Components affected
57+
58+ 4. Select appropriate labels from the available labels list provided above:
59+ - Choose labels that accurately reflect the issue's nature
60+ - Be specific but comprehensive
61+ - Select priority labels if you can determine urgency (high-priority, med-priority, or low-priority)
62+ - Consider platform labels (android, ios) if applicable
63+ - If you find similar issues using mcp__github__search_issues, consider using a "duplicate" label if appropriate. Only do so if the issue is a duplicate of another OPEN issue.
64+
65+ 5. Apply the selected labels:
66+ - Use mcp__github__update_issue to apply your selected labels
67+ - DO NOT post any comments explaining your decision
68+ - DO NOT communicate directly with users
69+ - If no labels are clearly applicable, do not apply any labels
70+
71+ IMPORTANT GUIDELINES:
72+ - Be thorough in your analysis
73+ - Only select labels from the provided list above
74+ - DO NOT post any comments to the issue
75+ - Your ONLY action should be to apply labels using mcp__github__update_issue
76+ - It's okay to not add any labels if none are clearly applicable
77+ EOF
78+
79+ - name: Run Claude Code
80+ uses: ./.github/actions/claude-code-action
81+ with:
82+ prompt_file: /tmp/claude-prompts/claude-issue-triage-prompt.txt
83+ allowed_tools: "Bash(gh label list),mcp__github__get_issue,mcp__github__get_issue_comments,mcp__github__update_issue,mcp__github__search_issues,mcp__github__list_issues"
84+ install_github_mcp: "true"
85+ timeout_minutes: ${{ inputs.timeout_minutes }}
86+ anthropic_api_key: ${{ inputs.anthropic_api_key }}
87+ github_token: ${{ inputs.github_token }}
@@ -1,0 +1,23 @@
1+name: Claude Issue Triage
2+description: "Automatically triage GitHub issues using Claude Code"
3+
4+on:
5+ issues:
6+ types: [opened]
7+
8+jobs:
9+ triage-issue:
10+ runs-on: ubuntu-latest
11+ timeout-minutes: 10
12+ permissions:
13+ contents: read
14+ issues: write
15+ steps:
16+ - name: Checkout repository
17+ uses: actions/checkout@v4
18+
19+ - name: Run Claude Issue Triage
20+ uses: ./.github/actions/claude-issue-triage-action
21+ with:
22+ anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
23+ github_token: ${{ secrets.GITHUB_TOKEN }}