clash 0.5.5

Command Line Agent Safety Harness — permission policies for coding agents
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
# CLI Reference

Complete reference for the `clash` command-line interface.

---

## Global Options

All commands accept:

| Flag | Description |
|------|-------------|
| `-v`, `--verbose` | Enable verbose/debug output |
| `-V`, `--version` | Print version |
| `-h`, `--help` | Print help |

---

## clash init

Initialize a new clash policy with a safe default configuration.

```
clash init [SCOPE] [OPTIONS]
```

**Arguments:**

| Argument | Description |
|----------|-------------|
| `SCOPE` | Scope to initialize: `user` (global) or `project` (this repo). When omitted, an interactive prompt lets you choose. |

**What it does:**

- **`clash init user`** — Creates `~/.clash/policy.star` with a safe default policy, installs the Claude Code plugin, and installs the clash status line.
- **`clash init project`** — Creates `.clash/policy.star` in the current repository root with a minimal deny-all policy.

Only one scope is initialized per invocation. When no scope is given, clash explains both options and asks you to choose.

**Examples:**

```bash
# Interactive — prompts you to choose user or project scope
clash init

# Set up your global (user-level) policy
clash init user

# Create a repo-specific policy
clash init project
```

---

## clash status

Show policy status: layers, rules with shadowing, and potential issues.

```
clash status [OPTIONS]
```

**Options:**

| Flag | Description |
|------|-------------|
| `--json` | Output as JSON instead of human-readable text |
| `--verbose` | Show all rules including builtin rules from `@clash//builtin.star` |

Outputs a comprehensive breakdown covering:

- **Policy layers** — which levels are active (user, project, session) with file paths, and the automatic precedence chain (session > project > user)
- **Effective policy** — all rules in evaluation order grouped by domain (exec, filesystem, network, tool), with level tags showing where each rule originates and shadow indicators when a higher-precedence layer overrides a lower one. Builtin rules (from `@clash//builtin.star`, included via `base.update(...)`) are collapsed into a summary count by default; pass `--verbose` to expand them.
- **Potential issues** — detectable misconfigurations (overly broad wildcards, missing deny rules, shadowed rules, etc.)

**Example:**

```bash
clash status            # user/project/session rules; builtin rules collapsed
clash status --verbose  # all rules including builtin rules expanded
```

---

## clash doctor

Diagnose common setup issues and report fix instructions. Runs a series of checks and reports pass/warn/fail status for each.

```
clash doctor [--onboard]
```

**Flags:**

| Flag | Description |
|------|-------------|
| `--onboard` | Run interactive onboarding: diagnose issues and offer to fix them automatically |

**Checks performed:**

| Check | Description |
|-------|-------------|
| Policy files | Verifies user and project policy files exist |
| Policy parsing | Attempts to parse and compile each policy file, reporting syntax errors |
| Plugin installed | Checks if clash is registered as a Claude Code plugin with hooks configured |
| Binary on PATH | Verifies the `clash` binary is findable on `$PATH` |
| File permissions | Checks policy files are not world/group readable (Unix) |
| Sandbox support | Checks if the platform supports sandboxing (Seatbelt on macOS, Landlock on Linux) |

Each check outputs a status (**PASS**, **WARN**, or **FAIL**) with a message. Failures include concrete fix commands or instructions.

With `--onboard`, failing checks prompt the user to fix the issue interactively (install the plugin, configure bypassPermissions, create a policy, install the status line). This collapses the multi-step `clash init` flow into a single guided command.

**Examples:**

```bash
# Standard diagnostics
clash doctor

# Interactive onboarding — diagnose and fix
clash doctor --onboard
```

---

## clash policy

View, validate, and manage policy rules.

### clash policy allow

Add an allow rule for a tool or binary. Supports positional command syntax or explicit flags.

```
clash policy allow [OPTIONS] [COMMAND]...
```

**Arguments:**

| Argument | Description |
|----------|-------------|
| `[COMMAND]...` | Command to allow (e.g. `"gh pr create"` → bin=gh, args=[pr, create]) |

**Options:**

| Flag | Description |
|------|-------------|
| `--tool <TOOL>` | Tool name (e.g. "Bash", "Read", "Write") |
| `--bin <BIN>` | Binary name (implies --tool Bash) |
| `--sandbox <SANDBOX>` | Named sandbox to apply (must be defined in the policy) |
| `--scope <SCOPE>` | Policy scope: "user" or "project" (default: auto-detect) |

When no flags are provided, the positional command is parsed as a Bash tool rule: the first word becomes the binary name and remaining words become positional arguments.

**Examples:**

