[ GitHub security features  ](/en/actions/security-guides/using-githubs-security-features-to-secure-your-use-of-github-actions)
    * [ Automatic token authentication  ](/en/actions/security-guides/automatic-token-authentication)

  * Creating actions 

    * [ About custom actions  ](/en/actions/creating-actions/about-custom-actions)
    * [ Create a Docker container action  ](/en/actions/creating-actions/creating-a-docker-container-action)
    * [ Create a JavaScript action  ](/en/actions/creating-actions/creating-a-javascript-action)
    * [ Create a composite action  ](/en/actions/creating-actions/creating-a-composite-action)
    * [ Metadata syntax  ](/en/actions/creating-actions/metadata-syntax-for-github-actions)
    * [ Dockerfile support  ](/en/actions/creating-actions/dockerfile-support-for-github-actions)
    * [ Set exit codes  ](/en/actions/creating-actions/setting-exit-codes-for-actions)
    * [ Publish in GitHub Marketplace  ](/en/actions/creating-actions/publishing-actions-in-github-marketplace)
    * [ Share from your private repository  ](/en/actions/creating-actions/sharing-actions-and-workflows-from-your-private-repository)
    * [ Share with your organization  ](/en/actions/creating-actions/sharing-actions-and-workflows-with-your-organization)
    * [ Release and maintain actions  ](/en/actions/creating-actions/releasing-and-maintaining-actions)
    * [ CLI setup action  ](/en/actions/creating-actions/developing-a-third-party-cli-action)

  * [ Guides for GitHub Actions  ](/en/actions/guides)

  * [ GitHub Actions ](/en/actions "GitHub Actions") / 
  * [ Using workflows ](/en/actions/using-workflows "Using workflows") / 
  * [ GitHub CLI in workflows ](/en/actions/using-workflows/using-github-cli-in-workflows "GitHub CLI in workflows")

#  Using GitHub CLI in workflows

You can script with GitHub CLI in GitHub Actions workflows.

To learn more about GitHub CLI, see " [ About GitHub CLI ](/en/github-
cli/github-cli/about-github-cli) ."

GitHub CLI is preinstalled on all GitHub-hosted runners. For each step that
uses GitHub CLI, you must set an environment variable called ` GH_TOKEN ` to a
token with the required scopes.

You can execute any GitHub CLI command. For example, this workflow uses the `
gh issue comment ` subcommand to add a comment when an issue is opened.

YAML

    
    
    name: Comment when opened
    on:
      issues:
        types:
          - opened
    jobs:
      comment:
        runs-on: ubuntu-latest
        steps:
          - run: gh issue comment $ISSUE --body "Thank you for opening this issue!"
            env:
              GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
              ISSUE: ${{ github.event.issue.html_url }}
    
    
    
    name: Comment when opened
    on:
      issues:
        types:
          - opened
    jobs:
      comment:
        runs-on: ubuntu-latest
        steps:
          - run: gh issue comment $ISSUE --body "Thank you for opening this issue!"
            env:
              GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
              ISSUE: ${{ github.event.issue.html_url }}
    

You can also execute API calls through GitHub CLI. For example, this workflow
first uses the ` gh api ` subcommand to query the GraphQL API and parse the
result. Then it stores the result in an environment variable that it can
access in a later step. In the second step, it uses the ` gh issue create `
subcommand to create an issue containing the information from the first step.

YAML

    
    
    name: Report remaining open issues
    on: 
      schedule: 
        # Daily at 8:20 UTC
        - cron: '20 8 * * *'
    jobs:
      track_pr:
        runs-on: ubuntu-latest
        steps:
          - run: |
              numOpenIssues="$(gh api graphql -F owner=$OWNER -F name=$REPO -f query='
                query($name: String!, $owner: String!) {
                  repository(owner: $owner, name: $name) {
                    issues(states:OPEN){
                      totalCount