Skip to content

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

@timwagnerjr-athleticops

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingeffort-medium1-2 jours, quelques fichiersresolved-pending-closeAnswered/resolved — will close if no response

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions