explainit
v2.0.5
Published
π§ AI CLI that tests code comprehension on git diffs, explains AI changes, and writes commit messages
Maintainers
Readme
Understand your code before you ship it.
Quiz your staged Git changes, understand AI-generated code, scan files, and generate clear commit messages.
A lightweight developer CLI that adds an understanding check to your Git workflow. It inspects staged diffs, scans files for line statistics and risk metrics, asks a quick multiple-choice question in the terminal, and helps developers review AI-generated code before committing.
Table of contents
- The problem
- Features
- Requirements
- Quick start
- How it works
- Usage
- Command reference
- Tracking your progress
- Inspecting and scanning files
- API key and privacy
- Project structure
- Technology stack
- Troubleshooting
- Development
- Contributing
- Roadmap
- Issues and support
- License
The problem
AI coding tools can generate working code quickly, but working code is not always code you fully understand. When a change causes problems later, it can be hard to remember why a particular implementation was added.
explainit helps you pause and review your changes before they become part of your codebase.
Features
- Quiz staged changes: generate a short multiple-choice question from your staged Git diff.
- Explain code changes: get a readable summary of changes, key decisions, and potential concerns.
- Generate commit messages: create a commit message from the staged diff.
- Scan and inspect files: preview target files, view line statistics, and assess risk levels before committing (
explainit scan). - Track quiz progress: view previous quiz results and your score history.
The quiz is a check on your own understanding. It does not replace tests, code review, or security checks.
Requirements
- Node.js and npm (see the Node.js badge above for the supported version)
- Git
- A Gemini API key from Google AI Studio
Quick start
Follow these four steps to set up explainit in a Git repository.
Step 1: Install explainit
Install the package globally with npm:
npm install -g explainitCheck that the command is available:
explainit --helpStep 2: Get a Gemini API key
- Open Google AI Studio and sign in with your Google account.
- Select Create API key in new project.
- Copy the generated key.
Gemini API access, quotas, and pricing vary by account and may change. Check Google's current terms in AI Studio before use.
Step 3: Connect your API key
Run the setup command and follow the prompts:
explainit setupExample output:
Setup β Gemini API key
--------------------------------------------
Get your API key at:
https://aistudio.google.com/apikey
Steps:
1. Sign in with Google
2. Select "Create API key in new project"
3. Copy and paste the key below
Paste your Gemini API key: [input hidden]
API key saved.
You're all set β run explainit install to connect it to Git.The key is stored locally in ~/.explainit/config.json.
Security note: the key is stored as plain text. Keep the file private (for example,
chmod 600 ~/.explainit/config.jsonon macOS/Linux) and never share it in logs, screenshots, or issue reports.
Step 4: Connect explainit to Git
From the repository where you want the automatic quiz, run:
explainit installExample output:
Installing Git hook
--------------------------------------------
Git hook installed
run-quiz.js created
Every Git commit can now trigger a quick understanding check.You are ready to go. Stage your changes and commit as usual:
git add .
git commit -m "describe your changes"During the pre-commit step, explainit asks a short question. Answer it, or enter s to skip. The hook does not block your commit.
To bypass all Git hooks for a single commit, use Git's standard flag:
git commit --no-verify -m "describe your changes"How it works
- You stage changes with
git add. explainitreads the staged diff usinggit diff --cached.- If the Git hook is installed, a short quiz is shown during the pre-commit step.
- You answer the question or skip it, and the commit proceeds.
The quiz may skip small changes and documentation-only edits.
Install explainit
|
v
Configure the Gemini API key
|
v
Install the Git hook in your repository
|
v
Make changes and stage files
|
v
Commit your changes
|
v
explainit reviews the staged diff
|
v
Answer the quiz or skip it
|
v
The commit proceedsUsage
You can run commands directly instead of relying only on the Git hook.
Explain your staged changes:
explainit explainExplain a specific file:
explainit explain src/auth.jsGenerate a commit message from the staged diff:
explainit msgRun a quiz on your staged changes:
explainit quizRun a quiz on a specific file:
explainit quiz src/auth.jsView your quiz history:
explainit scorePreview and scan a file:
explainit scan src/auth.jsCommand reference
| Command | Alias | Description |
| ------------------------ | ----- | -------------------------------------------------------------- |
| explainit setup | n/a | Configure your Gemini API key. |
| explainit install | n/a | Install the Git hook for the current repository. |
| explainit explain [file] | exp | Explain staged changes or a specific file, including key decisions and potential risks. |
| explainit msg | m | Generate a commit message from the staged diff. |
| explainit quiz [file] | q | Quiz yourself on staged changes or a specified file. |
| explainit score | sc | View quiz results, history, and streak information. |
| explainit scan <file> | s | Preview a file, inspect line statistics, additions, and risk metrics. |
Run explainit --help to see the commands and aliases available in your installed version.
Tracking your progress
explainit scoreThe score command shows your quiz history and progress, including correct and incorrect answers and streak information.
Inspecting and scanning files
Inspect any source file before staging or committing:
explainit scan src/auth.jsExample terminal output:
π§ explainit Β· understand your code Β· v2.0.4
βΈ file info
ββββββββββββββββββββββββββββββββββββββββββββ
π path src/auth.js
π lines 85
πΎ size 2.8 kb
βΈ preview
ββββββββββββββββββββββββββββββββββββββββββββ
1 β import jwt from "jsonwebtoken";
2 β import { db } from "../config/db.js";
3 β
...
... 65 more lines
β scan complete β explainit explain src/auth.jsThe scan command previews a target file with line statistics, addition metrics, and quick risk level insights before committing or pushing.
API key and privacy
explainit uses a bring-your-own-key model: each user configures their own Gemini API key.
- Your API key is stored locally in
~/.explainit/config.json. - AI-powered features may send staged diffs or file content to the Gemini API to generate questions, explanations, or commit messages.
- Avoid using the tool on confidential or sensitive code unless your organization's policies allow sending that content to the configured AI provider.
- Never share your API key in logs, screenshots, or issue reports.
- Gemini API quotas and pricing can change. Consult Google's current documentation.
Project structure
explainit/
βββ bin/
β βββ explainit.js # CLI entry point and commands
βββ lib/
β βββ ai.js # Gemini API integration
β βββ diff.js # Staged Git diff processing
β βββ quiz.js # Quiz prompts and answer checking
β βββ scores.js # Quiz history and streak tracking
βββ package.jsonTechnology stack
| Technology | Purpose | | ------------------------------------------------ | ----------------------------------------------- | | Node.js | JavaScript runtime | | Commander.js | Command-line interface | | Gemini API | Quiz questions, explanations, and commit messages | | Chalk | Terminal output styling | | Ora | Terminal spinner |
Troubleshooting
explainit is not recognized
Reinstall the package:
npm install -g explainitRestart your terminal and run explainit --help. If the command is still unavailable, check that npm's global executable directory is in your PATH.
The API key is missing or invalid
Run setup again:
explainit setupCheck that the key was copied correctly and that your Gemini API access is enabled.
The quiz does not reflect my changes
The quiz uses staged changes. Check what is staged and add the files you want to review:
git status
git add <file>
git diff --cached
explainit quizThe Git hook does not run
Run the install command from the repository where you want the hook enabled:
explainit installThen check your Git hook configuration and read any messages printed by explainit.
Development
To work on the project locally:
git clone https://github.com/shekharrs/explainit.git
cd explainit
npm install
npm linknpm link links your local checkout so you can run the development version as a global command. Verify it with:
explainit --helpContributing
Contributions, bug reports, and feature requests are welcome.
Fork the repository.
Create a feature branch:
git checkout -b feature/your-featureMake and test your changes.
Commit your changes:
git commit -m "describe your changes"Push the branch and open a pull request.
When reporting a bug, include your operating system, Node.js version, the command you ran, and the relevant error output. Remove API keys and sensitive code before sharing logs.
Roadmap
- [ ] Model Context Protocol (MCP) support for AI coding environments
- [ ] Visual Studio Code extension
- [ ] Team leaderboard
- [ ] Optional strict mode with additional commit controls
Issues and support
Found a bug or have a feature request? Open an issue on GitHub.
License
MIT. See the LICENSE file.
Built for developers who want to understand the code they ship.
