This solution implements a Python CLI that blends static analysis with optional LLM review. It scans a file or directory, runs local analyzers when available, and produces a report in terminal, markdown, json, or html formats.
- A modular Python package under
src/codereviewgpt/. - CLI entrypoint with
analyzeandconfig-examplecommands. - Static analysis integration via
pylint,bandit,flake8, andradon(best-effort). - Internal checks for long files/functions, TODO tags, missing docstrings, and syntax errors.
- LLM client for Claude or OpenAI with JSON response parsing.
- Report formatters for terminal, markdown, json, and html.
- Lightweight tests covering config, formatter JSON, and internal analyzer checks.
code-review-gpt/
??? src/
? ??? codereviewgpt/
? ??? __init__.py
? ??? analyzer.py
? ??? cli.py
? ??? config.py
? ??? formatters.py
? ??? llm_client.py
? ??? models.py
??? tests/
? ??? test_analyzer.py
? ??? test_config.py
? ??? test_formatters.py
??? requirements.txt
??? setup.py
??? README.md
- CLI parses arguments and loads configuration.
- Analyzer runs internal checks and external static tools.
- LLM client is called only if enabled and a key exists.
- Formatter renders a report in the requested output format.
- Use best-effort integrations so the tool still works without every static tool installed.
- Keep LLM optional and guarded by presence of API keys.
- Return JSON from LLM so results can be parsed and merged.
- Provide simple defaults with a JSON config override path.
# Analyze a directory
codereview analyze .
# Markdown report
codereview analyze . --format markdown --output report.md
# JSON report without LLM
codereview analyze script.py --format json --no-llm
# Generate a config file
codereview config-example > config.jsonThe CLI can load a JSON config file. Example fields:
{
"language": "python",
"severity_threshold": "LOW",
"output_format": "terminal",
"provider": "claude",
"llm_enabled": true,
"max_lines_per_chunk": 500,
"max_file_lines": 800,
"max_function_lines": 120,
"todo_tags": ["TODO", "FIXME", "HACK"],
"file_exclude_globs": [".venv", "__pycache__", "node_modules"],
"tool_paths": {}
}
- Install
pylint,bandit,flake8, andradonfor fuller static analysis. - Set
OPENAI_API_KEYorANTHROPIC_API_KEYto enable LLM calls. - Use
--no-llmto avoid API calls entirely.