#3355·CowAgent

[Bug] read-only mode refuses valid git reads that use a global option (\git -C <dir> status\), blaming a path

Author: aniruddhaadak80Created Sep 29, 2026Updated Sep 29, 2026

English is recommended so global developers can help. 推荐使用英文提交,谢谢 ❤️

  • I'm on the latest version and searched existing issues (incl. closed) — no duplicate.

Environment

Version: current master (commit 08f64f7) OS: any — platform-independent Python: 3.11 / 3.13 (CI matrix) Mode: read-only (or workspace-write, which shares the same bash classifier for escalation and redirects)

What happened?

In read-only mode, read-only git commands that use a global git option taking a value are refused, and the refusal names a path instead of a sub-command.

_check_git_read_only() takes positional[0] as the sub-command:

python
positional = [a for a in args if not a.startswith("-") and not _is_operator(a)]
sub = positional[0].lower() if positional else ""

git accepts options before the sub-command, and several of them consume the following argument (-C <path>, -c <name>=<value>, --git-dir <path>, --work-tree <path>, --namespace <name>, --exec-path[=<path>]). So the option's value lands in positional[0] and is mistaken for the sub-command.

Steps to reproduce

python
>>> from agent.permission.policy import READ_ONLY, check_tool_call
>>> d = check_tool_call(READ_ONLY, "bash", {"command": "git -C /srv/app status"})
>>> d.allowed, d.reason
(False, "Blocked by permission mode 'read-only': 'git /srv/app' can change the repository. ...")

Expected: allowed — git -C <path> status is exactly as read-only as git status.

Actual: refused, and the reason blames git /srv/app, which is not a command.

Other affected forms:

Command Message today
git -C /srv/app status 'git /srv/app' can change the repository
git -c core.pager=cat log --oneline 'git core.pager=cat' can change the repository
git --git-dir /srv/app/.git log 'git /srv/app/.git' can change the repository
git --work-tree /srv/app status 'git /srv/app' can change the repository

The reason is also misleading, which matters more than the refusal: it tells the model a path is a sub-command, so the model has no idea what to change.

A second, related misclassification

_GIT_WRITE_FLAGS lists -c and -C as flags that "turn a read-only git sub-command into a write":

python
_GIT_WRITE_FLAGS = frozenset({
    "-d", "-D", "--delete", "-m", "-M", "--move", "-f", "--force", ...
    "--edit", "-e", "--prune", "--rename", "--create", "-c", "-C", "--amend",
})

Neither flag writes anything on its own — -C is just a working directory and -c sets one config value for a single invocation. Treating them as write flags means a legitimate read is refused twice over for a different reason:

python
>>> check_tool_call(READ_ONLY, "bash", {"command": "git -C /srv/app log"}).reason
"... 'git log -C' modifies the repository."

Suggested fix

Parse git's global options before identifying the sub-command: skip the option, and skip its value for the options that take one, then read the sub-command. Separately, drop -c / -C from _GIT_WRITE_FLAGS and stop the blanket positional[0] assumption.

Note this is the opposite direction to #3351, which is about writes slipping through — here reads are being refused, so it is safe to treat as a separate change. Suggested scope: the option parser, plus tests over the global-option forms above.

Logs

Not applicable — reproducible through check_tool_call as shown above.