Skip to content
CLI tool · Databases

sqlite3 for AI agents

The sqlite3 shell for coding agents: list tables, read schemas, query in read-only mode with JSON output, and back up a database before any change.

sqlite3by SQLite project
What it is

What sqlite3 does for an agent

sqlite3 is the official command-line shell for SQLite. It opens a database file, runs SQL, and has dot-commands such as .tables, .schema, and .backup.

It can open a file read-only and print results as JSON, which makes it easy for an agent to inspect an app's local database without risking the data.

Official site: sqlite.org

Install

Install sqlite3

The install commands from the official docs. Check it worked with sqlite3 --version.

Homebrew
brew install sqlite
Debian or Ubuntu
sudo apt-get install sqlite3
Auth

Signing in sqlite3 for an agent

No sign-in. Access is controlled by file permissions on the database file.

Common agent tasks

What agents use sqlite3 for

Example commands with placeholder names. Swap in your own project, app, or file names.

  1. List tables

    sqlite3
    sqlite3 -readonly app.db ".tables"
  2. Show a table's schema

    sqlite3
    sqlite3 -readonly app.db ".schema users"
  3. Query as JSON in read-only mode

    sqlite3
    sqlite3 -readonly -json app.db "SELECT id, email FROM users LIMIT 10;"
  4. Back up before changing anything

    sqlite3
    sqlite3 app.db ".backup app.backup.db"
Safety

Safety rules for agents

Safe to run without asking

  • sqlite3 -readonly file ".tables"
  • sqlite3 -readonly file ".schema"
  • sqlite3 -readonly file "SELECT ..."

Ask a human first

  • INSERT, UPDATE, DELETE
  • CREATE, ALTER, DROP
  • VACUUM
  • writing to a database file another process has open
  • Open databases with -readonly unless a change was requested.
  • Make a .backup copy before any write, and say where it is.
  • Do not write to the database of a running app; SQLite allows one writer at a time and the app may hold locks.
Agent instructions

AGENTS.md or CLAUDE.md snippet

Paste this into the instruction file your agent reads at the start of every session, then adjust the rules to your setup.

AGENTS.md
## sqlite3

Use `sqlite3` for inspecting and querying SQLite database files.

- Check it is installed with `sqlite3 --version`. If it is missing, ask before installing it.
- Auth: none needed.
- Run without asking (read-only): `sqlite3 -readonly file ".tables"`, `sqlite3 -readonly file ".schema"`, `sqlite3 -readonly file "SELECT ..."`.
- Ask a human first (changes or deletes things): `INSERT, UPDATE, DELETE`, `CREATE, ALTER, DROP`, `VACUUM`, `writing to a database file another process has open`.
- Open databases with -readonly unless a change was requested.
- Make a .backup copy before any write, and say where it is.
- Do not write to the database of a running app; SQLite allows one writer at a time and the app may hold locks.
- Prefer JSON output where the command supports it, and keep output short.
CLI or MCP server?

sqlite3 or an MCP server?

No official MCP server. SQLite has no official MCP server; community servers exist. For local files, the sqlite3 shell is usually simpler and gives the agent the same power.

Rule of thumb: in a terminal agent that a human has signed in, the CLI is usually faster and cheaper in context. In a chat client without a shell, or when you want a fixed set of typed tools, use an MCP server.

Same category
All Databases tools
FAQ

sqlite3 questions

How do I install sqlite3?

Homebrew: brew install sqlite. Other official options: Debian or Ubuntu. Check the install with sqlite3 --version, and see the SQLite project docs for other platforms.

How does an AI agent authenticate sqlite3?

No sign-in. Access is controlled by file permissions on the database file. There is nothing to set up: an agent can use it as soon as sqlite3 --version succeeds.

Which sqlite3 commands are safe for an agent to run?

Commands that only read state are safe to run without asking: sqlite3 -readonly file ".tables"; sqlite3 -readonly file ".schema"; sqlite3 -readonly file "SELECT ...". Ask a human before anything that changes or deletes something: INSERT, UPDATE, DELETE; CREATE, ALTER, DROP; VACUUM; writing to a database file another process has open.

Is there an MCP server for sqlite3?

SQLite has no official MCP server; community servers exist. For local files, the sqlite3 shell is usually simpler and gives the agent the same power.