# gh workflow view: Inspect a Workflow in CI

> gh workflow view shows a workflow definition, state, and recent runs. Reference for --yaml, --ref, --json, and the workflow-not-found errors in CI.

Source: https://latchkey.dev/learn/command-reference/gh-workflow-view  
Updated: 2026-06-30

gh workflow view shows a workflow file, whether it is enabled, and its most recent runs.

Before dispatching or auditing a workflow, gh workflow view confirms the file, its enabled state, and the ID you will reference.

## What it does

gh workflow view displays a workflow identified by name, filename, or ID. It shows the enabled or disabled state and recent runs; --yaml prints the workflow YAML at the default branch or a chosen --ref.

## Common usage

```Terminal
gh workflow view ci.yml
gh workflow view ci.yml --yaml
gh workflow view ci.yml --ref release/1.x
gh workflow view 161335 --json id,name,state
```

## Flags

| Flag | What it does |
| --- | --- |
| -y, --yaml | Print the workflow YAML content |
| -r, --ref <ref> | View the workflow at a branch, tag, or SHA |
| --json <fields> | Output workflow data as JSON |
| -w, --web | Open the workflow in a browser |
| -R, --repo <owner/repo> | Target a specific repository |

## In CI

Set GH_TOKEN and permissions: { actions: read }. Reference workflows by filename (ci.yml) for stability, since names can change. --yaml --ref lets you confirm what a workflow looked like at the commit a run used.

## Common errors in CI

"could not find any workflows named X" means the name or filename is wrong; list them with gh workflow list. "gh: To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable" means GH_TOKEN is missing. A workflow that exists but is disabled still views fine; check the state field.

## Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

```.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

### gh workflow view: Inspect a Workflow in CI?

Before dispatching or auditing a workflow, gh workflow view confirms the file, its enabled state, and the ID you will reference.

### What it does?

gh workflow view displays a workflow identified by name, filename, or ID. It shows the enabled or disabled state and recent runs; --yaml prints the workflow YAML at the default branch or a chosen --ref.

### In CI?

Set GH_TOKEN and permissions: { actions: read }. Reference workflows by filename (ci.yml) for stability, since names can change. --yaml --ref lets you confirm what a workflow looked like at the commit a run used.

### Common errors in CI?

"could not find any workflows named X" means the name or filename is wrong; list them with gh workflow list. "gh: To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable" means GH_TOKEN is missing. A workflow that exists but is disabled still views fine; check the state field.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
