Repository navigation
Apply Coven's permission policy to the Claude CLI backend - #468
Conversation
The Claude CLI backend was started with no permission or settings flags, so it ran in its headless default mode under whatever the user's and the workspace's Claude settings files allowed. The engine's own permission never reached it, and the same chat was refused different tool calls on different machines (OpenCoven/coven#1738). When Coven starts the engine for a headless run it now sets COVEN_CLAUDE_POLICY, a JSON object naming Coven's settings file, the settings sources the CLI may still read, the permission mode, extra directories and the user's MCP config. The engine appends those to every CLI launch. A policy it cannot apply in full (unknown version, missing settings file, a value that reads as a flag) fails the turn instead of starting the CLI without it. Without the variable the launch is unchanged. Co-Authored-By: Cody <cody@opencoven.ai> Coven-Familiar: cody Coven-Harness: Claude Code / claude-fable-5-2 Signed-off-by: Val Alexander 👑 <val@opencoven.ai>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
🟡 Changes recommended
A critical active finding remains because an empty or whitespace-only COVEN_CLAUDE_POLICY is treated as absent, allowing Claude to launch without a required policy.
1 open issue
What changed in this PR
This pull request makes headless Claude CLI turns honor Coven’s permission policy supplied through COVEN_CLAUDE_POLICY, while preserving legacy behavior when the variable is absent.
Changes:
- Added versioned policy parsing, validation, and conversion into Claude CLI arguments.
- Applied validated policy arguments to Claude CLI launches and refused unusable policies before launch.
- Added fake-launcher integration coverage and documented the policy behavior.
| File | Description |
|---|---|
| src-rust/crates/api/tests/claude_cli_pipes.rs | Adds fake-launcher integration tests for policy propagation and refusal of unusable policies. |
| src-rust/crates/api/src/providers/mod.rs | Registers the new Claude CLI policy module. |
| src-rust/crates/api/src/providers/claude_cli.rs | Appends validated permission-policy arguments when spawning Claude CLI turns. |
| src-rust/crates/api/src/providers/claude_cli_policy.rs | Parses and validates Coven’s Claude permission policy and converts it into CLI arguments. |
| docs/providers.md | Documents Claude CLI permission-policy behavior and failure handling. |
Review effort: Lite
| match std::env::var(CLAUDE_POLICY_ENV) { | ||
| Ok(value) => policy_args(Some(&value)), | ||
| Err(std::env::VarError::NotPresent) => policy_args(None), |
There was a problem hiding this comment.
@copilot Fix the code for all comments in this review comment.
When a review comment includes a suggested change, apply the suggestion exactly.
Do not make changes beyond what is described in the linked review comment.
There was a problem hiding this comment.
Fixed in eca2ee9. Only an absent policy preserves the bare launch; empty and whitespace-only values now reject the turn.
Co-authored-by: BunsDev <68980965+BunsDev@users.noreply.github.com>
Brings in v0.9.1, including #471, which makes the keyless transport pass each turn's permission mode to the CLI as `--permission-mode`. One conflict, in `spawn_turn` in `providers/claude_cli.rs`: both sides changed the argument list. Resolved by keeping both, main's `build_args(model, resume, permission)` followed by the policy arguments. This commit is the mechanical resolution only. The policy can still name a permission mode of its own here, which would put two on the command line, and the pipes fixture fails on that. The next commit removes the mode from the policy. Co-Authored-By: Cody <cody@opencoven.ai> Coven-Familiar: cody Coven-Harness: Claude Code / claude-fable-5-2 Signed-off-by: Val Alexander 👑 <val@opencoven.ai>
Since #471 the keyless transport passes each turn's permission mode to the CLI. Coven's policy object also named one, so a policy launch would have carried `--permission-mode` twice, and which one applied depended on the CLI's argument parsing. The policy no longer names a mode. `build_args` is the only place the flag comes from, and it carries the turn's own mode. The policy object now refuses unknown fields, so a Coven that still sends `permissionMode`, or any later field this engine does not know, fails the turn instead of having part of its policy dropped. Nothing released sends the old shape. The pipes fixture checks, with and without a policy, that the CLI receives exactly one `--permission-mode`. Refs OpenCoven/coven#1738 Co-Authored-By: Cody <cody@opencoven.ai> Coven-Familiar: cody Coven-Harness: Claude Code / claude-fable-5-2 Signed-off-by: Val Alexander 👑 <val@opencoven.ai>
The CLI applies allow rules in plan mode as well. Coven's policy allows `touch`, `cp`, `mv` and a few more without asking, so a read-only turn that was handed the policy could still create and move files: in a real run through Coven, `touch` wrote a file in a `plan` turn. That undoes what #471 set out to do for read-only turns. The policy object now names two settings files. A turn that reaches the CLI as `plan` gets `readOnlySettingsFile`, which carries the refusals and no allow list. Every other turn gets `settingsFile`. The field is required, and both files are checked on every turn, so a policy without the read-only file is refused instead of leaving read-only turns with the allow list. `cli_permission_mode` now maps the turn's mode in one place, for both `--permission-mode` and the choice of file. Refs OpenCoven/coven#1738 Co-Authored-By: Cody <cody@opencoven.ai> Coven-Familiar: cody Coven-Harness: Claude Code / claude-fable-5-2 Signed-off-by: Val Alexander 👑 <val@opencoven.ai>

Summary
COVEN_CLAUDE_POLICY, instead of starting the CLI under whatever the operator's and the workspace's Claude settings files allow.Context
crates/api/src/providers/claude_cli_policy.rs(new), the spawn inclaude_cli.rs, the fake-launcher integration test and one paragraph indocs/providers.md.Changes
claude_cli_policy.rsreadsCOVEN_CLAUDE_POLICY(a JSON object:version,settingsFile,readOnlySettingsFile,settingSources,addDirs,mcpConfigFile) and turns it into CLI arguments. The flags that take several values come first and the block ends with two single-value flags.ClaudeCliProvider::spawn_turnappends those arguments afterbuild_args.build_argspasses each turn's own mode, and that stays the only--permission-modeon the command line. The first version of this PR carried a mode in the policy, which would have put the flag there twice after fix: keep read-only and keyless turns within their permission #471.touch,cp,mvand a few more) aplanturn could still write files. A turn that reaches the CLI asplannow getsreadOnlySettingsFile, which has the refusals and no allow list.cli_permission_modemaps the turn's mode in one place, for both the flag and the choice of file.Commits since the first review:
eca2ee96(Copilot, requested in review): an empty or whitespace-only variable is refused. Only an absent variable keeps the bare launch. Reviewed and kept as is.41f70f20: merge ofmain(v0.9.1). One conflict, inspawn_turn; resolved by keepingbuild_args(model, resume, permission)followed by the policy arguments.c59353cd: the policy no longer names a permission mode, and unknown fields are refused.9d4281ac: the read-only settings file.Validation
git diff --check: cleancargo fmt --all -- --check(Rust 1.100.0): exit 0cargo check --workspace: N/A, covered by the clippy and test builds belowcargo clippy --workspace --all-targets --locked -- -D warnings(Rust 1.100.0): exit 0cargo test --workspace --locked --no-fail-fastwith a throwawayHOME: exit 0, 3273 passed, 0 failed, 65 ignored (Rust 1.100.0). An earlier run of the same command on a heavily loaded machine failed one test,a_screen_full_of_long_changed_lines_stays_quickincrates/tui, a frame-timing test in a crate this PR does not touch; it passed in this run.cargo test -p claurst-api --test claude_cli_pipes: 10 passed, 1 ignored (the worker). The fake launcher asserts, in every case, that it receives exactly one--permission-mode.covens_policy_reaches_the_cli_argumentsruns aplanturn and expects the read-only file;a_full_access_turn_gets_the_full_policy_fileruns abypassPermissionsturn and expects the full one;an_unusable_policy_refuses_the_launchexpects the launcher never to start.cargo test -p claurst-api --lib claude_cli: 27 passed.coven run coven-code --stream-jsonwith this build (0.9.1) and the matching Coven build, against a scratch Coven home:--permission full: the CLI started with one--permission-mode bypassPermissionsand the full policy file. A Write-tool write, apython3write andtouchran.rmwas refused.--permission: one--permission-mode default. A command allowed only by a rule in the operator's own~/.claude/settings.jsonwas refused and the policy'stouchran.--add-dir: the granted directory was readable, and refused without the grant.--permission read-only: one--permission-mode planand the read-only policy file. Before this fix the same launch rantouchand the file was created. Under the read-only file the CLI answers the sametouchwith "needs approval"; under the full file it runs.permissionMode: the turn failed with "unknown fieldpermissionMode" and the CLI was never started.PR Readiness
Known limit: a workspace's checked-in
.claude/settings.jsonis still read, so an allow rule there can let a command run in a read-only turn. That is the same onmaintoday.Note: this repository asks for no emojis in PR text. The closing line below is the Coven familiar attribution Val asked for on this PR.
✨ Co-authored by Cody, a Coven familiar for Val