๐ง Claude AI for Code DebuggingMarch 12, 2026โ
Tests passing
Claude Fix Generator
An automation tool that uses Claude AI to scan a project directory for Python files, identify common coding issues, and auto-generate suggested fixes. It outputs a summary report and optionally applies fixes to a copy of the codebase.
What It Does
- Scans a project directory for Python files.
- Analyzes Python files for coding issues using Claude AI.
- Generates a JSON report with suggested fixes.
- Optionally applies fixes to a copy of the project directory.
Installation
1. Clone the repository:
git clone https://github.com/your-repo/claude-fix-generator.git
cd claude-fix-generator2. Install the required dependencies:
pip install -r requirements.txtUsage
Run the tool using the following command:
python claude_fix_generator.py --project-dir <path_to_project> --api-key <your_api_key> [--apply-fixes] [--output-dir <output_directory>] [--report-file <report_file>]Arguments
--project-dir: Path to the project directory containing Python files (required).--api-key: OpenAI API key for Claude AI (required).--apply-fixes: Apply fixes to a copy of the project (optional).--output-dir: Directory to save the fixed project (default:./fixed_project).--report-file: Path to save the JSON report (default:report.json).
Source Code
import os
import json
import argparse
from unittest.mock import Mock
class ClaudeFixGenerator:
def __init__(self, api_key):
self.api_key = api_key
self.client = Mock() # Mocking ChatCompletion for testing purposes
def scan_python_files(self, directory):
"""Scans the provided directory for Python files."""
python_files = []
for root, _, files in os.walk(directory):
for file in files:
if file.endswith('.py'):
python_files.append(os.path.join(root, file))
return python_files
def analyze_file(self, file_path):
"""Analyzes a single Python file for issues using Claude AI."""
try:
with open(file_path, 'r') as f:
code = f.read()
response = self.client.create(
model="claude-v1",
messages=[
{"role": "system", "content": "You are a Python code analysis assistant."},
{"role": "user", "content": f"Analyze the following Python code for issues and suggest fixes:\n{code}"}
]
)
return response['choices'][0]['message']['content']
except Exception as e:
return f"Error analyzing {file_path}: {e}"
def generate_report(self, directory):
"""Generates a report of issues and fixes for all Python files in the directory."""
python_files = self.scan_python_files(directory)
report = {}
for file_path in python_files:
analysis = self.analyze_file(file_path)
report[file_path] = analysis
return report
def apply_fixes(self, report, output_dir):
"""Applies fixes to a copy of the codebase based on the report."""
os.makedirs(output_dir, exist_ok=True)
for file_path, fixes in report.items():
try:
with open(file_path, 'r') as f:
original_code = f.read()
fixed_code = self.apply_fix_to_code(original_code, fixes)
relative_path = os.path.relpath(file_path, start=os.path.commonpath([file_path, output_dir]))
output_path = os.path.join(output_dir, relative_path)
os.makedirs(os.path.dirname(output_path), exist_ok=True)
with open(output_path, 'w') as f:
f.write(fixed_code)
except Exception as e:
print(f"Error applying fixes to {file_path}: {e}")
def apply_fix_to_code(self, original_code, fixes):
"""Applies fixes to the original code (mock implementation)."""
# This is a placeholder. In a real implementation, parse the fixes and apply them.
return original_code + "\n# Fixes applied: " + fixes
def save_report(self, report, output_file):
"""Saves the report to a JSON file."""
with open(output_file, 'w') as f:
json.dump(report, f, indent=4)
def main():
parser = argparse.ArgumentParser(description="Claude Fix Generator: Analyze and fix Python code issues.")
parser.add_argument('--project-dir', required=True, help="Path to the project directory containing Python files.")
parser.add_argument('--apply-fixes', action='store_true', help="Apply fixes to a copy of the project.")
parser.add_argument('--output-dir', default='./fixed_project', help="Directory to save the fixed project.")
parser.add_argument('--api-key', required=True, help="OpenAI API key for Claude AI.")
parser.add_argument('--report-file', default='report.json', help="Path to save the JSON report.")
args = parser.parse_args()
generator = ClaudeFixGenerator(api_key=args.api_key)
report = generator.generate_report(args.project_dir)
generator.save_report(report, args.report_file)
print(f"Report saved to {args.report_file}")
if args.apply_fixes:
generator.apply_fixes(report, args.output_dir)
print(f"Fixed project saved to {args.output_dir}")
if __name__ == "__main__":
main()Community
Downloads
ยทยทยท
Rate this tool
No ratings yet โ be the first!
Details
- Tool Name
- claude_fix_generator
- Category
- Claude AI for Code Debugging
- Generated
- March 12, 2026
- Tests
- Passing โ
- Fix Loops
- 2
Quick Install
Clone just this tool:
git clone --depth 1 --filter=blob:none --sparse \ https://github.com/ptulin/autoaiforge.git cd autoaiforge git sparse-checkout set generated_tools/2026-03-12/claude_fix_generator cd generated_tools/2026-03-12/claude_fix_generator pip install -r requirements.txt 2>/dev/null || true python claude_fix_generator.py