```bash
# Allow a command (positional syntax)
clash policy allow "gh pr create"

# Allow a specific binary
clash policy allow --bin grep

# Allow a binary with a sandbox
clash policy allow --bin cargo --sandbox cwd

# Allow a tool by name
clash policy allow --tool Read

# Allow in user scope
clash policy allow --scope user --bin git
```

### clash policy deny

Add a deny rule for a tool or binary. Same syntax as `allow`.

```
clash policy deny [OPTIONS] [COMMAND]...
```

**Arguments and options are the same as `clash policy allow`** (except `--sandbox` is not available for deny rules).

**Examples:**

```bash
# Deny a command
clash policy deny "rm -rf"

# Deny a tool
clash policy deny --tool WebSearch

# Deny a binary
clash policy deny --bin curl
```

### clash policy remove

Remove a rule matching a tool or binary.

```
clash policy remove [OPTIONS] [COMMAND]...
```

**Arguments and options are the same as `clash policy allow`** (except `--sandbox` is not available).

**Examples:**

```bash
# Remove a previously added command rule
clash policy remove "gh pr create"

# Remove a tool rule
clash policy remove --tool Read

# Remove a binary rule
clash policy remove --bin grep
```

### clash policy edit

Open the policy file in `$EDITOR`.

```
clash policy edit [OPTIONS]
```

**Options:**

| Flag | Description |
|------|-------------|
| `--scope <SCOPE>` | Policy scope to edit: "user" or "project" (default: auto-detect) |

### clash policy show

Show the compiled decision tree: default effect, policy name, and all rules grouped by capability domain.

```
clash policy show [OPTIONS]
```

**Options:**

| Flag | Description |
|------|-------------|
| `--json` | Output as JSON |

**Examples:**

```bash
clash policy show
clash policy show --json
```

### clash policy list

List all active rules with level tags showing which policy layer each rule comes from.

```
clash policy list [OPTIONS]
```

**Options:**

| Flag | Description |
|------|-------------|
| `--json` | Output as JSON |

**Examples:**

```bash
clash policy list
clash policy list --json
```

### clash policy validate

Validate policy files and report errors. Checks that each policy file parses and compiles successfully, reporting the policy name, default effect, and rule count on success, or detailed error messages with hints on failure.

```
clash policy validate [OPTIONS]
```

**Options:**

| Flag | Description |
|------|-------------|
| `--file <PATH>` | Path to a specific policy file to validate (default: all active levels) |
| `--json` | Output as JSON |

When no `--file` is given, validates all active policy levels (user, project) and reports results for each. Exits with code 0 if all files are valid, code 1 if any have errors.

**Examples:**

```bash
# Validate all active policy levels
clash policy validate

# Validate a specific file
clash policy validate --file ~/.clash/policy.star

# JSON output for scripting
clash policy validate --json
```

### clash policy schema

Print the JSON schema for the policy file format.

```
clash policy schema
```

**Examples:**

```bash
clash policy schema
```

### clash policy explain

Explain which policy rule would match a given tool invocation, reading hook input from stdin as JSON.

```
clash policy explain
```

**Examples:**

```bash
echo '{"tool_name":"Bash","tool_input":{"command":"git push"}}' | clash policy explain
```

---

## clash explain

Explain which policy rule would match a given tool invocation. Useful for debugging why an action is allowed, denied, or prompts for confirmation.

```
clash explain [OPTIONS] <TOOL> [ARGS]...
```

**Arguments:**

| Arg | Description |
|-----|-------------|
| `<TOOL>` | Tool type: `bash`, `read`, `write`, `edit`, `tool` (or full name like `Bash`, `Read`) |
| `[ARGS]...` | The command, file path, or noun to check (remaining args joined) |

**Options:**

| Flag | Description |
|------|-------------|
| `--json` | Output as JSON instead of human-readable text |

Accepts either CLI arguments or JSON from stdin. Trailing arguments are joined with spaces, so quoting is not required.

**Examples:**

```bash
# Check a bash command (no quoting needed)
clash explain bash git push origin main

# Check a file read
clash explain read .env

# JSON output for scripting
clash explain --json bash rm -rf /

# Quoting still works
clash explain bash "git push origin main"

# Check a tool capability
clash explain tool "ExitPlanMode"

# Pipe JSON input (via policy explain)
echo '{"tool_name":"Bash","tool_input":{"command":"git push"}}' | clash policy explain
```

---

## clash launch

Launch Claude Code with clash managing hooks and sandbox enforcement.

```
clash launch [OPTIONS] [ARGS]...
```

**Options:**

| Flag | Description |
|------|-------------|
| `--policy <POLICY>` | Path to policy file (default: `~/.clash/policy.star`) |

**Arguments:**

| Arg | Description |
|-----|-------------|
| `[ARGS]...` | Arguments passed through to Claude Code |

