Skip to main content

GitHub Code Search CLI (ghcs) - With Semantic Code Refinement

ghcs is a powerful command-line interface (CLI) tool for searching code on GitHub and downloading matched files. It allows you to search for code snippets using various filters such as language, user, repository, and path. Additionally, ghcs enables AI-powered code manipulation and refinement using large language models (LLMs) like Gemini. This makes it especially useful for developers working in CLI-based environments without a graphical user interface (e.g., remote servers).

Features

  • Search GitHub repositories for code using advanced filters (query, user, repository, language, path, etc.).
  • Download matched files directly from GitHub.
  • Extract, modify, enhance, and refine code using AI-powered transformations with models like Gemini.
  • User-friendly CLI interface designed for seamless integration into developer workflows.

Installation

To install ghcs, use pip:

pip install ghcs

For the latest updates, install directly from GitHub:

pip install git+https://github.com/hissain/ghcs.git

Usage

To use ghcs, you need a GitHub Personal Access Token, which can be set using the --token argument or the GITHUB_TOKEN environment variable. For AI-powered code manipulation with --remark, you must set the GEMINI_API_KEY in your environment.

Basic Search

ghcs 'search_term' --token YOUR_GITHUB_TOKEN
ghcs 'search_term' # When GITHUB_TOKEN is already set in .env

Search with Filters

ghcs 'search_term' --user 'username' --repo 'username/repo' --language 'python' --path 'llama/train' --token YOUR_GITHUB_TOKEN --max-results MAX_RESULT_COUNT

Download Matched Files

ghcs 'search_term' --download --token YOUR_GITHUB_TOKEN

AI-Powered Code Extraction & Refinement

To extract specific code sections or apply AI-driven transformations on downloaded files:

  • Use --remark to specify semantic modifications (requires --download).
  • The refined code can be printed to the console or saved using --output-file.

Example:

ghcs "LoRA def train()" --user hissain --download --remark "Extract the training function for LoRA with proper imports" --output-file extracted_code.py --verbose

Note: The GEMINI_API_KEY must be set in your environment variables or .env file to enable the --remark feature.

CLI Arguments

Positional Arguments

  • query: Search term as a string (required).

Optional Arguments

  • -l, --language : Filter by programming language.
  • -u, --user : Search within all repositories of a specific user.
  • -r, --repo : Search within a specific repository (e.g., username/repo).
  • -p, --path : Restrict search to a specific file path.
  • -t, --token : GitHub Personal Access Token (or set GITHUB_TOKEN environment variable).
  • -m, --max-result : Limit the number of search results.
  • -d, --download : Download matched files.
  • -dd, --download-dir : Specify the directory for downloaded files.
  • -v, --verbose : Enable verbose logging.
  • -r, --remark : AI instruction for refining downloaded files.
  • -o, --output-file : Output file to save refined code (default: print to console).
  • -e, --extensions : Specify file extensions to consider (e.g., .py,.js).
  • -h, --help : Show help menu and exit.

Example Commands

ghcs 'def train(' --language 'python' --user 'hissain' --path 'llama/train' --download --token YOUR_GITHUB_TOKEN --max-results 5
ghcs 'def train(' -l 'python' -p 'llama/train' -d -m 10
ghcs "def train()" --path llm --max-results 3 --download

With AI-powered refinement:

ghcs "def train LoRA" --path llm --download --remark "Extract only the forward pass function" --output-file forward_pass.py --max-results 5

API Keys

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author

Md. Sazzad Hissain Khan

Feel free to modify and enhance this project as needed!

Metadata

Release files for ghcs 1.0.1

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

Source distribution (sdist)

Source distribution for ghcs 1.0.1
File Size Uploaded
ghcs-1.0.1.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ghcs 1.0.1
File Interpreter ABI Platform
ghcs-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / ghcs-1.0.1.tar.gz

Download URL ghcs-1.0.1.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
13a4256dfb84ef2a3fcf8b08b7dba7f04a265ac94caee9302d181c66ec260c0b
BLAKE2b-256 checksum
How to use checksums
bc45f54bf3161dae3b60bf71ad779605accbb86b9ae1f73d42a9cfc38b5f1710
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.0

Release files / ghcs-1.0.1-py3-none-any.whl

Download URL ghcs-1.0.1-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e2e6bed8232153f02f54ab0e0040409b3df18fb136eda25338d9b2751e936789
BLAKE2b-256 checksum
How to use checksums
2b69ffec1e3c224a1b7713d98188e41a17cb536ac669a45ccc434b51fda05ad0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.0

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

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