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 #2779 from anthropics/ashwin/triageBrowse files
refactor: Replace custom GitHub actions with claude-code-base-action
Ashwin Bhat authored on Jul 1, 2025 · GitHub committed on Jul 1, 2025 parent 390f110 · commit 80ddbcd96de5
3 changed files+87 -230compared with 390f110
D.github/actions/claude-code-action/action.yml
D.github/actions/claude-issue-triage-action/action.yml
M.github/workflows/claude-issue-triage.yml
D.github/actions/claude-code-action/action.yml+0 -136
@@ -1,136 +1,0 @@
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 }}
D.github/actions/claude-issue-triage-action/action.yml+0 -87
@@ -1,87 +1,0 @@
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,6 +1,5 @@
11 name: Claude Issue Triage
2-description: "Automatically triage GitHub issues using Claude Code"
3-
2+description: Automatically triage GitHub issues using Claude Code
43 on:
54 issues:
65 types: [opened]
@@ -12,12 +11,93 @@
1211 permissions:
1312 contents: read
1413 issues: write
14+
1515 steps:
16- - name: Checkout repository
17- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
16+ - name: Create triage prompt
17+ run: |
18+ mkdir -p /tmp/claude-prompts
19+ cat > /tmp/claude-prompts/triage-prompt.txt << 'EOF'
20+ You're an issue triage assistant for GitHub issues. Your task is to analyze the issue and select appropriate labels from the provided list.
1821
19- - name: Run Claude Issue Triage
20- uses: ./.github/actions/claude-issue-triage-action
22+ IMPORTANT: Don't post any comments or messages to the issue. Your only action should be to apply labels.
23+
24+ Issue Information:
25+ - REPO: ${{ github.repository }}
26+ - ISSUE_NUMBER: ${{ github.event.issue.number }}
27+
28+ TASK OVERVIEW:
29+
30+ 1. First, fetch the list of labels available in this repository by running: `gh label list`. Run exactly this command with nothing else.
31+
32+ 2. Next, use the GitHub tools to get context about the issue:
33+ - You have access to these tools:
34+ - mcp__github__get_issue: Use this to retrieve the current issue's details including title, description, and existing labels
35+ - mcp__github__get_issue_comments: Use this to read any discussion or additional context provided in the comments
36+ - mcp__github__update_issue: Use this to apply labels to the issue (do not use this for commenting)
37+ - mcp__github__search_issues: Use this to find similar issues that might provide context for proper categorization and to identify potential duplicate issues
38+ - mcp__github__list_issues: Use this to understand patterns in how other issues are labeled
39+ - Start by using mcp__github__get_issue to get the issue details
40+
41+ 3. Analyze the issue content, considering:
42+ - The issue title and description
43+ - The type of issue (bug report, feature request, question, etc.)
44+ - Technical areas mentioned
45+ - Severity or priority indicators
46+ - User impact
47+ - Components affected
48+
49+ 4. Select appropriate labels from the available labels list provided above:
50+ - Choose labels that accurately reflect the issue's nature
51+ - Be specific but comprehensive
52+ - Select priority labels if you can determine urgency (high-priority, med-priority, or low-priority)
53+ - Consider platform labels (android, ios) if applicable
54+ - 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.
55+
56+ 5. Apply the selected labels:
57+ - Use mcp__github__update_issue to apply your selected labels
58+ - DO NOT post any comments explaining your decision
59+ - DO NOT communicate directly with users
60+ - If no labels are clearly applicable, do not apply any labels
61+
62+ IMPORTANT GUIDELINES:
63+ - Be thorough in your analysis
64+ - Only select labels from the provided list above
65+ - DO NOT post any comments to the issue
66+ - Your ONLY action should be to apply labels using mcp__github__update_issue
67+ - It's okay to not add any labels if none are clearly applicable
68+ EOF
69+
70+ - name: Setup GitHub MCP Server
71+ run: |
72+ mkdir -p /tmp/mcp-config
73+ cat > /tmp/mcp-config/mcp-servers.json << 'EOF'
74+ {
75+ "mcpServers": {
76+ "github": {
77+ "command": "docker",
78+ "args": [
79+ "run",
80+ "-i",
81+ "--rm",
82+ "-e",
83+ "GITHUB_PERSONAL_ACCESS_TOKEN",
84+ "ghcr.io/github/github-mcp-server:sha-7aced2b"
85+ ],
86+ "env": {
87+ "GITHUB_PERSONAL_ACCESS_TOKEN": "${{ secrets.GITHUB_TOKEN }}"
88+ }
89+ }
90+ }
91+ }
92+ EOF
93+
94+ - name: Run Claude Code for Issue Triage
95+ uses: anthropics/claude-code-base-action@beta
2196 with:
97+ prompt_file: /tmp/claude-prompts/triage-prompt.txt
98+ 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"
99+ timeout_minutes: "5"
22100 anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
23- github_token: ${{ secrets.GITHUB_TOKEN }}
101+ mcp_config: /tmp/mcp-config/mcp-servers.json
102+ claude_env: |
103+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}