**Examples:**

```bash
# Launch with default policy
clash launch

# Launch with a custom policy
clash launch --policy ./project.policy

# Pass arguments to Claude Code
clash launch -- --model sonnet
```

---

## clash sandbox

Apply and test kernel-level sandbox restrictions. Clash uses Seatbelt on macOS and Landlock on Linux to enforce filesystem and network restrictions at the OS level.

### clash sandbox create

Create a new named sandbox definition in the policy.

```
clash sandbox create [OPTIONS] <NAME>
```

**Arguments:**

| Argument | Description |
|----------|-------------|
| `<NAME>` | Name for the new sandbox |

**Options:**

| Flag | Description |
|------|-------------|
| `--default <DEFAULT>` | Default capability: "deny" or "allow" (default: deny) |
| `--network <NETWORK>` | Network policy: "allow", "deny", or "localhost" (default: deny) |
| `--doc <DOC>` | Documentation string for the sandbox |
| `--scope <SCOPE>` | Policy scope: "user" or "project" |

**Examples:**

```bash
# Create a basic sandbox
clash sandbox create dev

# Create a sandbox with network access
clash sandbox create build --network allow --doc "Build tools sandbox"

# Create a sandbox with localhost-only networking
clash sandbox create test --network localhost
```

### clash sandbox delete

Delete a named sandbox from the policy.

```
clash sandbox delete [OPTIONS] <NAME>
```

**Arguments:**

| Argument | Description |
|----------|-------------|
| `<NAME>` | Name of the sandbox to delete |

**Options:**

| Flag | Description |
|------|-------------|
| `--scope <SCOPE>` | Policy scope: "user" or "project" |

### clash sandbox list

List all named sandboxes in the policy.

```
clash sandbox list [OPTIONS]
```

**Options:**

| Flag | Description |
|------|-------------|
| `--json` | Output as JSON |
| `--scope <SCOPE>` | Policy scope: "user" or "project" |

### clash sandbox add-rule

Add a filesystem rule to a named sandbox.

```
clash sandbox add-rule [OPTIONS] <SANDBOX> <PATH>
```

**Arguments:**

| Argument | Description |
|----------|-------------|
| `<SANDBOX>` | Name of the sandbox to modify |
| `<PATH>` | Filesystem path for the rule |

**Options:**

| Flag | Description |
|------|-------------|
| `--effect <EFFECT>` | Rule effect: "allow" or "deny" (default: allow) |
| `--caps <CAPS>` | Capabilities: "read", "write", or "read,write" (default: read) |
| `--match <MATCH>` | Path match mode: "prefix" or "literal" (default: prefix) |
| `--doc <DOC>` | Documentation string for the rule |
| `--scope <SCOPE>` | Policy scope: "user" or "project" |

**Examples:**

```bash
# Allow read access to a directory
clash sandbox add-rule dev ./src

# Allow read+write access
clash sandbox add-rule dev ./target --caps read,write

# Add a deny rule
clash sandbox add-rule dev /etc --effect deny
```

### clash sandbox remove-rule

Remove a filesystem rule from a named sandbox by path.

```
clash sandbox remove-rule [OPTIONS] <SANDBOX> <PATH>
```

**Arguments:**

| Argument | Description |
|----------|-------------|
| `<SANDBOX>` | Name of the sandbox |
| `<PATH>` | Path of the rule to remove |

**Options:**

| Flag | Description |
|------|-------------|
| `--scope <SCOPE>` | Policy scope: "user" or "project" |

### clash sandbox check

Check if sandboxing is supported on the current platform.

```
clash sandbox check
```

### clash sandbox exec

Apply sandbox restrictions and execute a command.

```
clash sandbox exec [OPTIONS] --sandbox <SANDBOX> --cwd <CWD> [COMMAND]...
```

**Options:**

| Flag | Description |
|------|-------------|
| `--sandbox <SANDBOX>` | Sandbox config: inline JSON or a named sandbox from the policy |
| `--cwd <CWD>` | Working directory for path resolution |

**Arguments:**

| Arg | Description |
|-----|-------------|
| `[COMMAND]...` | Command and arguments to execute under sandbox |

**Examples:**

```bash
# Run ls under a read-only sandbox
clash sandbox exec \
  --sandbox '{"read":["/Users/me/project"],"write":[]}' \
  --cwd /Users/me/project \
  ls -la

# Run cargo with write access to target/
clash sandbox exec \
  --sandbox '{"read":["."],"write":["./target"]}' \
  --cwd /Users/me/project \
  cargo build
```

### clash sandbox test

Test sandbox enforcement interactively. Same interface as `exec` but designed for verifying that restrictions work as expected.

