/ai-code-assistant-claude

🤖 AI-powered code assistant using Claude API - Analyze, explain, and generate code with streaming support

Primary LanguageTypeScript

AI Code Assistant with Claude API

An intelligent command-line tool that uses Claude AI to analyze, explain, and generate code.

Features

  • Code Analysis: Get detailed code quality assessments, bug detection, and optimization suggestions
  • Code Explanation: Understand complex code with clear, step-by-step explanations
  • Code Generation: Generate code from natural language descriptions
  • Interactive Chat: Have conversations with Claude about your code
  • Streaming Support: Real-time streaming responses for better UX

Prerequisites

Installation

  1. Clone the repository:
git clone <your-repo-url>
cd ai-code-assistant
  1. Install dependencies:
npm install
  1. Configure environment variables:
cp .env.example .env
# Edit .env and add your ANTHROPIC_API_KEY

Usage

Analyze Code

npm run dev analyze path/to/your/file.js

Explain Code

npm run dev explain path/to/your/file.ts

Generate Code

npm run dev generate "create a function to validate email addresses" --language typescript

Interactive Chat

# Regular response
npm run dev chat "How do I optimize this SQL query?"

# Streaming response
npm run dev chat "Explain async/await in JavaScript" --stream

Configuration

Edit .env file to customize:

  • ANTHROPIC_API_KEY: Your Anthropic API key (required)
  • MODEL: Claude model to use (default: claude-sonnet-4-5-20250929)
  • MAX_TOKENS: Maximum tokens per response (default: 4096)
  • LOG_LEVEL: Logging level (info, warn, error, debug)

Available Models

  • claude-sonnet-4-5-20250929: Best balance of speed and intelligence (recommended)
  • claude-opus-4-5-20250929: Maximum capability for complex tasks
  • claude-haiku-3.5: Fast and cost-effective

Development

# Run in development mode with auto-reload
npm run dev

# Build TypeScript
npm run build

# Run production build
npm start

# Run tests
npm test

# Lint code
npm run lint

# Format code
npm run format

Project Structure

ai-code-assistant/
├── src/
│   ├── index.ts           # CLI entry point
│   ├── api/
│   │   └── claude.ts      # Claude API client
│   ├── utils/
│   │   ├── config.ts      # Configuration management
│   │   └── logger.ts      # Logging utilities
├── .claude/               # Claude Code configuration
│   ├── CLAUDE.md         # Project context
│   ├── skills/           # Custom skills
│   └── commands/         # Slash commands
└── tests/                # Test files

Claude Code Integration

This project includes Claude Code configuration in .claude/:

  • Skills: Expert knowledge for Claude API integration
  • Commands: Custom slash commands like /analyze and /explain
  • Context: Project-specific guidelines in CLAUDE.md

Examples

Analyze a JavaScript file

npm run dev analyze src/utils/helper.js

Output:

Code Analysis:
==================================================

1. Code Quality: 8/10
   - Well-structured and readable
   - Good use of modern JavaScript features

2. Potential Issues:
   - Missing error handling in line 15
   - Potential null reference at line 23

3. Performance Optimizations:
   - Consider memoization for expensive calculations
   - Use Set instead of Array for uniqueness checks

...

Best Practices

  • Always validate inputs before sending to the API
  • Use streaming for longer responses
  • Monitor token usage to control costs
  • Implement rate limiting for production use
  • Keep API keys secure (never commit .env files)

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Commit changes: git commit -m 'feat: add new feature'
  4. Push to branch: git push origin feature/my-feature
  5. Open a Pull Request

License

MIT

Support

For issues and questions: