database-optimization — Claude Code subagent: what it does
A subagent for slow queries: reads execution plans, suggests indexes and connection pool settings.
npx claude-code-templates@latest --agent database/database-optimizationWhat database-optimization does
The database-optimization subagent handles database performance work: execution plan analysis, indexing, connection pooling, transactions, schema design. It runs with Read, Write, Edit and Bash, so it can fire off EXPLAIN ANALYZE itself and edit your SQL files.
The workflow is measure first, optimize second. It won't guess from source code alone — it asks for real numbers and builds indexes from actual query patterns. You get rewritten queries with plan comparisons, index recommendations with impact estimates, connection pool configs, and monitoring queries. PostgreSQL and MySQL get engine-specific treatment.
Worth reaching for when a query suddenly crawls and the cause isn't obvious. Without access to a live database or at least its statistics, though, there's little to work with: the subagent needs real execution plans, not guesses. Behind a proxy or private mirror, set that up in your environment or the tool's config file rather than on the install line.
What it helps with
- trace a slow query back through its execution plan
- pick indexes that match real query patterns
- compare plans before and after rewriting SQL
- size a connection pool for the workload
- review schema design and plan migrations
Example prompts for the agent
- Dig into this slow query: pull the execution plan and tell me what to rewrite
- Check the indexes on the orders table and tell me which ones are missing
- Compare the execution plan before and after my query change
How to install database-optimization
1claude-code-templates
npx claude-code-templates@latest --agent database/database-optimization2Manually: put the files in place
.claude/agents/database-optimization.mdFor all projects use ~/.claude/agents/. Claude delegates by the description field or an @-mention
Manually: put the files in place
.codex/agents/database-optimization.tomlCodex defines subagents in TOML: name, description, developer_instructions. Move the Markdown text into developer_instructions by hand. For all projects use ~/.codex/agents/
Manually: put the files in place
.cursor/agents/database-optimization.mdCursor also reads .claude/agents/
Step by step, with commands for each platform: Claude Code subagents: how to create one, call it and keep context clean
Questions about database-optimization
How do I install database-optimization in Claude?
Through the templates CLI: npx claude-code-templates@latest --agent database/database-optimization. The subagent file then lives at .claude/agents/database-optimization.md.
What does database-optimization do?
It analyzes query execution plans, recommends indexes, tunes connection pooling and transactions, and suggests schema changes with migration paths.
Which tools can the subagent use?
Read, Write, Edit and Bash. The Bash tool is how it runs EXPLAIN ANALYZE against your database.