```
clash sandbox test [OPTIONS] --sandbox <SANDBOX> --cwd <CWD> [COMMAND]...
```

**Options and arguments are the same as `sandbox exec`.**

---

## clash hook

Internal commands called by Claude Code's hook system. These are not typically invoked directly — they are registered in `hooks.json` and called automatically by Claude Code.

### clash hook pre-tool-use

Called before a tool is executed. Evaluates the policy and returns an allow/deny/ask decision. Reads hook input from stdin as JSON.

```
clash hook pre-tool-use
```

### clash hook post-tool-use

Called after a tool is executed. Used for audit logging and notifications. Reads hook input from stdin as JSON.

```
clash hook post-tool-use
```

### clash hook permission-request

Called when Claude Code prompts for permission. Responds to permission prompts on behalf of the user based on policy rules. Reads hook input from stdin as JSON.

```
clash hook permission-request
```

### clash hook session-start

Called when a Claude Code session begins. Initializes session state, symlinks the clash binary into `~/.local/bin/`, and injects system prompt context. Reads hook input from stdin as JSON.

```
clash hook session-start
```

---

## clash update

Update clash to the latest release from GitHub, or check if an update is available.

```
clash update [OPTIONS]
```

**Options:**

| Flag | Description |
|------|-------------|
| `--check` | Only check for updates, don't install |
| `-y`, `--yes` | Skip confirmation prompt |
| `--version <VERSION>` | Update to a specific version (e.g., `0.4.0`) |

The command compares the running version against the latest GitHub release, downloads the matching binary for your platform, verifies the SHA-256 checksum, and atomically replaces the current binary.

If clash was installed via `cargo install`, the command prints the appropriate cargo command instead of replacing the binary directly.

**Examples:**

```bash
# Update to latest release
clash update

# Check for updates without installing
clash update --check

# Update non-interactively (e.g., in a script)
clash update --yes

# Install a specific version
clash update --version 0.2.0
```

---

## clash bug

File a bug report to both Linear (private, with full diagnostics) and GitHub (public, title and description only).

```
clash bug [OPTIONS] <TITLE>
```

**Arguments:**

| Arg | Description |
|-----|-------------|
| `<TITLE>` | Short summary of the bug |

**Options:**

| Flag | Description |
|------|-------------|
| `-d`, `--description <DESCRIPTION>` | Detailed description of the bug |
| `--include-config` | Include the clash policy config in the Linear report |
| `--include-logs` | Include recent debug logs in the Linear report |
| `--include-trace` | Include the session trace in the Linear report |

Private data (config, logs, trace) is only sent to the Linear issue. The GitHub issue contains only the title and description.

**Examples:**

```bash
# Simple bug report
clash bug "Sandbox blocks cargo build in target directory"

# Detailed report with diagnostics
clash bug "Policy not matching git commands" \
  -d "The rule on git does not match git status" \
  --include-config \
  --include-logs \
  --include-trace
```

---

## Disabling Clash

Set the `CLASH_DISABLE` environment variable to temporarily bypass all clash enforcement for a session.

| Value | Effect |
|-------|--------|
| Unset or empty | Clash **enabled** (normal operation) |
| `0` or `false` | Clash **enabled** |
| Any other value (`1`, `true`, `yes`, ...) | Clash **disabled** (all hooks pass-through) |

When disabled, clash hooks still run but immediately return pass-through responses — no policy evaluation, no sandbox enforcement. `clash status` and `clash doctor` will report the disabled state.

**Examples:**

```bash
# Disable for a single session
CLASH_DISABLE=1 claude

# Re-enable
unset CLASH_DISABLE
```

---

## Uninstalling

To fully remove clash from your system:

```bash
# 1. Remove the Claude Code plugin (stops hooks from firing)
claude plugin uninstall clash

# 2. Remove the binary
cargo uninstall clash

# 3. (Optional) Remove from the plugin marketplace
claude plugin marketplace remove clash

# 4. (Optional) Remove the status line — only needed if you skipped step 2
clash statusline uninstall

# 5. (Optional) Clean up configuration and logs
rm -rf ~/.clash       # user-level policy and logs
rm -rf .clash         # project-level policy (per repo)
```

After step 1, Claude Code reverts to its built-in permission model immediately. Policy files are left in place so you can resume where you left off if you reinstall later.

---

## Exit Codes

| Code | Meaning |
|------|---------|
| `0` | Success |
| `1` | General error (parse failure, I/O error, etc.) |
| `2` | CLI usage error (invalid arguments) |

---

## See Also

- [Policy Writing Guide]./policy-guide.md — how to write policy rules
- [Policy Semantics]./policy-semantics.md — evaluation algorithm