CodeContext provides both a CLI interface and a REST API for programmatic access.
./gradlew installDist
# Analyze current directory
./build/install/codecontext/bin/codecontext analyze .
# Analyze specific directory
./build/install/codecontext/bin/codecontext analyze /path/to/project
# With options
./build/install/codecontext/bin/codecontext analyze . --no-cache --clear-cache
analyzeAnalyzes a codebase and generates an interactive report.
Syntax:
codecontext analyze <path> [options]
Arguments:
<path> - Path to analyze (default: current directory)Options:
--no-cache - Disable caching for this run--clear-cache - Clear cache before analyzingOutput:
output/index.htmloutput/ai-insights.mdExample:
codecontext analyze ~/projects/my-app --clear-cache
Output:
π Starting CodeContext analysis for: ~/projects/my-app
π Scanning repository...
Found 247 files
π§ Parsing code...
Parsed 247 files
π Analyzing Git history...
πΈοΈ Building dependency graph...
πΊοΈ Your Codebase Map
ββ π₯ Hot Zones (Top 5):
β ββ UserService.kt (0.0847)
β ββ DatabaseConfig.kt (0.0623)
β ββ ...
π Generating report...
β
Report: ~/projects/my-app/output/index.html
β¨ Complete in 3421ms
serverStarts a REST API server.
Syntax:
codecontext server [options]
Options:
--port <number> - Port to listen on (default: 8080)--host <address> - Host address (default: 0.0.0.0)Example:
codecontext server --port 3000
ai-assistantGenerates AI-powered code insights.
Syntax:
codecontext ai-assistant <path> [options]
Requirements:
Example:
export OPENAI_API_KEY=sk-...
codecontext ai-assistant .
evolutionTracks codebase evolution over time.
Syntax:
codecontext evolution <path>
Output:
codecontext server --port 8080
POST /analyzeTriggers analysis of a codebase.
Request:
{
"path": "/path/to/project",
"options": {
"enableCache": true,
"clearCache": false
}
}
Response:
{
"status": "success",
"analysisId": "abc123",
"stats": {
"filesScanned": 247,
"filesParsed": 247,
"graphNodes": 247,
"graphEdges": 892
},
"reportUrl": "/report/abc123"
}
Status Codes:
200 - Analysis completed successfully400 - Invalid request500 - Analysis failedGET /report/:idRetrieves analysis report.
Request:
GET /report/abc123
Response:
{
"id": "abc123",
"timestamp": "2025-12-14T20:00:00Z",
"path": "/path/to/project",
"hotspots": [
{
"file": "UserService.kt",
"score": 0.0847,
"description": "Main user service"
}
],
"learningPath": [
{
"file": "Utils.kt",
"reason": "Foundation utilities"
}
],
"graph": {
"nodes": [...],
"links": [...]
}
}
GET /healthHealth check endpoint.
Response:
{
"status": "healthy",
"version": "0.1.0",
"uptime": 3600
}
Add to build.gradle.kts:
dependencies {
implementation("com.codecontext:codecontext-core:0.1.0")
}
import com.codecontext.core.scanner.RepositoryScanner
import com.codecontext.core.parser.ParserFactory
import com.codecontext.core.graph.RobustDependencyGraph
import com.codecontext.output.ReportGenerator
fun analyzeProject(path: String) {
// 1. Scan files
val scanner = RepositoryScanner()
val files = scanner.scan(path)
// 2. Parse files
val parsedFiles = files.map { file ->
val parser = ParserFactory.getParser(file)
parser.parse(file)
}
// 3. Build graph
val graph = RobustDependencyGraph()
graph.build(parsedFiles)
graph.analyze()
// 4. Get hotspots
val hotspots = graph.getTopHotspots(10)
hotspots.forEach { (file, score) ->
println("$file: $score")
}
// 5. Generate report
val generator = ReportGenerator()
generator.generate(graph, "output/report.html", parsedFiles, emptyList())
}
Location: .codecontext.json in project root
Example:
{
"maxFilesAnalyze": 10000,
"hotspotCount": 15,
"enableCache": true,
"ai": {
"enabled": false,
"apiKey": "",
"model": "gpt-4"
}
}
import com.codecontext.core.config.ConfigLoader
val config = ConfigLoader.load()
println("Max files: ${config.maxFilesAnalyze}")
data class ParsedFile(
val file: File,
val packageName: String,
val imports: List<String>,
val gitMetadata: GitMetadata = GitMetadata(),
val description: String = ""
)
data class GitMetadata(
val lastModified: Long = 0,
val changeFrequency: Int = 0,
val topAuthors: List<String> = emptyList(),
val recentMessages: List<String> = emptyList()
)
data class LearningStep(
val file: String,
val description: String,
val reason: String
)
β No source files found
β Too many files (12000). Limit: 10000
β Failed to build graph: ...
β Analysis failed: ...
{
"error": {
"code": "INVALID_PATH",
"message": "Path does not exist: /invalid/path",
"details": {}
}
}
Error Codes:
INVALID_PATH - Path doesnβt existTOO_MANY_FILES - Exceeds max file limitPARSE_ERROR - Failed to parse fileGRAPH_BUILD_ERROR - Failed to build dependency graphINTERNAL_ERROR - Unexpected errorval scanner = RepositoryScanner()
val files = scanner.scan(".")
val parser = CodeParallelParser()
val parsed = runBlocking { parser.parseFiles(files) }
val graph = RobustDependencyGraph()
graph.build(parsed)
graph.analyze()
val hotspots = graph.getTopHotspots(5)
class PythonParser : LanguageParser {
override fun parse(file: File): ParsedFile {
val content = file.readText()
val packageName = extractPackage(content)
val imports = extractImports(content)
return ParsedFile(file, packageName, imports)
}
}
// Register
ParserFactory.register("py", PythonParser())
Coming soon: Webhook support for real-time notifications.
{
"event": "analysis.completed",
"data": {
"analysisId": "abc123",
"timestamp": "2025-12-14T20:00:00Z"
}
}
For API questions or issues: