Example: Claude Code Wrapper

Copy-paste this example to get started. Modify the project and task IDs to match your workspace.

What This Does

A shell script that wraps a Claude Code session with Keito time tracking. It starts a timer before launching Claude Code and logs the time and token cost when the session ends.

Prerequisites

  • Keito CLI installed and authenticated
  • Claude Code installed
  • KEITO_API_KEY and KEITO_ACCOUNT_ID environment variables set

Full Code

#!/bin/bash
# keito-claude.sh — Track Claude Code sessions with Keito

set -e

PROJECT="${1:?Usage: keito-claude.sh <project-slug> [task-slug]}"
TASK="${2:-development}"
SESSION_ID=$(uuidgen)

echo "Starting Keito tracking for project: $PROJECT"

# Start the timer
keito time start \
  --project "$PROJECT" \
  --task "$TASK" \
  --source agent \
  --agent-id "claude-code" \
  --session-id "$SESSION_ID"

# Run Claude Code (interactive session)
claude "$@" || true

# Stop the timer
keito time stop --notes "Claude Code session"

echo "Session tracked. ID: $SESSION_ID"

How It Works

  1. Takes a project slug as the first argument and an optional task slug.
  2. Generates a unique session ID for correlation.
  3. Starts a Keito timer with source: agent and agent metadata.
  4. Launches Claude Code — the user works interactively.
  5. When Claude Code exits, stops the timer and logs the session.

Customisation

  • Add token logging: If your Claude Code wrapper outputs token usage, parse it and add keito expense log after stopping the timer.
  • Auto-detect project: Read from a .keito.toml file in the repo root instead of requiring a CLI argument.
  • Git integration: Include the current branch name or commit range in the notes.

Usage

# Basic usage
./keito-claude.sh acme-website

# With a specific task
./keito-claude.sh acme-website code-review

# Make it executable
chmod +x keito-claude.sh