|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +libtmux is a typed Python library providing an object-oriented wrapper for tmux. It enables programmatic control of tmux servers, sessions, windows, and panes through a hierarchical API: Server → Sessions → Windows → Panes. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Setup |
| 12 | +```bash |
| 13 | +# Install dependencies using uv (modern Python package manager) |
| 14 | +uv sync --all-extras --dev |
| 15 | +``` |
| 16 | + |
| 17 | +### Testing |
| 18 | +```bash |
| 19 | +# Run all tests |
| 20 | +uv run pytest |
| 21 | +# or |
| 22 | +make test |
| 23 | + |
| 24 | +# Run specific test file |
| 25 | +uv run pytest tests/test_server.py |
| 26 | + |
| 27 | +# Run specific test |
| 28 | +uv run pytest tests/test_server.py::test_server_cmd |
| 29 | + |
| 30 | +# Run with verbose output |
| 31 | +uv run pytest -v |
| 32 | + |
| 33 | +# Run doctests |
| 34 | +uv run pytest --doctest-modules src/ |
| 35 | +``` |
| 36 | + |
| 37 | +### Code Quality |
| 38 | +```bash |
| 39 | +# Run linting |
| 40 | +uv run ruff check . |
| 41 | +# or |
| 42 | +make ruff |
| 43 | + |
| 44 | +# Format code |
| 45 | +uv run ruff format . |
| 46 | +# or |
| 47 | +make ruff_format |
| 48 | + |
| 49 | +# Type checking |
| 50 | +uv run mypy . |
| 51 | +# or |
| 52 | +make mypy |
| 53 | + |
| 54 | +# Run all checks |
| 55 | +make watch_ruff # Watches for changes |
| 56 | +``` |
| 57 | + |
| 58 | +### Documentation |
| 59 | +```bash |
| 60 | +# Build and serve docs locally |
| 61 | +make start_docs |
| 62 | + |
| 63 | +# Build docs only |
| 64 | +cd docs && make html |
| 65 | +``` |
| 66 | + |
| 67 | +## Architecture |
| 68 | + |
| 69 | +### Core Classes (src/libtmux/) |
| 70 | +- **Server** (`server.py`): Represents tmux server, manages sessions |
| 71 | +- **Session** (`session.py`): Manages windows within a session |
| 72 | +- **Window** (`window.py`): Manages panes within a window |
| 73 | +- **Pane** (`pane.py`): Individual terminal pane |
| 74 | + |
| 75 | +### Key Modules |
| 76 | +- **common.py**: Base classes, command execution (`tmux_cmd`, `AsyncTmuxCmd`) |
| 77 | +- **exc.py**: Custom exceptions (e.g., `LibTmuxException`, `TmuxCommandNotFound`) |
| 78 | +- **formats.py**: Format handling for tmux output |
| 79 | +- **constants.py**: Tmux version constants and feature flags |
| 80 | + |
| 81 | +### Command Execution Pattern |
| 82 | +All tmux objects inherit from `TmuxCommonObject` which provides: |
| 83 | +- `.cmd()` - Synchronous tmux command execution |
| 84 | +- `.acmd()` - Asynchronous tmux command execution (new feature on asyncio branch) |
| 85 | + |
| 86 | +Example: |
| 87 | +```python |
| 88 | +server.cmd('list-sessions', '-F', '#{session_name}') |
| 89 | +await server.acmd('list-sessions', '-F', '#{session_name}') |
| 90 | +``` |
| 91 | + |
| 92 | +### Testing Approach |
| 93 | +- Tests require tmux to be installed |
| 94 | +- Use pytest fixtures from `conftest.py` (e.g., `server`, `session`) |
| 95 | +- Test helpers in `libtmux.test.*` for creating temporary sessions/windows |
| 96 | +- Legacy API tests kept separate in `tests/legacy_api/` |
| 97 | + |
| 98 | +### Current Development Focus |
| 99 | +Currently on `asyncio` branch implementing async support: |
| 100 | +- `AsyncTmuxCmd` class for async subprocess execution |
| 101 | +- `.acmd()` methods added to all tmux objects |
| 102 | +- Basic async tests in `test_async.py` |
| 103 | + |
| 104 | +## Important Notes |
| 105 | +- Supports tmux 1.8+ and Python 3.9+ |
| 106 | +- Uses numpy docstring convention |
| 107 | +- Strict typing with mypy |
| 108 | +- All new features should include tests and type hints |
| 109 | +- Format strings use tmux's format syntax (e.g., `#{session_name}`) |
0 commit comments