This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
git-split is a Python CLI tool that splits a file into multiple files while preserving git blame line history. It uses temporary git branches and octopus merges so that git tracks the lineage of each line through the split.
git_split/
__init__.py # version, top-level imports
core.py # pure logic: parse_range, detect_split_blocks, process_file, analyze_split
git_ops.py # git interaction: run_git_command, ensure_clean_worktree, move_file_and_commit
cli.py # argparse main(), execute_split_plan()
exceptions.py # GitSplitError, GitCommandError, ParseError
mcp_server.py # FastMCP server with tools + resource
__main__.py # python -m git_split
tests/
test_core.py # test parse_range, detect_split_blocks, process_file
test_git_ops.py # test run_git_command, ensure_clean_worktree
# Install in development mode:
pip install -e .
# Run with inline SPLIT markers (autodetect mode):
git-split source_file.py
# Run with explicit line ranges (manual mode):
git-split "source.py:10-20:new_file.py"
# Preview changes:
git-split -p source_file.py
# Dry run (no git operations executed):
git-split -n source_file.py
# Skip confirmation prompt:
git-split -y source_file.py
# Run as module:
python -m git_split source_file.py
# Start MCP server:
git-split-mcppytest tests/ -v- Python >=3.9
intervaltree>=3.0— tracking line rangestabulate>=0.9— formatting change digest output- Optional:
mcp>=1.0— for MCP server functionality
Install with: pip install -e ".[dev]" (includes pytest)
- Autodetect mode — scans for
SPLIT:EXTRACT:<target>/SPLIT:ENDBLOCKcomment markers - Manual mode —
old_file:line_range:new_fileformat
Both build an IntervalTree and converge on process_file().
- For each target file, create a temp branch and
git mvsource -> target - Octopus merge all temp branches
- Rename temp copies back to original names
- Overwrite each file with only its designated lines
- Merge final branch back with
--no-ff - Clean up temp branches
core.py— Pure logic:parse_range,detect_split_blocks,process_file,analyze_splitgit_ops.py— Git commands viasubprocess(list-based, noshell=True),ensure_clean_worktreecli.py— CLI entry point,execute_split_plan()orchestrationmcp_server.py— MCP tools:detect_blocks,preview_split,execute_split