Skip to content

code-context-agent

AI-powered CLI tool for automated codebase analysis and context generation.

code-context-agent uses Claude Opus 4.6 (via Amazon Bedrock) with 45+ tools to analyze unfamiliar codebases and produce structured context documentation for AI coding assistants. It combines semantic analysis (LSP), structural pattern matching (ast-grep), graph algorithms (NetworkX), git history analysis, and intelligent code bundling (repomix) to generate narrated markdown that helps developers and AI assistants understand a codebase's architecture and business logic.

Autonomous Agent

This CLI runs a fully autonomous AI agent loop. The agent decides which tools to invoke, what files to read, and what shell commands to run. While shell commands are restricted to a read-only allowlist and all inputs are validated, the agent makes its own decisions within those bounds. Review all generated output before using it in production.

AI-Generated Output

Generative AI can make mistakes. Review all output and monitor costs generated by your chosen AI model. Analysis of a single repository typically consumes 50K--500K input tokens and 10K--50K output tokens on Claude Opus 4.6.

Disclaimer

The author is an AWS employee. This is not an official AWS project or service. It is not maintained, supported, or endorsed by AWS. This project runs fully autonomous agent loops with access to your filesystem (read-only). You are solely responsible for any consequences of running this tool. The CLI and source code are provided AS IS without warranty of any kind. User discretion advised.


Key Capabilities

Capability Description
45+ analysis tools LSP, ast-grep, ripgrep, repomix, git history, NetworkX graph
Multi-language LSP Python (ty), TypeScript, Rust, Go, Java with ordered fallback chains
Graph-based insights Hotspots (betweenness centrality), foundations (PageRank/TrustRank), modules (Louvain/Leiden), triangle detection
Git-aware bundling Embeds diffs, commit history, and coupling data in context bundles
Tree-sitter compression Extracts signatures/types only, stripping function bodies for token efficiency
Structured output Pydantic-typed AnalysisResult with ranked business logic, risks, and graph stats
Security hardened Shell allowlist, input validation, path traversal prevention, CI security pipeline
Full mode --full for exhaustive analysis with no size limits, fail-fast errors, and per-module output
MCP server Expose graph algorithms and analysis as MCP tools for Claude Code, Cursor, and other agents

Architecture

flowchart TD
    A[CLI: cyclopts] --> B[run_analysis]
    B --> C[create_agent]
    C --> D[Strands Agent<br/>Opus 4.6 + adaptive thinking]
    D --> E[Jinja2 System Prompt]
    D --> F[HookProviders<br/>quality + efficiency + fail-fast]
    D --> G[AnalysisResult<br/>structured output]
    D --> H[Tool Execution]
    H --> I[Discovery<br/>ripgrep, repomix]
    H --> J[LSP<br/>ty, ts-server, rust-analyzer]
    H --> K[AST<br/>ast-grep patterns]
    H --> L[Graph<br/>NetworkX analysis]
    H --> M[Git<br/>coupling, churn, blame]
    H --> N[Shell<br/>bounded execution]
    H --> O[Output Files<br/>.code-context/ directory]

Quick Start

# Install
uv tool install code-context-agent

# Analyze a repository
code-context-agent analyze /path/to/repo

# Focus on a specific area
code-context-agent analyze . --focus "authentication system"

# Verify tool dependencies
code-context-agent check

# Exhaustive analysis (no size limits, fail-fast)
code-context-agent analyze . --full

# Full analysis focused on specific area
code-context-agent analyze . --full --focus "authentication"

See the Installation and Quick Start guides for details.


Output

All outputs are written to .code-context/ (or custom --output-dir):

File Description
CONTEXT.md Main narrated context (<=300 lines in standard mode)
CONTEXT.orientation.md Token distribution tree
CONTEXT.bundle.md Bundled source code (compressed)
CONTEXT.signatures.md Signatures-only structural view
files.all.txt Complete file manifest
files.business.txt Curated business logic files
code_graph.json Persisted graph data
FILE_INDEX.md File index with graph metrics (complex repos)
analysis_result.json Structured analysis result (Pydantic JSON)
CONTEXT.modules/ Per-module context files (full mode)
CONTEXT.business.*.md Category-specific business logic (full mode)

Tech Stack

Component Technology
Agent framework Strands Agents
LLM Claude Opus 4.6 via Amazon Bedrock
CLI cyclopts
Prompt templates Jinja2
Data models Pydantic + pydantic-settings
Graph analysis NetworkX
Terminal UI Rich
Code search ripgrep
Code bundling repomix (Tree-sitter)
Pattern matching ast-grep
Type checker / LSP ty, typescript-language-server