psql -h flag conflict + exclude_commands ignores env-var prefixed commands
#917 创建于 2026年3月29日
仓库指标
- Star
- (48,085 star)
- PR 合并指标
- (平均合并 11天 1小时) (30 天内合并 45 个 PR)
描述
Summary
Two related issues with rtk psql and the hook rewrite system:
1. psql -h (host) conflicts with rtk psql -h (help)
When the hook rewrites psql -h localhost -p 54322 ... → rtk psql -h localhost -p 54322 ..., RTK interprets -h as its own --help flag instead of passing it through to psql as the host flag.
Repro:
# This prints RTK help instead of connecting to postgres:
PGPASSWORD=postgres rtk psql -h localhost -p 54322 -U postgres -d postgres -c 'SELECT 1'
# Workaround — use `--` separator:
PGPASSWORD=postgres rtk psql -- -h localhost -p 54322 -U postgres -d postgres -c 'SELECT 1'
# ✅ Works correctly
The -- workaround works, but the hook-generated rewrite doesn't include it, so psql is broken out of the box when used with -h for host.
2. exclude_commands in config.toml doesn't match env-var-prefixed commands
Setting exclude_commands = ["psql"] in config.toml correctly excludes bare psql commands:
rtk rewrite "psql -h localhost" # EXIT: 1 ✅ excluded
But the common pattern PGPASSWORD=x psql ... is still rewritten:
rtk rewrite "PGPASSWORD=postgres psql -h localhost -p 54322 -U postgres -d postgres"
# Output: PGPASSWORD=postgres rtk psql -h localhost ... (EXIT: 0 — still rewritten)
It seems rtk rewrite parses the first token as the command name. When the command is prefixed with env vars (PGPASSWORD=postgres psql ...), the exclude check doesn't match psql because the first token is PGPASSWORD=postgres.
Expected behavior
rtk psqlshould not consume-has its own help flag — psql's-hmeans host, not help. Either use a different flag for RTK help or auto-insert--before psql args.exclude_commandsshould match the actual command name even when preceded by inline env vars (e.g.,VAR=val psqlshould still match thepsqlexclusion).
Environment
- rtk 0.34.1
- macOS (Darwin 25.4.0, arm64)
- Claude Code hook v3
- psql (PostgreSQL) 18.0