Skip to content

Apply Coven's permission policy to the Claude CLI backend - #468

Merged
BunsDev merged 5 commits into
mainfrom
feat/coven-1738-claude-policy
Nov 16, 2026
Merged

BunsDev merged 5 commits into
mainfrom
feat/coven-1738-claude-policy

Conversation

@BunsDev

@BunsDev BunsDev commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Summary

  • The Claude CLI backend now applies the permission policy Coven hands the engine in COVEN_CLAUDE_POLICY, instead of starting the CLI under whatever the operator's and the workspace's Claude settings files allow.

Context

Changes

  • claude_cli_policy.rs reads COVEN_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_turn appends those arguments after build_args.
  • The policy does not name a permission mode. Since fix: keep read-only and keyless turns within their permission #471, build_args passes each turn's own mode, and that stays the only --permission-mode on 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.
  • A read-only turn gets a different settings file. The CLI applies allow rules in plan mode too, so with Coven's allow list (touch, cp, mv and a few more) a plan turn could still write files. A turn that reaches the CLI as plan now gets readOnlySettingsFile, which has the refusals and no allow list. cli_permission_mode maps the turn's mode in one place, for both the flag and the choice of file.
  • A policy the engine cannot apply in full fails the turn with a message to update Coven and the engine together: an unknown version, an unknown field, an empty value, a missing settings file (either one), or a value that would read as a flag. The CLI is not started without the policy.

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 of main (v0.9.1). One conflict, in spawn_turn; resolved by keeping build_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: clean
  • cargo fmt --all -- --check (Rust 1.100.0): exit 0
  • cargo check --workspace: N/A, covered by the clippy and test builds below
  • cargo clippy --workspace --all-targets --locked -- -D warnings (Rust 1.100.0): exit 0
  • cargo test --workspace --locked --no-fail-fast with a throwaway HOME: 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_quick in crates/tui, a frame-timing test in a crate this PR does not touch; it passed in this run.
  • Targeted/manual checks:
    • 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_arguments runs a plan turn and expects the read-only file; a_full_access_turn_gets_the_full_policy_file runs a bypassPermissions turn and expects the full one; an_unusable_policy_refuses_the_launch expects the launcher never to start.
    • cargo test -p claurst-api --lib claude_cli: 27 passed.
    • Real Claude Code 2.1.325 turns through coven run coven-code --stream-json with this build (0.9.1) and the matching Coven build, against a scratch Coven home:
      • --permission full: the CLI started with one --permission-mode bypassPermissions and the full policy file. A Write-tool write, a python3 write and touch ran. rm was refused.
      • No --permission: one --permission-mode default. A command allowed only by a rule in the operator's own ~/.claude/settings.json was refused and the policy's touch ran.
      • --add-dir: the granted directory was readable, and refused without the grant.
      • --permission read-only: one --permission-mode plan and the read-only policy file. Before this fix the same launch ran touch and the file was created. Under the read-only file the CLI answers the same touch with "needs approval"; under the full file it runs.
      • A Coven build that still sends permissionMode: the turn failed with "unknown field permissionMode" and the CLI was never started.
  • Not run: Windows and Linux.

PR Readiness

  • Diff is limited to the intended files.
  • Generated files were not edited by hand.
  • User-facing docs/help were updated or are not needed.
  • No secrets, credentials, local paths, or unrelated logs are included.
  • Remaining risks or follow-up work are listed above.

Known limit: a workspace's checked-in .claude/settings.json is still read, so an allow rule there can let a command run in a read-only turn. That is the same on main today.

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

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>
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Nov 15, 2026 10:30pm UTC

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment on lines +42 to +44
match std::env::var(CLAUDE_POLICY_ENV) {
Ok(value) => policy_args(Some(&value)),
Err(std::env::VarError::NotPresent) => policy_args(None),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
BunsDev and others added 3 commits November 14, 2026 03:06
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>

This branch was successfully deployed

1 active deployment
Preview — 9d4281ac Deployed Nov 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants