This guide explains how to use Code Guardian Studio (CCG) inside Claude Code for AI-assisted code analysis and refactoring.
- Prerequisites
- Setting Up the MCP Server
- Connecting Claude Code to Your Repository
- Example Prompts
- How Claude Uses CCG Tools
- Best Practices
- Troubleshooting
Before setting up CCG with Claude Code, ensure you have:
| Software | Minimum Version | Purpose |
|---|---|---|
| Node.js | 18.0.0+ | Runtime environment |
| npm | 8.0.0+ | Package manager |
| Claude Desktop or Claude Code | Latest | AI assistant with MCP support |
# Install Code Guardian Studio globally
npm install -g codeguardian-studio
# Verify installation
ccg --versionCCG runs as an MCP (Model Context Protocol) server that Claude Code connects to. There are two ways to set this up:
Run the init command in your project:
cd /path/to/your/project
ccg initThis creates .mcp.json with the correct server configuration.
Add CCG to your Claude Code MCP settings:
For Claude Desktop (macOS/Linux):
Edit ~/.config/claude/claude_desktop_config.json:
{
"mcpServers": {
"code-guardian": {
"command": "npx",
"args": ["-y", "codeguardian-studio"],
"env": {
"CCG_PROJECT_ROOT": "/path/to/your/project"
}
}
}
}For Claude Desktop (Windows):
Edit %APPDATA%\Claude\claude_desktop_config.json:
{
"mcpServers": {
"code-guardian": {
"command": "npx",
"args": ["-y", "codeguardian-studio"],
"env": {
"CCG_PROJECT_ROOT": "C:\\path\\to\\your\\project"
}
}
}
}| Variable | Required | Description |
|---|---|---|
CCG_PROJECT_ROOT |
Yes | Path to your project root |
CCG_LOG_LEVEL |
No | Logging level: debug, info, warn, error |
CCG_LICENSE_KEY |
No | License key for Team tier features |
Open your repository folder in Claude Code or Claude Desktop.
Ask Claude to check the connection:
"Can you see the Code Guardian Studio tools? List them for me."
Claude should respond with available CCG tools like code_scan_repository, code_metrics, code_hotspots, etc.
If CCG hasn't been initialized:
"Initialize Code Guardian Studio in this project."
Use natural language to interact with CCG through Claude. No JSON or technical tool schemas needed.
Quick health check:
"Use Code Guardian Studio to scan this repository and show me the top hotspots."
Detailed analysis:
"Analyze the code quality of this project. Show me which files have the highest complexity."
Specific directory:
"Scan only the src/api folder and identify files that need refactoring."
Full optimization:
"Run the code optimization workflow and generate a report."
Targeted optimization:
"Run the code optimization workflow on the payments service only."
With specific focus:
"Analyze the authentication module for complexity issues and suggest improvements."
Generate report:
"Create a code optimization report for this repository."
View metrics:
"Show me the code metrics for the top 10 largest files."
Track progress:
"Compare the current code quality with the last optimization session."
List repositories:
"Show me all configured repositories in this multi-repo setup."
Analyze specific repo:
"Scan the frontend repository and show me the hotspots."
When you ask Claude to analyze your code, it automatically:
- Understands your request - Interprets natural language to determine what analysis you need
- Selects appropriate tools - Chooses CCG tools like
code_scan_repository,code_metrics, orcode_hotspots - Executes analysis - Runs the tools with correct parameters
- Presents results - Formats the output in a readable way
- Write JSON tool calls
- Memorize tool names or parameters
- Understand the MCP protocol
- Copy-paste code into chat
- Tool selection and orchestration
- Parameter configuration
- Error handling and retries
- Result formatting and explanation
| Scenario | Approach | Command/Prompt |
|---|---|---|
| Daily check | Quick scan | "Quick health check on this repo" |
| Before PR | Targeted analysis | "Check the files I changed for issues" |
| Sprint planning | Full optimization | "Run full optimization workflow" |
| Tech debt review | Detailed report | "Generate comprehensive tech debt report" |
Use CLI for automation and CI/CD:
# In CI pipeline
ccg code-optimize --report --json > metrics.jsonUse Claude Code for interactive analysis:
"I just ran ccg code-optimize. Help me understand the hotspots and prioritize fixes."
Be specific about scope:
"Analyze only TypeScript files in the src/services folder"
Ask for explanations:
"Why is this file flagged as a hotspot? What makes it complex?"
Request actionable advice:
"What's the quickest way to reduce complexity in auth/login.ts?"
Iterate on results:
"That's helpful. Now show me similar issues in other files."
- Start with quickstart - Get baseline metrics
- Review hotspots - Understand problem areas
- Prioritize fixes - Focus on high-impact, low-effort items
- Track progress - Compare before/after metrics
- Automate checks - Add to CI/CD pipeline
If your browser refreshes or Claude Code restarts mid-task:
- Check for resume offer: Call
session_offerto see if a previous session is available - Resume session: Call
session_resume(orsession_resume { sessionFile: "..." }for specific file) - Review what was done: Call
session_timelineto see completed events - Check blocked tasks: Look for
nextToolCallsin any blocked task responses - Continue from nextToolCalls: Execute suggested tools to unblock and complete tasks
See Session Resume Guide for detailed recovery workflows.
"Cannot find CCG tools"
- Verify CCG is installed:
ccg --version - Check MCP config file exists
- Restart Claude Desktop/Code
- Check logs:
CCG_LOG_LEVEL=debug
"Permission denied"
Ensure the project path in CCG_PROJECT_ROOT is accessible and has read permissions.
"No files found"
Check exclude patterns in .ccg/config.json. Default excludes node_modules, dist, etc.
"Analysis takes too long"
For large repositories (>50k LOC):
- Use
--max-filesflag - Analyze specific directories
- Use multi-repo config to split analysis
- Check User Guide for CLI details
- Run
ccg doctorto diagnose configuration issues - Open issues at GitHub
- User Guide - Complete CLI reference
- Quickstart Guide - 3-minute setup
- Multi-repo Setup - Managing multiple repositories