rtk-ai/rtk

psql -h flag conflict + exclude_commands ignores env-var prefixed commands

Open

#917 opened on Mar 29, 2026

View on GitHub
 (3 comments) (1 reaction) (0 assignees)Rust (2,914 forks)batch import
area:clibugeffort-mediumhelp wantedpriority:mediumresolved-pending-close

Repository metrics

Stars
 (48,085 stars)
PR merge metrics
 (Avg merge 11d 1h) (45 merged PRs in 30d)

Description

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

  1. rtk psql should not consume -h as its own help flag — psql's -h means host, not help. Either use a different flag for RTK help or auto-insert -- before psql args.
  2. exclude_commands should match the actual command name even when preceded by inline env vars (e.g., VAR=val psql should still match the psql exclusion).

Environment

  • rtk 0.34.1
  • macOS (Darwin 25.4.0, arm64)
  • Claude Code hook v3
  • psql (PostgreSQL) 18.0

Contributor guide