CodeGPT

repository·main·Indexed 23 days ago

https://github.com/appleboy/codegpt

A Go-based CLI tool that leverages AI models to automate git commit message generation and code reviews. It integrates into the Git workflow via hooks and supports various AI providers, custom prompt templates, and multi-language translation for commit messages and reviews.

Tokens
8.5K
Snippets
21
Records
73
Agent score
80%

What's inside CodeGPT

  1. Overview of CodeGPT features

    main

    CodeGPT is a CLI tool written in Go that uses AI (such as ChatGPT, Gemini, Anthropic, etc.) to:

    Key capabilities:

    • Multi-provider support: Azure OpenAI, OpenAI, Gemini, Anthropic, Ollama, Groq, and OpenRouter.
    • Customizable context: Specify the number of context lines (default: 3) for diff generation.
    • Diff filtering: Supports exclusion patterns for git diff.
    • Localization: Translate commit messages into en, zh-tw, or zh-cn.
    • Network support: Supports SOCKS or custom HTTP proxies.
    • Real-time feedback: Supports streaming output to show generated tokens.
  2. Use API Key Helper to dynamically fetch credentials

    main

    Instead of storing API keys in plaintext, you can use openai.api_key_helper to run a shell command that retrieves the key from a password manager (like 1Password or Bitwarden) or a cloud secret manager (AWS, Google Cloud).

    CodeGPT caches the result in ~/.config/codegpt/.cache/ with 0600 permissions. The cache is refreshed based on the openai.api_key_helper_refresh_interval setting (default 900s).

    Priority Order for API Keys:

    1. openai.api_key_helper (if configured)
    2. openai.api_key (static config)
    3. OPENAI_API_KEY (environment variable)
  3. Use API Key Helper for Dynamic Credentials

    main

    Instead of storing keys in plaintext, you can use openai.api_key_helper to run a shell command that retrieves your key from a password manager or secret service. CodeGPT will cache the result in ~/.config/codegpt/.cache/ with 0600 permissions.

    Priority Order for API Keys:

    1. openai.api_key_helper (if configured)
    2. openai.api_key (static configuration)
    3. OPENAI_API_KEY environment variable

    Examples:

    1Password CLI:

    codegpt config set openai.api_key_helper "op read op://vault/openai/api_key"

    AWS Secrets Manager:

    codegpt config set openai.api_key_helper "aws secretsmanager get-secret-value --secret-id openai-key --query SecretString --output text"

    Google Cloud Secret Manager:

    codegpt config set openai.api_key_helper "gcloud secrets versions access latest --secret=openai-api-key"

    Refresh Interval Configuration:

    # Refresh every 5 minutes
    codegpt config set openai.api_key_helper_refresh_interval 300
    
    # Disable caching (fetch every time)
    codegpt config set openai.api_key_helper_refresh_interval 0
  4. Configure OpenRouter API Service

    main

    To use OpenRouter, set the provider to openai and update the base_url. You can also set custom headers to include your application in OpenRouter rankings.

    Basic Configuration:

    codegpt config set openai.provider openai
    codegpt config set openai.base_url https://openrouter.ai/api/v1
    codegpt config set openai.api_key sk-or-v1-xxxxxxxxxxxxxxxx
    codegpt config set openai.model google/gemini-3-flash-preview

    With Ranking Headers:

    codegpt config set openai.headers "HTTP-Referer=https://github.com/appleboy/CodeGPT X-Title=CodeGPT"
  5. Configure Azure OpenAI Service

    main

    To use Azure OpenAI, update your configuration with your specific endpoint, key, and model deployment name.

    codegpt config set openai.provider azure
    codegpt config set openai.base_url https://xxxxxxxxx.openai.azure.com/
    codegpt config set openai.api_key xxxxxxxxxxxxxxxx
    codegpt config set openai.model xxxxx-gpt-4o
  6. Perform Code Reviews

    main

    Use the codegpt review command to analyze staged changes and generate a code review summary. This includes identifying security vulnerabilities, error handling issues, and input validation needs.

    Flags:

    • --lang <language>: Translates the review into Traditional Chinese (zh-tw), Simplified Chinese (zh-cn), or Japanese (ja).
    • --stream: Enables real-time streaming of the review output.
  7. Switch to OpenRouter API Service

    main

    To use OpenRouter, set the provider to openai, update the base_url to OpenRouter's endpoint, and provide your OpenRouter API key. You can also set custom headers to appear in OpenRouter rankings.

    codegpt config set openai.provider openai
    codegpt config set openai.base_url https://openrouter.ai/api/v1
    codegpt config set openai.api_key sk-or-v1-xxxxxxxxxxxxxxxx
    codegpt config set openai.model google/gemini-3-flash-preview
    
    # Optional: Set headers for OpenRouter rankings
    codegpt config set openai.headers "HTTP-Referer=https://github.com/appleboy/CodeGPT X-Title=CodeGPT"