Tickd.ai
← The Tickd Guide

Tutorials & Guides

How to Build a Local CLI Tool with Gemini 1.5 Pro to Auto-Generate Clean Changelogs from Git Diffs

Writing changelogs manually is a chore, and naive LLM wrappers produce corporate fluff. Here is how to build a precise local Python CLI that uses Gemini 1.5 Pro’s massive context window to turn raw git diffs into human-readable release notes.

Updated 11/19/2026

Why Most Automated Changelogs Are Utter Garbage

We have all seen those auto-generated release notes that look like they were written by a caffeinated corporate committee. They either lazily list every single micro-commit ("fixed typo", "tweaked padding") or they hallucinate grandiose features because the LLM got excited by a minor refactor.

Writing a changelog should not require manual pain, but outsourcing it to a generic AI agent usually yields flowery prose and zero actual context. To get a changelog that developers actually want to read, you need two things: raw git diff access to see exactly what changed, and an LLM that can ingest thousands of lines of code without choking on the context limits.

In this guide, we are building a local Python CLI tool that hooks into your git repository, extracts the exact diff between two branches or tags, and uses Gemini 1.5 Pro to output a clean, categorised, human-first changelog.

We are using Gemini 1.5 Pro because its massive native context window easily handles huge code diffs that would cause other models to stall or discard crucial details. Here is how to build it.

Which AI should I use for this?

Tickd is independent and not affiliated with any AI company.

The Architecture of a Clean Changelog Generator

Our CLI tool needs to run locally, query your local git history, filter out the noise, and send a structured payload to the Gemini API.

To make this actually useful, we will design the tool to: 1. Accept a target branch or comparison range (e.g., main...develop or v1.0.0...v1.1.0). 2. Extract the raw git log messages and the actual code diffs. 3. Filter out automated commits (like lockfile updates or dependency bumps) to keep the payload clean. 4. Send the cleaned code state to Gemini with a highly constrained system prompt. 5. Output a clean, markdown-formatted changelog structured by features, bug fixes, and breaking changes.

Step 1: Setting Up the Local Environment

First, make sure you have Python 3.10+ installed and a valid Gemini API key. If you run into issues setting up your developer environment or configuring your API access, check out our Gemini troubleshooting guides.

Create a new directory for your tool, set up a virtual environment, and install the official Google GenAI SDK:

`bash mkdir gemini-changelog-cli cd gemini-changelog-cli python3 -m venv venv source venv/bin/activate pip install google-genai click `

We are using click to handle the command-line interface cleanly and google-genai for access to the latest Gemini models.

Step 2: Extracting Git Logs and Diffs via Python

To understand what makes your codebase tick, the tool needs to interact directly with your git binary. We will use Python’s built-in subprocess module to execute git commands safely.

Create a file named changelog.py and write the helper functions to fetch the git commit messages and raw diffs:

`python import subprocess import sys

def run_git_command(args: list[str]) -> str: try: result = subprocess.run( ["git"] + args, capture_output=True, text=True, check=True ) return result.stdout.strip() except subprocess.CalledProcessError as e: print(f"Git command failed: {e.stderr}", file=sys.stderr) sys.exit(1)

def get_git_diff(range_str: str) -> str: # Get the commits for context commits = run_git_command(["log", "--oneline", range_str]) # Get the raw code changes, skipping binary files diff = run_git_command(["diff", "--no-color", "--ignore-all-space", range_str]) return f"=== COMMITS ===\n{commits}\n\n=== DIFF ===\n{diff}" `

This script fetches both the commit messages (which provide the high-level intent) and the raw diffs (which provide the ground truth). Feeding both into Gemini prevents the model from relying on misleading commit names.

Step 3: Crafting the System Prompt

This is where we avoid the classic AI traps. Left to its own devices, Gemini will start using exclamation marks, emojis, and marketing speak. We need to enforce strict rules using XML tags to segment our prompt instructions.

If you want to customise this structure or generate more specialised rules for your team's style guide, you can use our prompt generator tool to refine your prompt architecture.

Here is the system prompt we will embed in our CLI wrapper:

`python SYSTEM_PROMPT = """ You are an elite, technical technical writer and Principal Engineer. Your task is to analyse a git log and raw git diff to generate a highly accurate, concise, and clean changelog.

Guidelines: 1. Ignore trivial changes: lockfile updates, workspace config tweaks, formatted spacing, and minor comment updates must be ignored unless they are highly significant. 2. Do not use marketing jargon or fluff. Never write 'We are excited to announce' or 'This release brings powerful improvements'. State only the technical facts. 3. Group changes into the following headings: - ### Added (for new features) - ### Fixed (for bug fixes) - ### Changed (for performance tweaks, refactoring, or architectural shifts) - ### Breaking Changes (if any APIs or database schemas were modified in a non-backward-compatible way) 4. Under each heading, use bullet points describing the actual change, what part of the system it affected, and why it matters to developers using the codebase. 5. Keep your tone objective, engineering-focused, and direct. """ `

Step 4: Building the Complete CLI Tool

Now, let's assemble everything into a clean CLI interface. We will configure Gemini 1.5 Pro to return the response as clean Markdown. Make sure your GEMINI_API_KEY is exported in your terminal.

Add the following to your changelog.py:

`python import os import click from google import genai from google.genai import types

@click.command() @click.option('--range', '-r', required=True, help='The git commit/branch range to compare (e.g., v1.0.0...main)') @click.option('--output', '-o', default='CHANGELOG_DRAFT.md', help='Output file path') def main(range: str, output: str): """Generate a clean developer-centric changelog using Gemini 1.5 Pro.""" if not os.environ.get("GEMINI_API_KEY"): click.echo("Error: GEMINI_API_KEY environment variable is not set.", err=True) sys.exit(1)

click.echo(f"Fetching git data for range: {range}...") git_data = get_git_diff(range)

if not git_data.strip(): click.echo("No commits or diffs found for the specified range.") sys.exit(0)

click.echo("Sending diffs to Gemini 1.5 Pro (this might take a moment for large diffs)...") # Initialize the client client = genai.Client() try: response = client.models.generate_content( model='gemini-1.5-pro', contents=f"Generate a changelog based on the following git data:\n\n{git_data}", config=types.GenerateContentConfig( system_instruction=SYSTEM_PROMPT, temperature=0.2, # Lower temperature means less hallucination, more precision ) ) changelog_text = response.text with open(output, 'w', encoding='utf-8') as f: f.write(changelog_text) click.echo(f"✓ Changelog successfully written to {output}!") except Exception as e: click.echo(f"An error occurred while calling the Gemini API: {e}", err=True) sys.exit(1)

if __name__ == '__main__': main() `

Step 5: Testing It Locally

To make your CLI tool available globally across your machine, you can run it inside any of your git repositories. Set up an alias or install it locally:

`bash export GEMINI_API_KEY="your-actual-api-key"

Test it against your latest local commits python3 changelog.py --range HEAD~5...HEAD ```

Open up the generated CHANGELOG_DRAFT.md file. You will find that instead of a lazy copy-paste of your commit history, Gemini 1.5 Pro has mapped out exactly what your files are doing, grouped them intelligently, and stripped out the noisy refactor files and dependency bumps.

If you want to dive deeper into customising structured generation outputs using other local tools or different LLMs, check out our comparison of workflows at the Tickd.ai platform hubs.

tutorialsgeminipythongitautomation

Keep going

Build something with the prompt generator, decode the jargon in the glossary, or compare the tools on our platform deep-dives.