Skip to main content

github-context-tools

Typed GitHub API tools that give LLMs structured access to pull requests, code, history, and issues.

Installation

pip install github-context-tools

Quickstart

from github_context_tools import make_tools

tools = make_tools(token="ghp_...")  # or set GH_TOKEN / GITHUB_TOKEN env var

# Pass the list to your agent framework's tool registry
agent.run(tools=tools)

How it works

make_tools() returns a list of plain Python functions. You pass that list directly to your agent framework's tool registry — no adapters or glue code needed.

Each tool is fully typed using Annotated[type, "description"] on every parameter and return value. Agent frameworks (Anthropic SDK, LangChain, OpenAI, etc.) read these annotations to automatically generate tool schemas, so the LLM always knows what each tool does, what to pass in, and what to expect back.

Available tools

Pull requests

Tool Description Returns
get_pr_metadata Title, author, branch names, SHAs, state, and change stats for a PR PRMetadata
get_parsed_pr_diff Structured diff of every file changed in a PR, broken into hunks and individual lines PRDiff
get_pr_description Title, body, and labels of a PR PRDescription
get_pr_comments All inline review comments and conversation comments on a PR list[PRComment]

Code

Tool Description Returns
get_file_at_ref Contents of a file at any branch, tag, or commit SHA FileContent
get_directory_tree Recursive file tree for a repo or subdirectory at a given ref dict
search_codebase Search a repo by content, file path, filename, or symbol name list[SearchResult]
get_sibling_files All other files in the same directory as a given file list[str]

History

Tool Description Returns
get_file_commit_history Recent commits that touched a file, newest-first. Supports filtering by author, date range, and branch list[CommitSummary]
get_commit_diff Structured diff introduced by a single commit CommitDiff
get_blame Blame ranges for an entire file, each annotated with the commit, author, and a recency score list[BlameEntry]

Issues

Tool Description Returns
get_linked_issue Title, body, author, labels, state, and comments for a GitHub issue Issue

Conventions

Tool Description Returns
get_repo_conventions Contents of well-known convention and context files from the default branch (CONTRIBUTING.md, CLAUDE.md, AGENTS.md, .cursor/rules, .cursorrules, .github/copilot-instructions.md, docs/architecture.md, docs/ARCHITECTURE.md, docs/development.md, DEVELOPMENT.md) RepoConventions

Selecting tools

By default make_tools() returns all 13 tools. Use include or exclude to control which tools are registered with your agent.

Include only the tools you need:

tools = make_tools(
    token="ghp_...",
    include={"get_pr_metadata", "get_parsed_pr_diff", "get_pr_comments"},
)

Exclude tools you don't want:

tools = make_tools(
    token="ghp_...",
    exclude={"get_blame", "search_codebase"},
)

Both parameters accept a set[str] of tool names (the function names listed in the Available tools table). Unrecognised names raise a ValueError immediately.

Authentication

Pass a token directly or set an environment variable:

export GH_TOKEN=ghp_...
# or
export GITHUB_TOKEN=ghp_...
tools = make_tools(token="ghp_...")

Required token scopes

Use a classic personal access token (PAT) with the following scopes:

Scope Required for
repo All tools on private repositories
public_repo All tools on public repositories only

Fine-grained PATs work too. Grant read-only access to the following permissions on the target repositories:

Permission Required for
Contents get_file_at_ref, get_directory_tree, get_sibling_files, get_repo_conventions
Pull requests get_pr_metadata, get_parsed_pr_diff, get_pr_description, get_pr_comments
Issues get_linked_issue
Metadata Required by GitHub for all repository access (granted automatically)

get_file_commit_history, get_commit_diff, and get_blame use the Commits and GraphQL APIs, which are covered by the Contents and Metadata permissions above.

The token is captured in a closure and never appears in any tool signature, so it is never exposed to the LLM or included in generated schemas.

License

MIT

Metadata

Release files for github-context-tools 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for github-context-tools 0.1.0
File Size Uploaded Provenance Actions
github_context_tools-0.1.0.tar.gz 36.0 kB With provenance Details for github_context_tools-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for github-context-tools 0.1.0
File Interpreter ABI Platform Actions
github_context_tools-0.1.0-py3-none-any.whl Python 3 none any Details for github_context_tools-0.1.0-py3-none-any.whl

Total release size: 57.1 kB

Release files / github_context_tools-0.1.0.tar.gz

Download URL github_context_tools-0.1.0.tar.gz
Size 36.0 kB
Tags Source
SHA-256 checksum
How to use checksums
033658f1484993691277e788d68fdc52ad6f1538eadf652838d2d316b457cb24
BLAKE2b-256 checksum
How to use checksums
a405eebed10279412b6351d72ee84716b425dccb430df81d374e9c0903c9467b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 24, 2026.

Transparency log

Release files / github_context_tools-0.1.0-py3-none-any.whl

Download URL github_context_tools-0.1.0-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
edc873045cd71be10c5ac2af969ff3568421b7fe477e3377293a6fa50cf37f45
BLAKE2b-256 checksum
How to use checksums
15110a17e5897283476d7a213aee35b55e884d3669c745679d352e1a56938987
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 24, 2026.

Transparency log

Security for github-context-tools 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for github_context_tools-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page