Skip to content

Management commands

Kosmos's own manage.py commands, grouped by the app that defines them. Run one with python manage.py <command>, and add --help to see its arguments.

Which of these an operator needs, and when, is covered in Background worker.

accounts

Command What it does
reset_authenticator Remove a user's authenticator app, by email address, for when the phone is lost and no administrator can reset it from Settings > Users. The user gets the emailed code at their next sign-in.

calendar

Command What it does
sync_calendar Sync events with Google Calendar (two-way sync)

case

Command What it does
backfill_ocr Queue OCR processing for all existing PDF documents that have not been processed
build_semantic_index Embed matter materials for semantic search
cleanup_orphan_documents List document records whose files are missing from storage, and with --apply delete them (and their highlights). Reports only by default.
dedupe_documents Delete duplicate documents (same matter) that have no highlights or references
fingerprint_documents Compute content fingerprints for documents that lack them
fix_document_paths Fix document file paths from old naming format to current convention
purge_closed_chats Delete AI chat history (conversations, messages and their history rows) for matters closed longer than the retention window. Chats are working notes with no lasting value once a matter closes; the client file lives in Drive and Gmail. Scheduled weekly by setup_schedules.
setup_chat_purge_schedule Create or update the weekly chat-purge schedule (Sunday 03:00 local): deletes AI chat history for matters closed past the retention window. Superseded by setup_schedules, which installs this with every other schedule.
update_search_vectors Update search vectors for all documents and highlights

drive

Command What it does
link_drive_folders Link Google Drive matter folders (under the Drive root) to Matter records (Matter.drive_folder + drive_folder_id). Interactive; suggests matches by name. Subfolder mapping happens in the Documents tab.
restore_drive_documents Re-download Drive-mirrored documents whose file is missing from storage
sync_drive_notes Mirror PDFs under each matter's mapped Drive folders into Documents (append-only; categories and proceedings follow the Documents tab's Drive Folder mapping). The case-notes mirror is retired; files under Notes/ are ignored.

intakes

Command What it does
clean_intake_notes List intake notes whose intake is gone, and with --apply delete them. Reports only by default.
seed_intake_forms Create the starter intake form templates: example questionnaires from one firm's practice. Review and edit them before use.

invoicing

Command What it does
confido_check Read-only pre-flight check for the Confido processor (no charge).
generate_invoice_pdfs Generate and store PDFs for existing invoices
lawpay_accounts List LawPay/AffiniPay merchant deposit accounts (operating vs trust).
reconcile_pending Poll the processor for in-flight online payments and trust deposits and settle, confirm, or reverse them (missed-webhook backstop).

mail

Command What it does
adopt_gmail_account One-time multi-account migration: turn the legacy shared token file (GOOGLE_DATA_DIR/email_tokens.json) into the given user's GmailAccount, claim all existing Email rows, and backfill Email.message_id (the cross-mailbox dedupe key) from Gmail. Run BEFORE anyone else connects a mailbox.
link_gmail_labels Link Gmail labels to Matter records by setting Matter.gmail_label_name (the cross-mailbox contract). Interactive; suggests matches by name. Labels are read from the first connected mailbox.
refresh_email_bodies Refetch synced emails that have no stored HTML body (one-off backfill after the body_html field was added). Rows whose message genuinely has no HTML part are refetched each run; use --matter to limit scope.
setup_gmail_sync_schedule Create or update the Gmail sync schedules: an incremental history sync every 2 minutes and a weekly full re-list (early Monday) to reconcile drift the history feed can't repair. No env gate: the sync is read-only and no-ops when no Gmail account is connected. Superseded by setup_schedules, which installs these with every other schedule.
sync_gmail Sync labeled Gmail messages onto their mapped matters

management

Command What it does
clean_history Delete change-history records and failed worker tasks older than specified days (default: 90)
setup_schedules Create or update every recurring Django-Q schedule used by Kosmos.

notes

Command What it does
backfill_note_summaries Generate AI summaries for library notes whose summary is missing or stale. Queues onto qcluster by default; --sync runs inline.

tasks

Command What it does
setup_digest_schedule Create or update the daily digest email schedule. Superseded by setup_schedules, which installs this with every other schedule.