Skip to main content

Generate professional timesheets from Claude Code session history

Project description

Claude Code Timesheets

License: MIT Python 3.8+

Generate professional timesheets from your Claude Code session history. Automatically track billable hours across projects with intelligent activity grouping and weekly summaries.

One command does it all: cctimesheet automatically parses your Claude Code messages and generates a formatted timesheet with weekly totals and daily breakdowns—no manual database setup required.

Features

  • 📊 Accurate Time Tracking - Groups messages into 15-minute activity blocks
  • 📈 Weekly Summaries - Automatic weekly totals for easy billing and reporting
  • 🔍 Project Filtering - Filter and exclude projects using glob patterns
  • 📅 Flexible Date Ranges - View by days ago or specific date ranges
  • 💾 Smart Database - Automatic temporary database creation and cleanup
  • 🎯 Zero Dependencies - Pure Python 3 standard library
  • 🚀 Simple CLI - Single command workflow with comprehensive help

Quick Start

Installation with pipx (Recommended)

# Install directly from GitHub
pipx install git+https://github.com/pdenya/cctimesheet.git

# Or install from local clone
git clone https://github.com/pdenya/cctimesheet.git
cd cctimesheet
pipx install .

No additional dependencies required - uses Python 3 standard library only.

Alternative: Install with pip

pip install git+https://github.com/pdenya/cctimesheet.git

Usage Examples

The cctimesheet command automatically parses your Claude Code messages and generates a timesheet in one step.

Basic Timesheets

# Last 7 days (default)
cctimesheet

# Last 14 days
cctimesheet 14

# Since October 1, 2025
cctimesheet 20251001

Project Filtering

# All acme projects (last 7 days)
cctimesheet -p "*acme*"

# Specific client project since Oct 1
cctimesheet 20251001 -p "*client*"

# Backend projects (last 30 days)
cctimesheet 30 --project-filter "*backend"

Advanced Filtering

# Exclude specific projects
cctimesheet -p "*client*" -e "*test*"

# Group time by unique timeblocks (don't double-count same block across projects)
cctimesheet -p "*client*" -g

# Combine filters with grouped time
cctimesheet 30 -p "*api*" -e "*test*" --group-time

Database Options

# Use persistent database for faster subsequent runs
cctimesheet --db ~/timesheets/october.db --keep-db

# Parse from custom location
cctimesheet --projects-dir /path/to/projects

# View help
cctimesheet --help

How It Works

Time Calculation Method

Claude Code Timesheets uses 15-minute activity blocks to calculate billable hours:

  • Messages are grouped into 15-minute intervals
  • Multiple messages in the same interval count as one block (0.25 hours)
  • Gaps with no activity are automatically excluded (breaks, idle time)

Example:

14:42 - User message
14:43 - Assistant response  } → 1 block at 14:30-14:45
14:44 - User follow-up
14:50 - Assistant response  } → 1 block at 14:45-15:00

Total: 2 blocks × 0.25 hours = 0.5 billable hours

This method provides accurate tracking of actual work time while filtering out breaks, lunch hours, and other idle periods.

Data Source

Claude Code stores conversation history as JSONL files in ~/.claude/projects/. Each project directory contains session files with:

  • Message timestamps (ISO 8601 format)
  • Session IDs
  • Message types (user, assistant, system)
  • Message UUIDs

The parser extracts these timestamps and indexes them in SQLite for fast querying.

Output Example

================================================================================
CLAUDE CODE TIMESHEET
================================================================================
Since October 01, 2025 | Filter: *client-project*

WEEKLY SUMMARY
--------------------------------------------------------------------------------
  Oct 27 - Nov 02, 2025                                         19.75 hrs
  Oct 20 - Oct 26, 2025                                         21.50 hrs
  Oct 13 - Oct 19, 2025                                          5.25 hrs
  Oct 06 - Oct 12, 2025                                         11.00 hrs


DAILY BREAKDOWN
--------------------------------------------------------------------------------

