Retrieves 2FA codes from Apple Messages

Usage no npm install needed!

<script type="module">
  import famsg from 'https://cdn.skypack.dev/2famsg';



npm npm License: MIT Twitter: @selfagency_llc

Retrieve 2FA codes from Apple Messages on MacOS as JSON output with CLI or API


npm install -g 2famsg || yarn global add 2famsg

CLI Usage

2famsg [-a | --alfred] [-d | --database DATABASE_PATH] [-q | --query QUERY_TERM]

Also available via npx but loads much more slowly.

CLI Options

  • -a or --alfred [Boolean]: Format output for Alfred
  • -d or --database [String]: Specify database path (Default: ~/Library/Messages/chat.db)
  • -q or --query [String]: Term by which to filter results (eg., facebook or amazon)

Node Module Usage

const twoFactorMsg = require('2famsg')
const codes = async () =>
  await twoFactorMsg({
    query: 'facebook'

Module Options

  • alfred [Boolean]: Format output for Alfred
  • database [String]: Specify database path (Default: ~/Library/Messages/chat.db)
  • query [String]: Term by which to filter results (eg., facebook or amazon)

Build Binaries

npm run build:sqlite
npm run build:bin


👤 Daniel Sieradski hello@self.agency


The SQLite query was lifted from Scott Carpenter's alfred-imessage-2fa Alfred workflow, which I modified somewhat. Scott's project was a great start but I was looking for a more robust solution and decided to build one in a language in which I felt more comfortable jamming on the code.


Contributions, issues and feature requests are welcome! Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!