A command-line tool for creating and managing Google Contacts, including copying contacts and collecting email addresses from Gmail senders or webpages.
Requires macOS or Linux, Python 3.11 or newer, and uv. From a checkout:
uv sync --locked
./contacts-cli --helpFollow Google setup to create the Desktop OAuth client file and save it as
~/.config/contacts-cli/credentials.json. Then authorize your account:
./contacts-cli authorizeLater commands reuse the saved authorization. Local file validation needs no Google setup.
- Replace the example values below with your own.
--contactaccepts a Google Contacts URL such ashttps://contacts.google.com/person/c123456789or its bare ID,c123456789. - Commands that change contacts or labels show a preview and ask for confirmation. With multiple
choices, contact creation, sender-sync, email edits, custom-field edits, and label removal offer
selection by number/range. Enter or
nat the subsequent confirmation returns to selection;qcancels. A simple[y/N]prompt writes only afteryoryes. --applyselects all eligible items and skips final confirmation; conflict choices follow each command's rules. Piped or redirected runs without--applydo not write.add-contactandduplicatecreate new contacts each time; they do not merge with existing ones.- Use
./contacts-cli <command> --helpfor command options. Global options, including--token, appear in./contacts-cli --helpand work before or after the command.
./contacts-cli add-contact --name 'Jane Doe' --email [email protected]
./contacts-cli add-contact --file contacts.json --label RecruiterUse --name for a full name that Google parses, or --first-name and --last-name for explicit
components (together or individually). Combine either form with emails, or use a JSON file for
one or more contacts with additional fields. For multiple contacts, choose all or numbers/ranges such as 2,4-6, then confirm.
--apply creates every input contact without selection. Each new contact gets a Created
custom field with its creation time.
See contact input and creation.
./contacts-cli duplicate --contact c123456789 --name 'Delivery backup'Copies editable fields and the custom photo, and adds a Duplicate custom field with the
creation time. Omitted options keep the original fields. Use --name, repeatable --email, or
repeatable --phone to replace a field, or --clear-name, --clear-email, and --clear-phone
to leave it empty. --no-photo skips the photo. The source contact stays unchanged.
./contacts-cli duplicate --contact c123456789 --name 'Jane Doe' \
--email [email protected] --clear-phone --no-photo--name supplies a full name for Google to parse. Use --first-name and/or --last-name instead
for explicit components. Either form replaces the entire original name; omitted components are
empty. Replacement emails and phones replace the entire original list and have no labels.
See duplication details.
Adds missing sender addresses from a Gmail label or search, excluding addresses already on the contact and your Gmail sending addresses. Sender names become email labels when useful.
./contacts-cli sender-sync --label 'Example/Delivery' --contact c123456789Use either --label or --search:
./contacts-cli sender-sync --search 'from:example.com after:2026/01/01' --contact c123456789Case-only Gmail label matches prompt for a choice in interactive runs. A label can contain
messages from unrelated senders; use --exclude or --exclude-file to skip their addresses.
With --search 'from:dhl.com OR subject:dhl', the preview separates addresses matching dhl.com
from other senders. You can choose to skip those other senders, or use --exclude-other to skip
them automatically. You can then choose all remaining addresses or some by number.
--apply alone includes both groups without selection. See address selection rules.
Use --exclude ADDRESS or a quoted pattern such as --exclude '*@example.com' to skip senders.
* matches zero or more characters, ignoring case. --exclude-file PATH accepts one address or
pattern per line, without shell quotes. Wildcards filter discovered senders locally. See search and exclusion details.
Malformed From headers are skipped with a warning and local diagnostic log; valid senders
can still be added. Reply-To addresses are not collected.
./contacts-cli list-email --contact c123456789Shows a numbered list with labels and duplicate references.
./contacts-cli add-email --contact c123456789 --add '[email protected] — Work'
./contacts-cli remove-email --contact c123456789 --remove [email protected]Repeat the address option or use --add-file / --remove-file for lists. Removal also accepts
* patterns: --remove '*@example.com'. * matches zero or more characters, ignoring case;
quote patterns in the shell, but not in files. Removal deletes all
matching entries. Adding an existing address can change its label or consolidate duplicates.
Select all proposed changes or specific numbers/ranges before confirming. Each removal number
selects one address and all its duplicate entries.
For a webpage, use --from-url instead of address/file options:
./contacts-cli add-email --contact c123456789 --from-url 'https://example.com/contact'Enter all or numbers/ranges such as 3-5,8, then confirm. New addresses have
no labels; existing addresses and labels stay unchanged. --apply adds all new addresses.
See webpage input and
email conflict and apply rules.
./contacts-cli list-label
./contacts-cli add-label --label Recruiter
./contacts-cli list-label --contact c123456789
./contacts-cli add-label --contact c123456789 --label Recruiter
./contacts-cli remove-label --contact c123456789 --label Recruiterlist-label lists all account user labels with their contact counts. With --contact, it lists
only that contact’s labels, without counts.
add-label without --contact creates account labels. With --contact, it adds labels to that
contact, creating missing labels first. Case-only matches may require a choice even with --apply.
Repeat --label for multiple labels when adding or removing.
remove-label requires a contact and offers only labels attached to it. It accepts names or
quoted * patterns such as --label 'Recruit*', including case variants. Choose all or numbered
labels before confirming; --apply removes all matches. Removal detaches labels from this contact;
the labels themselves remain available in the account.
See label choices.
./contacts-cli add-custom-field --contact c123456789 --field 'Pipeline ID' P-001
./contacts-cli remove-custom-field --contact c123456789 --key 'Pipeline ID' --value P-001
./contacts-cli remove-custom-field --contact c123456789 --key CreatedRepeat --field KEY VALUE to add multiple pairs; quote text containing spaces. Addition matches
exactly, skips existing pairs, and offers selection when several new pairs are proposed.
Removal offers exact and case-different matches in separate selectable groups. Without --value,
it offers all values under the key and its case variants. Choose all or numbers/ranges
before confirming; identical key/value duplicates stay together. --apply removes all matches,
including case variants.
See custom field details.
./contacts-cli validate-contact --file contacts.jsonValidates locally without authorization or Google access. See validation details.
- Command reference: options, matching, conflicts, limits, and exit codes.
- Contact input: JSON fields, validation, and creation outcomes.
- Google setup: credentials, permissions, and authorization troubleshooting.
- Diagnostic logs: API errors, email-verification failures, and sender-sync traces.
- Local metrics: sender-sync timing and API counts;
make metricssummarizes runs. - Contributing and testing: development workflow and checks.