# Template. Copy to .github/workflows/claude-headless.yml in your own repository,
# and copy claude-headless.sh to scripts/claude-headless.sh.
# This job installs the Claude Code CLI and runs claude -p. It does not deploy.
# shipmunks.dev deploys from the Cloudflare Pages build of main. Do not put this
# file in that site's .github/workflows directory.
name: Claude Code headless

on:
  workflow_dispatch:
    inputs:
      prompt:
        description: Prompt passed to claude -p
        required: true
        default: Summarize README.md
        type: string

jobs:
  headless:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - name: Check out the repository
        uses: actions/checkout@v6
        with:
          fetch-depth: 1

      - name: Install the Claude Code CLI
        run: npm install -g --prefix "${{ runner.temp }}/claude-code" @anthropic-ai/claude-code

      - name: Run claude -p and print the result field
        env:
          PATH: ${{ runner.temp }}/claude-code/bin:${{ env.PATH }}
          PROMPT: ${{ inputs.prompt }}
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
        run: bash scripts/claude-headless.sh "$PROMPT"
