Use GitHub CLI to Read Repo Files Without Cloning
GitHub CLI 2.95.0 adds preview commands for reading files and directories from remote repositories, useful for agents, audits, and quick config checks.
What you get from it
Why this is useful
GitHub CLI 2.95.0 adds gh repo read-file and gh repo read-dir, two preview commands for inspecting repository content directly from the terminal. It is a practical upgrade for developers, maintainers, and AI-agent workflows that need to check a README, config file, package manifest, docs folder, or policy file without cloning the full repository first.
Quick start
# Read a single file from a public or accessible private repository
gh repo read-file README.md --repo cli/cli
# List a directory from a specific ref
gh repo read-dir docs --repo cli/cli --ref v2.95.0
# Return structured data for scripts and agents
gh repo read-dir .github --repo cli/cli --json name,path,type,size
Caveats
The commands are marked preview, so flags or output details may change. Access still follows the permissions of the authenticated GitHub user, and large or binary files are not a replacement for a proper checkout. For automation, pin your expected gh version and handle missing-command fallback paths.
Source check
| Source | What it confirms |
|---|---|
| GitHub Changelog | gh repo read-file and gh repo read-dir are available in GitHub CLI 2.95.0+ |
| GitHub CLI release notes | The release date, examples, preview status, and scripting flags |
| GitHub CLI manual | Exact command syntax, JSON fields, and terminal escape-sequence behavior |
Discussion
Share practical experience, questions, or warnings with the community.
Sign in to join the discussion and vote on comments.
Sign in