Skip to content

codacy-acme/guardrails-claudecode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Claude Code + Codacy Setup Script

This script automates the installation and configuration of Claude Code with Codacy integration, setting up a complete AI-powered code analysis workflow with guardrails for code quality and security.

Repository

🔗 GitHub: codacy-acme/guardrails-claudecode

About This Project

This project provides guardrails for Claude Code by integrating Codacy's comprehensive code analysis capabilities. It ensures that AI-generated code meets quality standards and security requirements automatically.

Key Benefits

  • Automated Quality Assurance: Every AI code change is immediately analyzed
  • Security First: Dependency vulnerabilities are caught before they reach production
  • Multi-Language Support: Works with JavaScript, Python, Java, and many other languages
  • Git Provider Agnostic: Supports GitHub, Bitbucket, and GitLab repositories

What This Script Does

The setup script automates the complete integration process:

  1. Installs Claude Code - The AI-powered command line tool from Anthropic
  2. Configures Codacy Integration - Sets up the Codacy MCP (Model Context Protocol) server
  3. Creates Configuration Files - Generates CLAUDE.md with behavior rules for AI interactions
  4. Environment Setup - Configures shell environment variables for seamless operation

Prerequisites

  • Node.js and npm - Required for Claude Code installation
  • Codacy Account - You'll need a Codacy account and API token
  • Git Repository - For repository analysis features
  • macOS or Linux - Windows support may require adjustments

Installation

Quick Start

# Clone the repository
git clone https://github.com/codacy-acme/guardrails-claudecode.git
cd guardrails-claudecode

# Make the script executable and run it
chmod +x claude-codacy-setup.sh
./claude-codacy-setup.sh

Direct Download

# Download and run the script directly
curl -O https://raw.githubusercontent.com/codacy-acme/guardrails-claudecode/main/claude-codacy-setup.sh
chmod +x claude-codacy-setup.sh
./claude-codacy-setup.sh

Manual Installation

  1. Clone the repository:
    git clone https://github.com/codacy-acme/guardrails-claudecode.git
    cd guardrails-claudecode
  2. Make it executable:
    chmod +x claude-codacy-setup.sh
  3. Run the script:
    ./claude-codacy-setup.sh

Setup Process

1. Codacy Token Setup

When prompted, you can either:

  • Enter your Codacy Account Token - The script will configure it automatically
  • Press Enter to skip - If you already have the token configured elsewhere

To get your Codacy token:

  1. Log into your Codacy account
  2. Go to Account Settings → API Tokens
  3. Generate a new Account Token
  4. Copy the token for use in the script

2. Shell Configuration

The script automatically detects your shell and updates the appropriate configuration file:

  • macOS: ~/.zshrc
  • Linux with zsh: ~/.zshrc
  • Linux with bash: ~/.bashrc

3. Post-Installation

After the script completes:

# Restart your terminal OR reload your shell configuration
source ~/.zshrc  # or ~/.bashrc

Features

Automatic Code Analysis

Once configured, Claude Code will automatically:

  • Analyze edited files using Codacy's quality checks
  • Scan for security vulnerabilities when dependencies are added
  • Propose and apply fixes for identified issues
  • Support multiple Git providers (GitHub, Bitbucket, GitLab)

AI Behavior Rules

The generated CLAUDE.md file contains rules that make Claude Code:

  • Run analysis after every file edit
  • Perform security scans after dependency installations
  • Dynamically detect Git repository information
  • Handle 404 errors by offering repository setup

Configuration Files Created

Environment Variables

export CODACY_ACCOUNT_TOKEN=your_token_here

MCP Configuration

claude mcp add codacy npx -- -y @codacy/codacy-mcp --env CODACY_ACCOUNT_TOKEN=$CODACY_ACCOUNT_TOKEN

CLAUDE.md Rules

Comprehensive AI behavior configuration including:

  • File analysis triggers
  • Security scanning protocols
  • Git provider mapping
  • Error handling procedures

Usage Examples

Basic Code Analysis

# Claude will automatically analyze files after editing
claude "Fix the code quality issues in my JavaScript files"

Security Scanning

# Automatically scans for vulnerabilities after package installation
claude "Add express to my project and check for security issues"

Repository Setup

# Handles repository setup if not found in Codacy
claude "Analyze this repository for code quality issues"

Troubleshooting

Common Issues

npm not found

# Install Node.js and npm first
curl -fsSL https://nodejs.org/dist/v18.17.0/node-v18.17.0-linux-x64.tar.xz | tar -xJ
export PATH=$PATH:/path/to/node/bin

Claude Code not in PATH

# Restart terminal or reload shell configuration
source ~/.zshrc

Codacy API Token Issues

  • Verify token is correct in Codacy dashboard
  • Check token permissions include repository access
  • Ensure token is properly exported in shell

Repository Not Found (404)

  • Claude will offer to set up the repository in Codacy
  • Make sure you have admin access to the repository
  • Verify the repository URL is correct

Debug Mode

Run with debug output:

bash -x ./claude-codacy-setup.sh

Advanced Configuration

Custom Shell Configuration

If using a non-standard shell setup:

# Edit the script to point to your custom config file
SHELL_CONFIG="$HOME/.your-custom-config"

Multiple Codacy Tokens

For multiple organizations:

# Set different tokens for different projects
export CODACY_ACCOUNT_TOKEN_ORG1=token1
export CODACY_ACCOUNT_TOKEN_ORG2=token2

Git Provider Mapping

The script supports automatic detection of:

  • GitHubgh
  • Bitbucketbb
  • GitLabgl

Security Considerations

  • Token Storage: Tokens are stored in shell configuration files
  • Permissions: Ensure appropriate file permissions on config files
  • Network: Script downloads packages from npm and Codacy
  • Execution: Review script contents before running with elevated privileges

Support

Documentation

Issues

For issues with:

  • This Project: Open an issue on GitHub
  • Claude Code: Check Anthropic's support documentation
  • Codacy Integration: Verify API token and repository access
  • Script Problems: Check shell configuration and permissions

Contributing

We welcome contributions to improve the guardrails integration! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

License

Please review and understand the code before execution in production environments.


Note: This script requires an active Codacy account and appropriate API permissions. Ensure you have the necessary access before running the setup.

About

Helper script to setup Codacy Guardrails with Claude Code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages