This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
pyhunt is a lightweight Python logging tool that automatically traces function calls and provides visual, tree-structured colored logs for debugging. It uses a simple @trace decorator to log function execution times, call hierarchies, and exceptions.
# Install dependencies
uv sync
# Build the package
uv build# Run Python files with uv
uv run python filename.py
# Run Python modules with uv
uv run python -m module_name
# Run Python interactively with uv
uv run python# Run all tests
uv run pytest
# Run specific test file
uv run pytest test/test_examples.py
# Run tests with verbose output
uv run pytest -v# Lint all files in the current directory
uvx ruff check
# Format all files in the current directory
uvx ruff format# Set up environment file (creates .env with DEBUG level)
hunt
# Set specific log levels
hunt --debug
hunt --info
hunt --warning
hunt --error
hunt --critical
# Set root directory and repeat limit
hunt --root
hunt --repeat 5pyhunt/decorator.py: Core@tracedecorator implementation for function call tracingpyhunt/cli.py: Command-line interface for managing log levels and environment variablespyhunt/logger.py: Direct logging interface for manual log messagespyhunt/console.py: Console output formatting and color handlingpyhunt/config.py: Environment variable configuration and.envfile managementpyhunt/colors.py: Color definitions for different log levelspyhunt/context.py: Call context management for tracking execution depthpyhunt/utils.py: Utility functions for path handling and formattingpyhunt/helpers.py: Helper functions for decorator and logging operations
- Automatic Tracing: The
@tracedecorator automatically logs function entry, exit, execution time, and exceptions - Tree-structured Output: Logs are indented based on call depth for visual hierarchy
- Multiple Log Levels: DEBUG, INFO, WARNING, ERROR, CRITICAL with color coding
- Async Support: Full support for async/await functions
- Class Integration: Can be applied to entire classes to trace all methods
- Environment Configuration: Manages log levels through
.envfile and CLI
from pyhunt import trace
@trace
def my_function(param):
return param * 2
@trace
async def async_function(param):
return await some_async_call()
@trace
class MyClass:
def method_one(self):
pass
def method_two(self):
passfrom pyhunt import logger
logger.debug("Debug message")
logger.info("Info message")
logger.warning("Warning message")
logger.error("Error message")
logger.critical("Critical message")The tool supports these environment variables (managed via .env file):
HUNT_LEVEL: Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)HUNT_MAX_REPEAT: Maximum number of repeated log displaysELAPSED: Whether to show execution time (True/False)ROOT_DIR: Base directory for path display
For AI-generated code, follow these patterns:
- Import:
from pyhunt import trace - Use
@tracedecorator instead ofprint()statements - For exceptions, use
try/except Exception as e: raise eto maintain traceback - Apply
@traceto classes and methods automatically when adding logging - Execute Python files with
uv run pythoninstead of justpython
Tests are located in the test/ directory and use pytest. The main test file test_examples.py runs all example files and compares their output against expected results stored in examples/outputs/.