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 27+ analysis tools to analyze unfamiliar codebases and produce structured context documentation for AI coding assistants. It combines structural code intelligence (GitNexus), BM25 ranked search, git history analysis, static scanners (semgrep, ruff, ty, radon, vulture), 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
27+ analysis tools GitNexus, ripgrep, BM25 search, repomix, git history, static scanners
GitNexus code intelligence Tree-sitter knowledge graph with structural search, blast radius, execution flows, community detection
BM25 ranked search Concept-level search with TF-IDF-like relevance scoring
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
Static analysis Semgrep security scanning, type checking, linting, complexity, dead code detection
Structured output Pydantic-typed AnalysisResult with ranked business logic and architectural risks
Security hardened Shell allowlist, input validation, path traversal prevention, CI security pipeline
Full mode --full for exhaustive analysis with extended limits and fail-fast errors
Deterministic indexer index command runs 16-step pipeline without LLM calls (fast, cheap)
Two-package workspace Reusable strands-teams framework + code-context-agent use case
Multi-agent teams Coordinator dispatches parallel native Swarm teams with GitNexus + git + discovery tools

Architecture

flowchart TD
    A[CLI: cyclopts] --> B[analyze command]
    A --> IDX[index command]
    A --> CHK[check command]
    IDX --> IDXP[Deterministic Indexer<br/>16 steps]
    IDXP --> HS[heuristic_summary.json<br/>bridge artifact]
    B --> COORD[Coordinator Agent<br/>reads heuristic_summary.json]
    COORD --> DT[dispatch_team<br/>parallel specialist teams]
    DT --> T1[Team 1]
    DT --> T2[Team 2]
    DT --> TN[Team N]
    T1 & T2 & TN --> RF[read_team_findings<br/>collect results]
    RF --> WB[write_bundle<br/>generate output]
    WB --> OUT[CONTEXT.md +<br/>bundles/BUNDLE.area.md]
    COORD -.-> F[HookProviders<br/>quality + efficiency + fail-fast]
    COORD -.-> GP[Pre-loaded Graph<br/>from index]

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

# Quick index without LLM (fast, cheap)
code-context-agent index .

# Interactive visualization
code-context-agent viz .

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)
bundles/BUNDLE.{area}.md Targeted narrative bundles per investigation area
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
heuristic_summary.json Bridge artifact between indexer and coordinator
analysis_result.json Structured analysis result (Pydantic JSON)
CONTEXT.modules/ Per-module context files (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
Ranked search BM25 (rank_bm25)
Terminal UI Rich
Code search ripgrep
Code bundling repomix (Tree-sitter)
Code intelligence GitNexus (Tree-sitter knowledge graph)
Static analysis semgrep, ruff, ty, radon, vulture, knip