Skip to content

feat: prefer gh CLI over web scraping for GitHub URLs#2225

Open
huaiyuWangh wants to merge 1 commit intocharmbracelet:mainfrom
huaiyuWangh:feat/prefer-gh-cli-for-github-urls
Open

feat: prefer gh CLI over web scraping for GitHub URLs#2225
huaiyuWangh wants to merge 1 commit intocharmbracelet:mainfrom
huaiyuWangh:feat/prefer-gh-cli-for-github-urls

Conversation

@huaiyuWangh
Copy link
Contributor

@huaiyuWangh huaiyuWangh commented Feb 14, 2026

Summary

Add prompt instructions to guide agents to use gh CLI instead of web_fetch when fetching GitHub content (PRs, issues, repos, commits). This provides structured JSON data with better quality and reliability than HTML parsing.

Changes

  • bash.tpl: Add <github_integration> section with gh CLI command examples for PRs, issues, repos, and commits
  • agentic_fetch.md: Add tip in <tips> section to prefer gh CLI for GitHub URLs
  • web_fetch.md: Add tip to use gh CLI as primary method for GitHub content

Benefits

  • ✅ Better data quality with structured JSON vs fragile HTML parsing
  • ✅ Access to rich metadata (reviews, check runs, reactions, timeline events)
  • ✅ More reliable API contract vs HTML structure changes
  • ✅ Faster direct API access vs web scraping overhead
  • ✅ Graceful fallback to web_fetch if gh CLI fails

Implementation Approach

This is a prompt-driven solution with no code changes required:

  • Main agent sees GitHub URL → considers bash tool (with gh CLI guidance) instead of agentic_fetch
  • If gh CLI fails → gracefully falls back to web_fetch
  • Easy to rollback by reverting prompt files

Test Plan

  • Test with PR URL: Verified agent uses gh CLI to fetch PR data
  • Test with issue URL: Verified agent uses gh CLI to fetch issue data
image - [x] Verified fallback: Confirmed web_fetch is used when gh CLI unavailable image

Note on Test Failures

The test failures in TestCoderAgent are expected because the bash tool prompt was modified (added <github_integration> section), which changes the system prompt sent to the API. The VCR cassettes need to be re-recorded with the new prompt.

To fix: Delete or re-record the cassette files in internal/agent/testdata/TestCoderAgent/*/ and run tests with valid API keys.

Closes #2215

Add prompt instructions to guide agents to use gh CLI instead of web_fetch
when fetching GitHub content (PRs, issues, repos, commits). This provides
structured JSON data with better quality and reliability than HTML parsing.

Changes:
- bash.tpl: Add github_integration section with gh CLI command examples
- agentic_fetch.md: Add tip to prefer gh CLI for GitHub URLs
- web_fetch.md: Add tip to use gh CLI as primary method for GitHub content

Closes charmbracelet#2215
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prefer gh cli over web scraping for GitHub URLs

1 participant