OmniscioSubagent examplesData analyst
A data analyst subagent
A data question produces query output nobody wants in their conversation, and it wants one number back. It is also the one case where a tool rule is not enough on its own.
A subagent allowed Bash can run any command the credential behind it can run. Anthropic's documented answer is a PreToolUse hook that reads each command and refuses the writes, and this page's file uses exactly that shape.
Checked against Anthropic's Claude Code documentation on November 25, 2026. By the Omniscio team. Updated .
When Claude delegates to it
Claude matches your request against the description, and the description says what shape qualifies: counts, totals, trends, a join across tables. "Why is checkout slow" is not this agent; "how many checkouts failed by day last week" is.
Ask by name when the question is already precise: "use the data-analyst subagent: signups per week since June". The transcript shows the run, the query and the answer.
It does not know your schema. Either say the tables in the request, or give it Read so it can read the migration files and the schema dump.
The file
Save this as .claude/agents/data-analyst.md, and save the validation script it names beside your other scripts and make it executable. The path in hooks must match where you put the script; Anthropic's example calls it ./scripts/validate-readonly-query.sh.
---
name: data-analyst
description: Answers questions about data by running read-only SQL and returns the numbers with the query it ran and the assumptions behind it. Use when the question needs counts, totals, trends or a join across tables rather than a code change.
tools: Read, Bash
model: sonnet
hooks:
PreToolUse:
- matcher: "Bash"
hooks:
- type: command
command: "./scripts/validate-readonly-query.sh"
---
You answer questions about data. You can read, and you can run queries. You cannot change data.
1. Restate the question as something a query can answer, and name the table or file you expect to
read. If a table is ambiguous, say which one you used and why.
2. Write one query, with the filters the question implies. Add the date range as an explicit
condition, even when the question implies it.
3. Run it. If it errors, read the error and fix the query; do not fall back to a different table
without saying so.
4. Check the result for the obvious wrong answer: zero rows because a join key does not match, a
sum that includes test accounts, a date range that starts a day late.
5. Answer in this shape:
- The number, first, with its unit and its date range.
- The query, exactly as you ran it.
- What the query assumes, and what it does not cover.
- The confidence: measured, or estimated from a sample of N rows when a full query was not possible, saying why.
Never estimate a number when you can run the query. Never present a number you did not see in a
result. If you cannot query, say what is missing — the credential, the table, or the column.The script itself only has to read the call and refuse the writes. This one is ours, written to the shape Anthropic documents: JSON on stdin, exit code 2 to block.
#!/usr/bin/env bash
# scripts/validate-readonly-query.sh — blocks SQL writes from the data-analyst agent.
input=$(cat)
command=$(printf '%s' "$input" | jq -r '.tool_input.command // empty')
[ -z "$command" ] && exit 0
if printf '%s' "$command" | grep -qiE '\b(INSERT|UPDATE|DELETE|DROP|CREATE|ALTER|TRUNCATE|REPLACE|MERGE|GRANT|VACUUM|COPY)\b'; then
echo "Blocked: this agent runs read-only queries. Use SELECT." >&2
exit 2
fi
exit 0Make it executable with chmod +x, and keep the path in the agent file's hooks block pointing at wherever you saved it.
The hook is the backstop, not the permission. Anthropic's read-only database example pairs the script with a system prompt that refuses writes and calls the hook the backstop; the credential is the layer above both, because whatever it can do, the agent can do through Bash.
What each field does
name
The identifier Claude delegates to, at most 256 characters, no colon. Hooks receive it as agent_type.
description
The routing rule, and the line that keeps the agent away from code work. Naming the shape — counts, totals, trends — is what stops it being delegated a refactor. Every description is loaded so Claude knows what it can delegate to, and the total is counted at startup, so a narrow one costs less than a broad one.
tools
Two tools. Bash is the query client, whether that is psql, sqlite3, bq or a script in the repository. Read lets it check the schema and the migration files. There is no Write and no Edit, because the answer to a data question is a number, not a file.
Omitting Edit is not a fence on its own: Bash can still write. That is why the hook below exists, and why the credential matters more than either.
hooks
A PreToolUse hook scoped to this subagent. Claude Code passes the tool call to your script as JSON on stdin; a script that exits with code 2 blocks the call and returns its message to the agent. Anthropic's database query validator example is exactly this, and the script it ships checks the command for INSERT, UPDATE, DELETE, DROP, CREATE, ALTER, TRUNCATE, REPLACE and MERGE.
One precondition worth knowing before you rely on it: a project-level subagent's frontmatter hooks run only once you accept the workspace trust dialog for the folder holding the agent file. Until then the subagent still runs, and Claude Code skips its hooks and logs the reason to the debug log — a fence that is not there looks exactly like a fence that never fired.
model
Anthropic's own data scientist example sets sonnet explicitly for analysis, which is a reasonable default here too. The alternatives are opus, haiku, fable, a full model ID, or inherit.
Project file or user file
Project. The body names a script path, the schema lives in this repository, and the credential it inherits is the one this project sets up. A user-level copy would carry a relative script path into a project that has no such script, and the hook would fail on every call. Where a project and a user file share a name, the project's wins.
.claude/agents/is the project's, and committing it keeps the query rules reviewable.~/.claude/agents/is yours and follows you everywhere.- Two files with the same name in one directory means one never loads;
/doctorreports the pair.
Confirm Claude picked it up
- No restart. Both directories are watched and an edit is live within a few seconds, except for a folder added with
--add-diror a session started with--disable-slash-commands. - Ask a question you know the answer to, by name, and check that the returned query matches what you would have written.
- Test the fence. Ask it to delete a row. The hook should block the command and the agent should report the refusal — that is the one test of a read-only agent worth doing before you trust it.
/tasksshows the run and the model, which confirmssonnettook effect (v2.1.242 or later)./agentsconfirms the folders are the source of truth — it prints a reminder to manage agents through Claude or by editing them, and the wizard that listed them was v2.1.197 and earlier.
When it goes wrong
- The number is wrong and nobody can tell. A result with no query cannot be re-run. The answer shape in step 5 is what makes the number checkable.
- The join silently drops rows. The commonest data bug: an inner join on a key that does not match produces a plausible smaller number. Step 4's zero-row check is the guard, and naming the join key in the answer is the audit.
- The hook blocks everything. A script that fails to run, or a path that does not exist, blocks the call it cannot inspect. Make the script executable and check the path — Anthropic's example calls
chmod +xout directly. - It writes anyway. A hook is a check on the command text, not a permission. The credential is the real boundary, which is why the agent should run on a read replica or an analytics copy.
- It never launches. A
toolsentry that resolves to nothing is usually refused with an error naming the entries; an empty list, or onedisallowedToolsempties, launches with no tools.
Adapting it to your warehouse
- Point the script and the body at your client:
psql,sqlite3,bq query, or the repository's ownnpm run query. - Extend the blocked keyword list with your engine's own:
GRANT,VACUUM,COPY,CALL. - Name the tables that are off limits — the billing ledger, the PII table — and add them to the script, not only to the prompt.
- Add the definition your team argues about: active user, paid seat, churn. An agent that guesses a definition produces a number nobody will defend in a meeting.
The other files are on the subagent examples page, and the subagents guide covers what a subagent inherits, its hooks and its limits.
Sources
- Anthropic's Create custom subagents, for the frontmatter reference (including the
hooksfield), the tool restriction rules, and the Data scientist and Database query validator examples, read November 25, 2026. - Anthropic's error reference, for the zero-tools refusal and its exceptions, read November 25, 2026.
- Anthropic's commands reference, for
/agentsand/tasks, read November 25, 2026.
The agent file, its answer shape and the query rules were written for this site. The fields, the hook mechanism and the read-only validation example are Anthropic's and were read from the pages above on the same day. The agent was not run against a live database here.
Common questions
How do I make a database subagent read-only?
Two layers. A credential that can only read, and a PreToolUse hook that inspects every Bash command and exits with code 2 on a write keyword. Anthropic documents that pair in its database query validator example.
Why does it need Bash?
Because that is how it reaches the database: psql, mysql, sqlite3, bq, or your project's query script. The alternative is an MCP server that wraps the database and a tool from it in the tools list.
Can it touch production?
It can run whatever the credential behind it can run. Point it at a read replica or an analytics copy, and keep the write credential out of the environment it inherits. The hook is a second lock, not the door.
Why does it return a number with no query?
Because nothing required the query. The answer shape in the body makes the SQL part of the answer, and makes a number the agent did not see in a result a failed answer.
Numbers you can re-run
Omniscio is a desktop app for running Claude Code and other coding agents side by side, with one list of sessions and one inbox, so an agent only interrupts you when a decision needs you.
The features page lists what is in it today, pricing covers the plans, and you can download it for Windows, macOS or Linux.