Automation & Cloud Execution/Local Automation & CI/CD
Intermediate11 min

The gh CLI — Claude Code's Best Integration

For most GitHub workflows, gh CLI outperforms the GitHub MCP server: no context overhead, battle-tested, zero setup if you're already authenticated. This article covers when to use gh vs GitHub MCP, core patterns, and building automation workflows around gh.

Quick Reference

  • gh is a first-class tool in Claude Code — no setup if already installed and authenticated
  • Claude knows gh from training — no docs or schema loading needed
  • Core commands: gh pr create, gh pr view, gh issue create, gh pr checks, gh pr merge
  • --from-pr flag in claude lets you start a PR-aware session directly
  • Build /fix-issue and /create-pr skills around gh for reusable team workflows
  • gh pr checks is the key command for CI monitoring loops
  • GitHub MCP: reach for it when gh can't do it (fine-grained API, webhook management)
  • gh is synchronous; GitHub MCP is better for event-driven or webhook-triggered workflows

Why gh Beats GitHub MCP for Most Use Cases

When engineers first add GitHub integration to Claude Code, the instinct is to reach for the GitHub MCP server — it's official, it sounds comprehensive, and it promises deep API access. But for the 90% of day-to-day GitHub workflows, gh CLI is a better choice.

Dimensiongh CLIGitHub MCP
SetupAlready installed for most engineersRequires installing and configuring MCP server
Context overheadZero — Claude calls it as BashAdds MCP tool schemas to context window
Claude's knowledgeDeeply trained on gh syntaxTreats it as a new API to discover
ReliabilityBattle-tested, widely usedNewer, fewer edge cases handled
API coverageComplete for common operationsMore comprehensive for obscure API calls
Event-driven useNot nativeBetter for webhook and event-driven patterns

The context overhead difference is real: every MCP server adds tool schemas to Claude's context window. For a simple pr create, you're spending tokens on schema discovery that could be used for code analysis. gh commands are two-token invocations that Claude already knows how to use.

When to Use GitHub MCP Instead

Reach for GitHub MCP when you need fine-grained API calls that gh doesn't expose (repository settings, webhook management, GitHub Apps), when you want event-driven triggers (e.g., respond when a label is added), or when you need to interact with GitHub's GraphQL API for complex queries.