A Claude Code skill that automates comprehensive documentation for Pull Requests using graph-based analysis. This tool analyzes PR changes, categorizes them by impact, extracts entities and relationships, and generates structured technical documentation.
This project provides a /pr-doc slash command that orchestrates file analysis through specialized agents, stores findings in a Neo4j graph database, and generates detailed markdown documentation covering technical changes, breaking changes, and architectural impacts.
Slash Command: /pr-doc <pr-number> [repo-path]
- Entry point for generating PR documentation
- Located in
.claude/commands/pr-doc.md - Orchestrates the entire workflow from PR metadata retrieval to documentation generation
Agents:
file-analyzer: Specialized agent that analyzes individual files in isolation- Examines before/after states using git
- Extracts entities (functions, classes, services, dependencies)
- Stores structured findings in Neo4j
- Operates in isolated context to prevent context pollution
Skills:
-
file-pattern-detector: Detects file types and extracts structural metadata- Classifies files (React components, API endpoints, configs, tests, etc.)
- Identifies frameworks (Next.js, Express, Terraform)
- Extracts imports, exports, functions, classes
-
neo4j-operations: Handles all Neo4j graph database interactions- Creates entities following standardized schema
- Establishes relationships between entities
- Queries graph for architectural insights
- Validates operations against schema
- Claude Code: Orchestration, agents, and skills framework
- GitHub CLI (
gh): PR metadata and file diff retrieval - Neo4j (via MCP): Graph database for relationship tracking
- MCP Tools:
mcp__mcp-neo4j-memory__*for entity-observation model - Git: File history and diff analysis
-
PR Metadata Retrieval
- Uses
gh pr viewto fetch PR details (title, author, files, commits) - Stores context in
memory_bank/prContext.md - Creates PR entity in Neo4j:
pr:{number}
- Uses
-
File Analysis Strategy
- Threshold: PRs with <12 effective files analyze all; ≥12 files use strategic sampling
- Effective Count: Excludes generated files, lock files, trivial updates
- Delegation: Each file analyzed by
file-analyzeragent in isolation
-
Per-File Analysis (via
file-analyzeragent)- Reads file's "before" state:
git show {base_commit}:{file_path} - Detects file type using
file-pattern-detectorskill - Reads changes:
git diff {base_commit}..{head_commit} - Extracts entities: functions, classes, business logic, services, dependencies
- Analyzes impact: lines added/removed, change type, impact level
- Stores in Neo4j using
neo4j-operationsskill - Saves JSON results to
memory_bank/analysisResults/{file_hash}.json
- Reads file's "before" state:
-
Graph-Based Representation
- Entities:
PR,File,Change,Function,Class,BusinessLogic,Configuration,Service,Dependency - Relationships:
MODIFIES,HAS_CHANGE,CONTAINS,DEPENDS_ON,IMPLEMENTS - Entity naming:
pr:{number},file:{path},bl:{name},config:{name},service:{name} - Schema reference:
memory_bank/graphSchema.md
- Entities:
-
Documentation Generation
- Reads ALL JSON files from
memory_bank/analysisResults/*.json - Queries Neo4j for architectural insights and relationships
- Generates structured markdown with three parts:
- Executive Summary: Overview, statistics, categorization
- Technical Deep-Dive: File-by-file analysis with breaking changes, entities, impact
- Cross-Cutting Concerns: Architecture, dependencies, testing recommendations
- Output:
pr-{number}-documentation.md
- Reads ALL JSON files from
This project uses the Neo4j MCP's entity-observation model instead of traditional graph properties:
- Entities: Named nodes with type classifications (e.g.,
pr:301,file:src/api.ts) - Observations: Atomic facts stored as text arrays (e.g., "Lines added: 42", "Impact level: high")
- Relations: Directed connections with active-voice types (e.g.,
MODIFIES,DEPENDS_ON)
This approach enables flexible, incremental knowledge building without rigid schema constraints.
- Explicit handling of large PRs with >10 files
- Agent-based isolation prevents context pollution
- Continuation tasks for PRs approaching context limits
- JSON file persistence for analysis results
- Business logic, configuration, services, dependencies
- Schemas, infrastructure, CI/CD pipelines
- Focus on purpose, behavior, and system impact
- Extracted per-file and documented explicitly
- Method signature changes, API modifications
- Dependency version changes
- Graph queries reveal service dependencies
- Cross-file impact analysis
- Relationship tracking between components
.claude/
├── commands/
│ └── pr-doc.md # Main slash command
├── agents/
│ └── file-analyzer.md # File analysis agent
├── skills/
│ ├── file-pattern-detector/ # File type detection skill
│ │ └── SKILL.md
│ └── neo4j-operations/ # Graph database skill
│ └── SKILL.md
└── CLAUDE.md # Project-level instructions
memory_bank/
├── prContext.md # Current PR workflow state
├── graphSchema.md # Neo4j entity/relation schema
├── analysisResults/ # Per-file analysis JSON
└── [other context files]
# Generate documentation for PR #123 in current directory
/pr-doc 123
# Generate documentation for PR #456 in specific repo
/pr-doc 456 /path/to/repoThe command will:
- Fetch PR metadata from GitHub
- Analyze changed files using specialized agents
- Store findings in Neo4j graph database
- Generate comprehensive markdown documentation
# PR #301: Add Dark Mode Support
## Executive Summary
- **Author**: john-doe
- **Files Changed**: 8
- **Impact**: High - Breaking changes to theme API
## Technical Deep-Dive
### src/themes/darkMode.ts
**Changes**: +274/-192 lines | **Impact**: HIGH
**Breaking Changes**:
1. Removed `ThemeInterface` inheritance
2. `applyTheme()` signature changed - removed `cascade` parameter
**Key Changes**:
- Migrated from CSS-in-JS to CSS variables
- Added `getThemePreference()` for system detection
**Entities Modified**:
- **Classes**: DarkModeManager (refactored)
- **Functions**: applyTheme, getThemePreference
- **Dependencies Added**: @theme-utils/css-vars
**Impact**: Affects all theme consumers. Migration required.
## Cross-Cutting Concerns
- Service dependencies: ThemeService, UserPreferencesService
- Testing: Add dark mode E2E tests
- Deployment: Update CSS build pipeline- Review workflow structure in
.claude/commands/pr-doc.md - Extend
file-analyzeragent for new file types - Update
graphSchema.mdfor new entity types - Enhance
file-pattern-detectorfor framework detection - Test with various PR sizes and types
Why Agents?: File analysis in isolated contexts prevents context pollution and enables parallel processing patterns in future iterations.
Why Graph Database?: Relationships between code entities (dependencies, impacts, modifications) are naturally expressed as graphs, enabling sophisticated queries for architectural insights.
Why Entity-Observation Model?: Flexible fact management without rigid schemas, allowing incremental knowledge building as analysis progresses.
Why JSON Persistence?: Analysis results stored as files enable review, debugging, and provide fallback if graph queries fail.
- Claude Code (with MCP support)
- Neo4j (local or remote instance)
- GitHub CLI (
gh) authenticated - Git repository with PR access
- Neo4j MCP server configured in Claude Code
- Parallel file analysis for large PRs
- Automated test recommendation based on entity changes
- Dependency impact visualization
- Historical PR comparison
- Integration with CI/CD systems