This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Install in development mode
uv sync
# Run the CLI
uv run rw-cli --help
# Run tests
uv run pytest
# Lint
uv run ruff check .
uv run ruff format .The READER_API_TOKEN environment variable must be set to make API calls. Set it in a .env file or export it in the shell.
The CLI is built with Click and structured as a single package under src/readwise_reader_cli/.
Request flow for list:
commands.pyβ parses CLI options, manages a JSON file cache at~/.local/share/reader/library.json(1-minute expiry). Cache key is{location}_{category}_{update_after}.api.pyβ wraps the Reader API v3.list_documents()calls_fetch_results(), which paginates viapageCursoruntil exhausted. Rate limit retries are handled automatically.models.pyβ Pydantic models:ListParameters(serializes to API query params viaupdatedAfter/pageCursoraliases),DocumentInfo(represents a document).layout.pyβ renders output using rich as either a table (default) or list layout. Highlights/notes have a separate column layout.
lib command uses data.py which fetches the entire library (no filters) and caches it for 1 day at ~/.local/share/reader/full_library.json.
upload command uses reading_list/extractors.py to parse HTML or CSV reading list exports, then utils.batch_add_documents() to add them with a rich progress bar.
--update-afterdefaults toNone(no filter). When omitted, the API returns all documents for the given location. Use--date-range [today|week|month]for relative filtering.- The cache appends a
{"time": "..."}sentinel as the last element of each cached list β code that iterates results must slice it off with[:-1]. VALID_CATEGORY_OPTIONSinconstants.pyis the source of truth for allowed categories;constants.pyandmodels.py'sCategoryEnummust stay in sync.