Friday, Nov 01, 2025

  client-project/api                                                 3.50 hrs
  client-project/frontend                                            1.25 hrs
  ----------------------------------------------------------------- ---------
  Daily Total                                                        4.75 hrs

Thursday, Oct 31, 2025

  client-project/api                                                 5.00 hrs
  ----------------------------------------------------------------- ---------
  Daily Total                                                        5.00 hrs

...

================================================================================
  TOTAL HOURS                                                       57.50 hrs
================================================================================

Maintenance

How the Database Works

By default, cctimesheet creates a temporary database each time you run it. The database is automatically cleaned up after generating the timesheet. This means:

  • ✅ No manual database management required
  • ✅ Always uses the latest Claude Code data
  • ✅ No leftover files to clean up

Using a Persistent Database (Optional)

For faster repeated queries, you can use a persistent database:

# First run creates the database
cctimesheet --db my_timesheet.db --keep-db

# Subsequent runs are faster (reuses existing data)
cctimesheet --db my_timesheet.db

# To refresh with new sessions, delete and recreate
rm my_timesheet.db
cctimesheet --db my_timesheet.db --keep-db

The import process typically takes a few seconds for hundreds of sessions.

Database Schema

CREATE TABLE messages (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    timestamp TEXT NOT NULL,
    session_id TEXT NOT NULL,
    project_name TEXT NOT NULL,
    message_type TEXT,
    uuid TEXT,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

-- Indexes for fast queries
CREATE INDEX idx_session_id ON messages(session_id);
CREATE INDEX idx_timestamp ON messages(timestamp);
CREATE INDEX idx_project_name ON messages(project_name);

Requirements

  • Python: 3.8 or higher
  • Operating System: macOS, Linux, or Windows
  • Claude Code: Installed with conversation history in ~/.claude/projects/

FAQ

Q: Why 15-minute blocks instead of exact time? A: 15-minute blocks provide a standard billing increment and naturally filter out idle time while remaining accurate for professional timesheets.

Q: How are weekly summaries calculated? A: Weeks start on Monday and end on Sunday. The timesheet groups all activity within each week and displays the total hours for that week range. This makes it easy to see weekly billing totals at a glance.

Q: What does the --group-time flag do? A: By default, if you work on multiple projects during the same 15-minute block, each project counts that block separately. With --group-time (-g), unique timeblocks are counted only once across all filtered projects, preventing double-counting when multitasking.

Q: Can I use this for invoicing? A: Yes! The output provides verifiable timestamps and session IDs for audit purposes. Consider adding your own verification process.

Q: Does this modify my Claude Code data? A: No. The tool only reads JSONL files. All data is temporarily stored (or in a separate database if --db is used).

Q: What if I have multiple Claude Code installations? A: Use --projects-dir to specify the location of your .claude/projects directory.

Development

# Clone the repository
git clone https://github.com/pdenya/cctimesheet.git
cd cctimesheet

# Create a virtual environment
python3 -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install in editable mode
pip install -e .

# Run the command
cctimesheet --help

Contributing

Contributions welcome! Please feel free to submit a Pull Request to github.com/pdenya/cctimesheet.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cctimesheet-1.0.0.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cctimesheet-1.0.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file cctimesheet-1.0.0.tar.gz.

File metadata

  • Download URL: cctimesheet-1.0.0.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for cctimesheet-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5f357bcb0993afd62b9613ca5c541eea9dd6ca5642cc192808565132704718f8
MD5 39f1bc07c717ace3bd2812898b7b6290
BLAKE2b-256 fea5e7388d420e4ead270912edcf0dfd9b37e059c82a630f4eb6e59618c55356

See more details on using hashes here.

File details

Details for the file cctimesheet-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cctimesheet-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for cctimesheet-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c411d2667ec5917fe3d2aedf359527f889790eec9618afae1b9dcdb5c3e3c509
MD5 1989c99204d6ef697d97f5b6e0ef8d19
BLAKE2b-256 71b1188319bf1bf01e4b8fe6fcb02b75e49f8c7767b62bdf7e0fadad9b6dd007

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page