This file provides guidance to Claude Code (claude.ai/code) and Cursor when working with code in this repository.
This repository is managed with contextgit. Before making changes to requirements or documentation:
-
Before modifying requirements/docs:
contextgit relevant-for-file <path> # Find related requirements contextgit extract <ID> # Get precise context
-
After modifying requirements/docs:
contextgit scan docs/ --recursive # Update the index contextgit status --stale # Check for broken links
-
When adding new requirements:
contextgit next-id <type> # Generate ID (business, system, architecture, code, test) # Add YAML frontmatter with the generated ID contextgit scan docs/ --recursive # Register in index
-
When upstream requirements change:
contextgit status --stale # Find affected downstream items # Update downstream items as needed contextgit confirm <ID> # Mark as synchronized
Check for .contextgit/config.yaml to confirm this is a contextgit-managed project.
contextgit is a local-first, git-friendly CLI tool for managing requirements and context traceability in LLM-assisted software projects.
Current Status: v1.1.0 - Production ready, all 10 CLI commands implemented.
contextgit is a local-first, git-friendly CLI tool that:
- Tracks requirements traceability from business needs → system specs → architecture → code → tests
- Embeds metadata in Markdown files (YAML frontmatter or HTML comments)
- Maintains a central YAML index (
.contextgit/requirements_index.yaml) - Detects staleness via checksums when upstream requirements change
- Extracts precise context snippets for LLM consumption
- Provides JSON output for all read operations to support Claude Code workflows
Key Design Principle: Designed specifically for integration with Claude Code and similar LLM CLIs.
All planning documents are in docs/:
- 01_product_overview.md - Problem, users, goals, features
- 02_user_stories.md - 11 detailed workflows with personas
- 03_system_requirements.md - Functional (FR-1 to FR-13) and non-functional requirements
- 04_architecture_overview.md - START HERE for architecture understanding
- 05_data_model_and_file_layout.md - Complete schemas for nodes, links, index, config
- 06_cli_specification.md - Detailed specs for all 10 CLI commands
- 07_llm_integration_guidelines.md - How Claude Code should interact with contextgit
- 08_mvp_scope_and_future_work.md - What's in/out of MVP scope
Layered Design:
CLI Layer (Typer/Click)
↓
Application Layer (Command Handlers)
↓
Core Domain Layer:
- Index Manager (CRUD for nodes/links, atomic writes)
- Metadata Parser (YAML frontmatter & HTML comments)
- Location Resolver & Snippet Extractor
- Linking Engine (graph traversal, staleness detection)
- Checksum Calculator (SHA-256)
- ID Generator (sequential with prefixes)
- Config Manager
↓
Infrastructure Layer:
- File System Access (UTF-8, atomic writes)
- YAML Serialization (deterministic, sorted)
- Output Formatter (text/JSON)
Key Components:
- Index Manager: Never corrupts index; uses temp file + atomic rename
- Metadata Parser: Supports two formats in Markdown files:
- YAML frontmatter at file start
- Inline
<!-- contextgit ... -->HTML comments
- Linking Engine: Auto-creates links from
upstream/downstreamfields; tracks sync status - Checksum Calculator: Detects content changes to mark downstream items stale
Node: Requirement/context item with id, type, title, file, location, status, checksum
Link: Traceability relationship with from/to IDs, relation_type, sync_status
Index File: .contextgit/requirements_index.yaml with sorted nodes and links
Config File: .contextgit/config.yaml with tag prefixes and directory suggestions
Node Types: business, system, architecture, code, test, decision Relation Types: refines, implements, tests, derived_from, depends_on Sync Status: ok, upstream_changed, downstream_changed, broken
All commands support --format json for LLM consumption:
contextgit init- Initialize projectcontextgit scan [PATH] [--recursive]- Scan files, update indexcontextgit status [--stale] [--orphans]- Show project healthcontextgit show <ID>- Display node details with linkscontextgit extract <ID>- Extract requirement snippet (critical for LLMs)contextgit link <FROM> <TO> --type <RELATION>- Manual link creationcontextgit confirm <ID>- Mark as synchronized after updatescontextgit next-id <TYPE>- Generate next ID (e.g., BR-001, SR-012)contextgit relevant-for-file <PATH>- Find requirements for source filecontextgit fmt- Format index for clean git diffs
Technology Stack (from docs/04_architecture_overview.md):
- Python 3.11+ with type hints, dataclasses
- CLI framework: Typer (recommended) or Click
- YAML: ruamel.yaml for deterministic output
- Markdown parsing: Python-Markdown or markdown-it-py
- Testing: pytest with coverage
Critical Implementation Requirements:
- Atomic writes: Always write to temp file, then rename (never corrupt index)
- Deterministic YAML: Sort nodes by ID, links by (from, to) for git-friendliness
- Performance targets:
- Extract: < 100ms
- Show/Status: < 500ms
- Scan 1000 files: < 5 seconds
- Checksum: SHA-256 of normalized text (strip whitespace, normalize line endings)
- Location tracking: Heading paths (e.g.,
["Section", "Subsection"]) or line ranges
File Organization (when implementing):
contextgit/
├── cli/ # Typer command definitions
├── handlers/ # Command handlers (InitHandler, ScanHandler, etc.)
├── domain/ # Core domain (IndexManager, MetadataParser, etc.)
├── infra/ # File system, YAML, output formatting
└── models/ # Node, Link, Index, Config dataclasses
Detection: Claude Code detects contextgit projects by checking for .contextgit/config.yaml
Core Workflows:
- Create requirement:
next-id→ create file with metadata →scan - Implement feature:
extract <ID>for context → implement →scanto link code - Handle upstream changes:
status --stale→ update downstream →confirm <ID> - Find requirements for file:
relevant-for-file <path>→extracteach ID
Best Practices:
- Always use
--format jsonfor parsing - Extract only needed context (not entire files)
- Run
scanafter any file modifications - Use
confirmafter updating downstream items
IN SCOPE:
- All 10 CLI commands
- Markdown-only support
- Local-first (no network/cloud)
- Python 3.11+, Linux-first
- JSON output for LLM integration
OUT OF SCOPE (deferred to Phase 2+):
- VS Code extension
- Code parsing (auto-extract functions/classes)
- Watch mode
- ReStructuredText/AsciiDoc
- Web dashboard
- Issue tracker integration
- Core CLI (Weeks 1-2): init, config, index management
- Scanning & Indexing (Weeks 2-3): parse metadata, calculate checksums, create links
- Querying & Extraction (Week 3-4): show, extract, status, relevant-for-file
- Traceability (Week 4): sync status, link, confirm, staleness detection
- Utilities (Week 5): next-id, fmt, error handling, JSON output
- Docs & Packaging (Week 6): README, examples, PyPI packaging
- Never corrupt index: Use atomic writes (temp + rename)
- Git-friendly: Deterministic YAML ordering, relative paths only
- No state beyond index: Index file is single source of truth
- Markdown-only for MVP: Don't add RST, AsciiDoc, or code parsing yet
- Single-repo for MVP: Don't implement multi-repo support yet
See docs/02_user_stories.md for 11 complete workflows including:
- Story 1: Initialize project
- Story 4: Create linked requirements
- Story 6: Detect upstream changes
- Story 7: Find requirements for source file
- Story 10: Use in CI to block PRs with stale requirements
Each story includes acceptance criteria and full flow.
- For CLI design: docs/06_cli_specification.md (exact argument syntax, exit codes, examples)
- For data structures: docs/05_data_model_and_file_layout.md (Node/Link schemas, YAML format)
- For architecture: docs/04_architecture_overview.md (component responsibilities, algorithms)
- For requirements validation: docs/03_system_requirements.md (FR-1 through FR-13)