Add agentArgs config field for pass-through CLI flags#44
Open
oleksiimazurenko wants to merge 1 commit into
Open
Add agentArgs config field for pass-through CLI flags#44oleksiimazurenko wants to merge 1 commit into
oleksiimazurenko wants to merge 1 commit into
Conversation
Adds a `.cook/config.json` field `agentArgs` that appends user-supplied
CLI flags to the agent invocation on every cook step. Native and docker
runners both honor it. Defaults to {} — fully opt-in.
{
"agentArgs": {
"claude": ["--mcp-config", ".cook/mcp.json", "--add-dir", "/x"],
"codex": ["--profile", "fast"]
}
}
Env-var override for one-off runs: COOK_AGENT_ARGS_<AGENT>.
Append-only — base flags (--permission-mode acceptEdits, etc.) stay;
users can override via CLI last-flag-wins semantics. POSIX single-quote
escaping in the docker shell-string interpolation.
15 unit tests added (tsx + node --test). See plans/p9r-agent-args/ for
research, plan, devlog, code-review, and PR description.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
agentArgsconfig field — pass-through extra CLI flags to agent binariesAdds a
.cook/config.jsonfieldagentArgsthat appends user-supplied CLI flags to the agent invocation on every cook step (work, review, gate, iterate, ralph, race, judge, shell). Native and docker runners both honor it. Defaults to{}— fully opt-in, no behavior change for existing configs.Motivation
Today the flags passed to
claude -p/codex exec/opencode runare hardcoded in two places (src/native-runner.ts:111,src/sandbox.ts:254). Real workflows that need extra flags — most notably--mcp-configand--add-dirfor Claude Code — cannot be expressed in cook config and force users into private forks orPATH-shadowing wrappers (which break inside the docker sandbox).This PR adds a single config field that unblocks every "I just need to pass
--my-flag" case without committing cook to know each agent's flag surface.Usage
{ "agent": "claude", "agentArgs": { "claude": ["--mcp-config", ".cook/mcp.json", "--add-dir", "../shared"], "codex": ["--profile", "fast"] } }Or as an env-var override for one-off runs (space-separated, POSIX shell quoting):
Design Decisions
Partial<Record<AgentName, string[]>>), not a flat list — agents have disjoint CLI surfaces; a flat list would silently misapply flags.--permission-mode bypassPermissionsto override the native runner'sacceptEditsdefault).cookinvocations hard to reason about ("what's actually being passed?").agentArgsin v1 — extends cleanly tosteps.<name>.agentArgslater if needed.See
plans/p9r-agent-args/research.mdandplans/p9r-agent-args/plan.mdfor full rationale.Files Changed
src/config.ts— newAgentArgstype,agentArgsfield onCookConfig,parseAgentArgs()validator, default{}.src/util.ts—splitShellArgs()(POSIX-ish tokenizer) +resolveAgentArgs()(env-var > config).src/native-runner.ts— constructor acceptsagentArgs;buildCommand()appends extras (before stdin marker for codex).src/sandbox.ts—shellQuote()helper;runCommandForAgent()interpolates safely;SandboxandstartSandboxthreadagentArgsthrough.verboseparameter position preserved for backward compatibility.src/race.ts—createRunnerPoolpassesconfig.agentArgsto both runners.src/shell.ts—cook shellhonoursagentArgsso interactive sessions inherit the same flags.tests/agent-args.test.mjs— 15 unit tests (splitShellArgs,resolveAgentArgs,loadConfigparsing,NativeRunner.buildCommandargv composition).package.json— addedtsxto devDependencies +npm testscript using Node's built-in--testrunner.README.md— "Custom agent CLI flags" subsection with examples + docker caveat.plans/p9r-agent-args/— RPI artifacts (research, plan, devlog, code-review, this pr.md).Backward Compatibility
agentArgsdefault to{}— no change to spawn argv.startSandboxsignature evolution: newagentArgsparameter appended after the existingverbose(which kept its position). Existing positional callers (currently onlysrc/shell.ts) compile and run unchanged.Test Plan
Automated (15 tests)
npm testCovers:
splitShellArgs— simple tokens, single-quoted with spaces, double-quoted with backslash escapes, empty input.resolveAgentArgs— config fallback, env-var override, unset both.loadConfig— validagentArgs, missing (default), malformed (non-object), unknown agent key (dropped), non-string entries in list (filtered).NativeRunner.buildCommand— claude appends after base flags; codex preserves stdin marker-as last argv; noagentArgsleaves base argv unchanged.Manual
Out of Scope
agentArgs(extensible later).acceptEdits,dangerously-skip-permissions) — those keep current behaviour; users override via append semantics.tsx + node --testis the lightest path that doesn't preempt PR h5p: Add Vitest test harness (63 tests) #21's Vitest discussion.Notes
No LICENSE file in the repo today; submitting under the implicit terms used by prior merged PRs. Happy to clarify or sign anything if maintainer has a CLA preference.