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.
🔗 GitHub: codacy-acme/guardrails-claudecode
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.
- 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
The setup script automates the complete integration process:
- Installs Claude Code - The AI-powered command line tool from Anthropic
- Configures Codacy Integration - Sets up the Codacy MCP (Model Context Protocol) server
- Creates Configuration Files - Generates CLAUDE.md with behavior rules for AI interactions
- Environment Setup - Configures shell environment variables for seamless operation
- 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
# 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
# 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
- Clone the repository:
git clone https://github.com/codacy-acme/guardrails-claudecode.git cd guardrails-claudecode
- Make it executable:
chmod +x claude-codacy-setup.sh
- Run the script:
./claude-codacy-setup.sh
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:
- Log into your Codacy account
- Go to Account Settings → API Tokens
- Generate a new Account Token
- Copy the token for use in the script
The script automatically detects your shell and updates the appropriate configuration file:
- macOS:
~/.zshrc
- Linux with zsh:
~/.zshrc
- Linux with bash:
~/.bashrc
After the script completes:
# Restart your terminal OR reload your shell configuration
source ~/.zshrc # or ~/.bashrc
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)
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
export CODACY_ACCOUNT_TOKEN=your_token_here
claude mcp add codacy npx -- -y @codacy/codacy-mcp --env CODACY_ACCOUNT_TOKEN=$CODACY_ACCOUNT_TOKEN
Comprehensive AI behavior configuration including:
- File analysis triggers
- Security scanning protocols
- Git provider mapping
- Error handling procedures
# Claude will automatically analyze files after editing
claude "Fix the code quality issues in my JavaScript files"
# Automatically scans for vulnerabilities after package installation
claude "Add express to my project and check for security issues"
# Handles repository setup if not found in Codacy
claude "Analyze this repository for code quality 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
Run with debug output:
bash -x ./claude-codacy-setup.sh
If using a non-standard shell setup:
# Edit the script to point to your custom config file
SHELL_CONFIG="$HOME/.your-custom-config"
For multiple organizations:
# Set different tokens for different projects
export CODACY_ACCOUNT_TOKEN_ORG1=token1
export CODACY_ACCOUNT_TOKEN_ORG2=token2
The script supports automatic detection of:
- GitHub →
gh
- Bitbucket →
bb
- GitLab →
gl
- 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
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
We welcome contributions to improve the guardrails integration! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
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.