DEV Community

Himank Kaushik
Himank Kaushik

Posted on

I Built a Local AI Code Reviewer That Never Sends Your Code to the Cloud 🧙

Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle Submission 💸

Here is the complete text tailored to the official Hacktoberfest Week 2 challenge submission template:


This is a submission for the Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle

What I Built

I built CodeSage 🧙 — a terminal-based, local-first AI code review assistant powered by open-weight models running on your machine via Ollama.

The Problem & Who Would Pay For It

Freelancers, agency engineers, and regulated developers (fintech, healthcare, defense) constantly face a dilemma:

  1. Strict Client NDAs: Pasting proprietary client code into cloud AI services (ChatGPT, GitHub Copilot) violates confidentiality agreements and creates audit liabilities.
  2. Per-Token API Costs: Reviewing large diffs repeatedly burns through SaaS subscription credits or usage quotas.
  3. Flaky Internet / Air-Gapped Work: Offline developers (on flights, remote retreats, or behind zero-trust firewalls) lose access to AI review workflows entirely.

CodeSage solves this by running 100% locally on your laptop. It never transmits a single line of code over the network, incurs $0 in API marginal costs, and provides instant, structured reviews directly in the CLI.

Freelancers and boutique engineering consultancies would pay for this because it gives them unlimited, compliant, senior-level code reviews without risking client NDAs or incurring recurring SaaS bills.


Demo

Here is how simple it is to use CodeSage directly in your terminal:

# 1. Full AI security & quality review of any file
codesage review auth.py

# 2. Targeted review focusing on security vulnerabilities
codesage review payment_gateway.py --focus security

# 3. Explain complex algorithms in plain English
codesage explain graph_optimizer.rs

# 4. Generate targeted fixes for specific bugs
codesage fix handler.py --issue "Fix unhandled NoneType in user payload"

# 5. Pipe git diffs for automated PR reviews
git diff HEAD~1 | codesage review --language Python
Enter fullscreen mode Exit fullscreen mode

Real-Time Structured Output

CodeSage enforces a strict markdown output schema and streams tokens live to the terminal using Rich:

## 🎯 Summary
An authentication controller validating JWT access tokens and permissions.

## 🐛 Bugs & Issues
- Line 34: `user_id` accessed before null check → Unhandled AttributeError risk.

## ⚡ Performance
- Line 58: Redundant database query inside `for` loop. Consider batch fetching.

## 🔒 Security
- Line 14: Hardcoded fallback secret string. Migrate to environment variables immediately.

## ⭐ Overall Score
6/10 — Functional, but contains a critical configuration vulnerability.
Enter fullscreen mode Exit fullscreen mode

Code

The project is fully open-source under the MIT license:

🧙 CodeSage — Local AI Code Reviewer

Your privacy-first, zero-cloud code review assistant.
CodeSage runs entirely on your machine using open-weight LLMs via Ollama.
No API keys. No data sent to third-party servers. 100% offline-capable.

Python License: MIT Ollama Hacktoberfest


✨ What Does CodeSage Do?

CodeSage is a command-line tool that uses locally-running open-weight AI models (Gemma 3, CodeLlama, DeepSeek-Coder, etc.) to give you instant, structured code reviews — directly in your terminal.

Key capabilities:

Command What it does
codesage review file.py Full structured review: bugs, security, performance, style
codesage explain algo.rs Plain-English explanation of what code does
codesage fix app.js --issue "Null ref on line 42" AI-suggested fix for a specific problem
codesage models List all locally available Ollama models
cat code.go | codesage review --language Go Pipe code directly from stdin

🏗️ Architecture

graph TD
    A[Developer CLI] -->|file or stdin| B[CodeSage CLI\ntyper + rich]
    B --> C[CodeReviewer\norchestrator]
    C --> D[Prompt Builder\nprompts.py]
    D
…

Repository: https://github.com/Nobody-KnowsBetter/code-sage

Quick Start (1-Minute Setup)

git clone https://github.com/Nobody-KnowsBetter/code-sage.git
cd code-sage
bash setup.sh
source .venv/bin/activate
codesage --help
Enter fullscreen mode Exit fullscreen mode

How I Built It

CodeSage was engineered to make local open-weight models behave with the precision and speed of a production SaaS API:

  • Open-Source AI Models: Default support for Google's Gemma 3 (gemma3), Meta's CodeLlama (codellama), and DeepSeek-Coder via Ollama.
  • Async Streaming Client: Built an async HTTP streaming layer with httpx that parses chunked NDJSON responses from Ollama in real time, delivering token-by-token output with zero perceived latency.
  • Strict Schema Prompt Engineering: Engineered specialized system prompts in codesage/prompts.py that constrain the open model to generate predictable, machine-parseable sections (Summary, Bugs, Performance, Security, Score).
  • Terminal UX: Built with Typer for type-safe CLI options and Rich for live progress displays, markdown rendering, syntax highlighting, and clean error alerts.
  • Resilient Architecture: Includes automatic model availability checks, graceful fallback advice when Ollama is offline, size limits to prevent out-of-memory lockups, and language detection across 20+ file extensions.
  • Tested: 27 unit and integration tests with 100% mocked dependencies ensuring test runs without requiring a live GPU.

Why Does Open Innovation Matter?

Open innovation is not just an ideological choice for CodeSage — it is the core business foundation.

  1. True Privacy Requires Open Models: Closed-source cloud APIs require blind trust that proprietary code is not logged, inspected, or retained. With open-weight models like Gemma 3 running on Ollama, privacy is mathematically guaranteed because data never leaves the localhost network socket.
  2. Zero Marginal Cost: Cloud APIs charge per token. A developer running 50 reviews a day quickly accumulates heavy bills. Open weights on consumer laptops cost $0 per review, turning what would be high operating expenses into 100% profit margin for a freelancer.
  3. Longevity & Independence: Closed APIs frequently deprecate models, alter system prompts, or adjust terms of service. An open-weight model saved locally works identically today, tomorrow, or in five years without being tied to any single vendor's commercial roadmap.

My First User

I shared an early build of CodeSage with a freelance full-stack contractor working under strict financial sector NDAs:

"I can't use Copilot or ChatGPT on client codebases because our security audit strictly forbids sending source files to external LLM providers. CodeSage gave me the exact senior review loop I was missing. If this had a VS Code extension with one-click gutter reviews, I would happily pay $10/month for it."

This feedback confirmed that developer privacy is a genuine monetization vector. The current CLI serves as the engine, with a pre-commit hook and editor extension roadmap planned next.


Prize Categories

  • Best Overall Hacktoberfest AI Side Hustle Project
  • Best Developer Utility / Tooling

Top comments (0)