From 46b2e99f181979c30b787cc0cf363fed6bda8e60 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 16 Nov 2025 14:19:55 +0000 Subject: [PATCH] Add Claude Code online environment support This commit adds complete support for Claude Code online environment: - Add .claude/hooks/SessionStart: Automatically sets up pixi and dependencies - Add .claude/README.md: Comprehensive documentation for Claude Code usage - Add .claude/activate.sh: Manual environment activation script - Update README.md: Add Claude Code section with quick start guide The SessionStart hook automatically: - Installs pixi package manager if not present - Installs all project dependencies via pixi - Sets up pre-commit hooks - Configures git merge drivers This enables immediate development in Claude Code online without manual setup. --- .claude/README.md | 63 ++++++++++++++++++++++++++++++++++++++ .claude/activate.sh | 19 ++++++++++++ .claude/hooks/SessionStart | 50 ++++++++++++++++++++++++++++++ README.md | 21 +++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 .claude/README.md create mode 100755 .claude/activate.sh create mode 100755 .claude/hooks/SessionStart diff --git a/.claude/README.md b/.claude/README.md new file mode 100644 index 0000000..0b0cc31 --- /dev/null +++ b/.claude/README.md @@ -0,0 +1,63 @@ +# Claude Code Configuration + +This directory contains configuration for using this project with Claude Code, particularly in the online environment. + +## SessionStart Hook + +The `hooks/SessionStart` script automatically runs when a new Claude Code session begins. It: + +1. **Installs pixi** (if not already installed) - The package and environment manager +2. **Installs project dependencies** - All Python packages and tools defined in `pyproject.toml` +3. **Sets up pre-commit hooks** - For automatic code quality checks +4. **Configures git** - Sets up merge drivers for lockfiles + +## Usage with Claude Code Online + +When you start a Claude Code online session, the SessionStart hook will automatically run and set up your environment. You'll see output indicating the setup progress. + +### Available Commands + +Once setup is complete, Claude can use these pixi tasks: + +#### Testing & Quality +- `pixi run test` - Run pytest tests +- `pixi run coverage` - Run tests with coverage report +- `pixi run lint` - Run ruff and pylint linters +- `pixi run format` - Format code with ruff + +#### CI Tasks +- `pixi run ci` - Run full CI pipeline (format, lint, test, coverage) +- `pixi run fix` - Auto-fix common issues (update lock, format, lint) + +#### Pre-commit +- `pixi run pre-commit` - Run all pre-commit hooks +- `pixi run pre-commit-update` - Update pre-commit hook versions + +### How It Works + +1. **First session**: The hook installs pixi and all dependencies (may take a few minutes) +2. **Subsequent sessions**: The hook verifies the environment is ready (much faster) +3. **Environment activated**: All pixi commands are available to Claude + +### Troubleshooting + +If you encounter issues: + +1. **Dependencies not found**: Run `pixi install` manually +2. **Lockfile conflicts**: Run `pixi run update-lock` +3. **Pre-commit issues**: Run `pixi run pre-commit-update` +4. **Full reset**: Delete `.pixi` directory and restart session + +### Customization + +You can modify `hooks/SessionStart` to: +- Install additional tools +- Run custom setup scripts +- Configure environment variables +- Set up external services + +## Learn More + +- [Claude Code Documentation](https://docs.claude.com/claude-code) +- [Pixi Documentation](https://pixi.sh) +- [Project README](../README.md) diff --git a/.claude/activate.sh b/.claude/activate.sh new file mode 100755 index 0000000..c6ca221 --- /dev/null +++ b/.claude/activate.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# Source this file to activate the pixi environment in your current shell +# Usage: source .claude/activate.sh + +# Add pixi to PATH +export PATH="$HOME/.pixi/bin:$PATH" + +# Optional: Activate pixi shell if available +if command -v pixi &> /dev/null; then + echo "✅ Pixi environment activated" + echo "💡 Available commands:" + echo " pixi run test - Run tests" + echo " pixi run lint - Run linters" + echo " pixi run format - Format code" + echo " pixi run ci - Run full CI" + pixi task list --summary 2>/dev/null || true +else + echo "⚠️ Pixi not found. Please run .claude/hooks/SessionStart first." +fi diff --git a/.claude/hooks/SessionStart b/.claude/hooks/SessionStart new file mode 100755 index 0000000..14958b5 --- /dev/null +++ b/.claude/hooks/SessionStart @@ -0,0 +1,50 @@ +#!/bin/bash +# SessionStart hook for Claude Code online environment +# This script sets up the Python development environment using pixi + +set -e + +echo "🚀 Setting up Python Template environment..." + +# Check if pixi is installed +if ! command -v pixi &> /dev/null; then + echo "📦 Installing pixi..." + curl -fsSL https://pixi.sh/install.sh | bash + + # Add pixi to PATH for current session + export PATH="$HOME/.pixi/bin:$PATH" + + # Source bashrc to get pixi in PATH (if bashrc was updated) + [ -f "$HOME/.bashrc" ] && source "$HOME/.bashrc" + + echo "✅ Pixi installed successfully" +else + echo "✅ Pixi already installed" +fi + +# Ensure pixi is in PATH for this session +export PATH="$HOME/.pixi/bin:$PATH" + +# Install project dependencies +echo "📦 Installing project dependencies..." +pixi install + +# Run pre-commit installation +echo "🔧 Setting up pre-commit hooks..." +pixi run pre-commit install || echo "⚠️ Pre-commit installation skipped (optional)" + +# Set up git merge driver for lockfiles +echo "🔧 Configuring git merge driver..." +pixi run setup-git-merge-driver || true + +echo "✅ Environment setup complete!" +echo "" +echo "Available pixi tasks:" +pixi task list +echo "" +echo "💡 Common commands:" +echo " pixi run test - Run tests" +echo " pixi run lint - Run linters" +echo " pixi run format - Format code" +echo " pixi run ci - Run full CI pipeline" +echo "" diff --git a/README.md b/README.md index 24dd05d..8e9aa8a 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,27 @@ If you want to use docker you may want to run the `scripts/setup_host.sh` script If you are using pixi, look at the available tasks in pyproject.toml If you are new to pixi follow the instructions on the pixi [website](https://prefix.dev/) +# Claude Code Online Support + +This template includes built-in support for [Claude Code](https://docs.claude.com/claude-code) online environment! The `.claude/hooks/SessionStart` script automatically: + +- Installs pixi package manager +- Sets up all project dependencies +- Configures pre-commit hooks +- Prepares the development environment + +**Quick Start with Claude Code:** +1. Open this repository in Claude Code online +2. The environment sets up automatically via the SessionStart hook +3. Claude can immediately run commands like `pixi run test`, `pixi run lint`, etc. + +**Manual activation (if needed):** +```bash +source .claude/activate.sh +``` + +See [.claude/README.md](.claude/README.md) for detailed information about the Claude Code configuration. + # Github setup There are github workflows for CI, codecov and automated pypi publishing in `ci.yml` and `publish.yml`.