Skip to content

Bug: hook rewrites unsupported docker compose subcommands, causing failures #336

@ronhanson

Description

@ronhanson

Problem

The auto-rewrite hook (rtk-rewrite.sh generated by rtk init -g) rewrites all docker compose commands to rtk docker compose, but RTK only supports a subset of subcommands: ps, logs, build.

Any other subcommand (config, up, down, exec, restart, etc.) or global docker compose flags (-f, --project-name) fail immediately:

$ docker compose -f docker-compose.base.yaml -f docker-compose.local.yaml config --services
# Hook rewrites to:
$ rtk docker compose -f docker-compose.base.yaml -f docker-compose.local.yaml config --services

error: unexpected argument '-f' found
Usage: rtk docker compose [OPTIONS] <COMMAND>

The agent then has to detect the failure and retry with /usr/local/bin/docker compose, wasting tokens on the error + retry.

Root cause

In the hook script, the docker compose match is unconditional:

if echo "$MATCH_CMD" | grep -qE '^docker[[:space:]]+compose([[:space:]]|$)'; then
    REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^docker /rtk docker /')"

It should only match the subcommands RTK actually implements (ps, logs, build).

Suggested fix

Restrict the hook pattern to supported subcommands only:

if echo "$MATCH_CMD" | grep -qE '^docker[[:space:]]+compose[[:space:]]+(ps|logs|build)([[:space:]]|$)'; then

This is a one-line change in the hook template. Relates to #276 (which requests adding more subcommands — until they're added, the hook shouldn't rewrite them).

On v0.22.2. Happy to submit a PR if that helps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions