The Claude Code Usage Monitor uses a centralized version management system that eliminates version duplication and ensures consistency across the entire codebase.
pyproject.toml is the only place where the version number is defined:
[project]
version = "3.0.0"The version is retrieved using a two-tier fallback system:
-
Primary: Read from package metadata (when installed)
importlib.metadata.version("claude-monitor")
-
Fallback: Read directly from
pyproject.toml(development mode)# Uses tomllib (Python 3.11+) or tomli (Python < 3.11)
from claude_monitor._version import __version__All modules import version from the main package:
from claude_monitor import __version__✅ Single Source of Truth: Version defined only in pyproject.toml
✅ No Duplication: Eliminates hardcoded versions in __init__.py files
✅ Automatic Sync: Version updates automatically propagate everywhere
✅ Development Support: Works both in installed and development environments
✅ Build Integration: Seamlessly integrates with build and release processes
- Python 3.11+: Uses built-in
tomllib - Python < 3.11: Uses
tomli>=1.2.0(automatically installed)
Comprehensive test suite in src/tests/test_version.py:
- Version import consistency
- Fallback mechanism testing
- Integration with
pyproject.toml - Format validation
# Multiple version definitions - sync issues!
# src/claude_monitor/__init__.py
__version__ = "2.5.0"
# pyproject.toml
version = "3.0.0" # Different version!# src/claude_monitor/__init__.py
from claude_monitor._version import __version__ # Always in sync!
# pyproject.toml
version = "3.0.0" # Single source of truth- Update version in
pyproject.tomlonly - All other files automatically reflect the new version
- No manual updates needed anywhere else
- ✅ Update version only in
pyproject.toml - ✅ Use
from claude_monitor import __version__in all modules - ❌ Never hardcode version strings in source code
- ❌ Never define
__version__in__init__.pyfiles
This system ensures version consistency and eliminates the maintenance burden of keeping multiple version definitions synchronized.