forge-guard 0.3.5

Pre-deployment smart contract auditing framework for Foundry
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
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
# ๐Ÿ“– Forge Guard โ€” Command Reference

> Complete documentation for all 22 `forge-guard` subcommands.

**Navigation:** [Back to README](README.md) ยท [Changelog](CHANGELOG.md) ยท [Roadmap](milestone-based-roadmap.md)

---

## Table of Contents

| # | Command | Description |
|---|---------|-------------|
| 1 | [`forge-guard audit`](#1-forge-guard-audit) | Run a comprehensive security audit |
| 2 | [`forge-guard deploy`](#2-forge-guard-deploy) | Deploy contracts with automatic security checks |
| 3 | [`forge-guard deploy-safe`](#3-forge-guard-deploy-safe) | Deploy with mandatory security pass requirement |
| 4 | [`forge-guard fuzz`](#4-forge-guard-fuzz) | Run fuzzing campaigns |
| 5 | [`forge-guard invariant`](#5-forge-guard-invariant) | Run invariant tests |
| 6 | [`forge-guard simulate`](#6-forge-guard-simulate) | Run deployment simulations |
| 7 | [`forge-guard gas`](#7-forge-guard-gas) | Analyze gas usage |
| 8 | [`forge-guard report`](#8-forge-guard-report) | Generate audit reports from existing results |
| 9 | [`forge-guard verify`](#9-forge-guard-verify) | Verify contract deployments |
| 10 | [`forge-guard doctor`](#10-forge-guard-doctor) | Analyze project health and configuration |
| 11 | [`forge-guard watch`](#11-forge-guard-watch) | Watch files for changes and re-audit |
| 12 | [`forge-guard ci`](#12-forge-guard-ci) | Generate CI/CD pipeline configurations |
| 13 | [`forge-guard benchmark`](#13-forge-guard-benchmark) | Run performance benchmarks |
| 14 | [`forge-guard scan`](#14-forge-guard-scan) | Scan dependencies for vulnerabilities |
| 15 | [`forge-guard upgrade-check`](#15-forge-guard-upgrade-check) | Analyze upgrade paths and proxy safety |
| 16 | [`forge-guard plugins`](#16-forge-guard-plugins) | Manage audit plugins |
| 17 | [`forge-guard chain`](#17-forge-guard-chain) | Configure chain settings |
| 18 | [`forge-guard sbom`](#18-forge-guard-sbom) | Generate a Software Bill of Materials (SBOM) |
| 19 | [`forge-guard install-hook`](#19-forge-guard-install-hook) | Install/uninstall git pre-commit hook |
| 20 | [`forge-guard security`](#20-forge-guard-security) | Configure security settings |
| 21 | [`forge-guard import`](#21-forge-guard-import) | Import findings from external analyzers (Slither, Mythril, Semgrep) |
| 22 | [`forge-guard notify`](#22-forge-guard-notify) | Send webhook notifications (Slack, Discord) |

---

## Shared Flags

These flags are available on most commands (noted per-command with โœ…).

| Flag | Type | Default | Description |
|------|------|---------|-------------|
| `--chain <NAME>` | `String` | `ethereum` | Target chain to audit for |
| `--project <PATH>` | `PathBuf` | `.` | Path to Foundry project root |
| `--json` | `bool` | `false` | Output as JSON |
| `--markdown` | `bool` | `false` | Output as Markdown |
| `--html` | `bool` | `false` | Output as HTML |
| `--strict` | `bool` | `false` | Fail on any MEDIUM+ finding |
| `--offline` | `bool` | `false` | Skip RPC calls |
| `--production` | `bool` | `false` | Production mode (extra checks) |
| `--report` | `bool` | `false` | Generate report files |
| `--parallelism <N>` | `usize` | `4` | Number of parallel workers |

---

## 1. `forge-guard audit`

Run a comprehensive security audit on Solidity smart contracts. The flagship command โ€” runs 50+ vulnerability checks, generates findings, scores, and reports.

**Shared flags:** โœ…

### Flags

| Flag | Type | Default | Description |
|------|------|---------|-------------|
| `--full` | `bool` | `false` | Run all available checks (equivalent to `--exploit --gas`) |
| `--quick` | `bool` | `false` | Skip parser-heavy and expensive checks for ~5x faster results |
| `--summary` | `bool` | `false` | Show executive summary with PASS/FAIL verdict and action items |
| `--ai` | `bool` | `false` | Enable AI-powered auditing using configured LLM provider |
| `--ai-provider <PROVIDER>` | `String` | `openai` | AI provider: `openai`, `claude`, or `ollama` |
| `--ai-model <MODEL>` | `String` | `gpt-5` | AI model identifier (e.g., `gpt-5`, `claude-5-sonnet-20260701`) |
| `--ai-api-key <KEY>` | `Option<String>` | โ€” | AI API key (reads `OPENAI_API_KEY` or `ANTHROPIC_API_KEY` env var when empty) |
| `--ollama-endpoint <URL>` | `Option<String>` | โ€” | Ollama endpoint URL (default: `http://localhost:11434`) |
| `--ai-full` | `bool` | `false` | Run a full AI audit (security + gas + logic auditors) |
| `--exploit` | `bool` | `false` | Include exploit path analysis |
| `--gas` | `bool` | `false` | Include gas analysis |
| `--all-chains` | `bool` | `false` | Audit across all supported chains (in parallel via Rayon) |
| `--max-parallel-chains <N>` | `usize` | `4` | Maximum number of chains to audit concurrently when `--all-chains` is set |
| `--sources <DIRS>` | `String` | `src` | Source directories to audit (comma-separated) |
| `--exclude <PATTERNS>` | `Option<String>` | โ€” | Exclude patterns (comma-separated) |
| `--template <NAME>` | `Option<String>` | โ€” | Audit template to use (`erc20`, `erc721`, `defi`, `bridge`, `upgradeable`) |
| `--list-templates` | `bool` | `false` | List available audit templates |
| `--suppressions <FILE>` | `Option<PathBuf>` | โ€” | Suppression file (default `.forge-guard-suppressions`) |
| `--show-suppressed` | `bool` | `false` | Show suppressed findings (visually marked) instead of hiding them |
| `--generate-suppressions` | `bool` | `false` | Write a suppression file from current findings and exit |
| `--notify` | `bool` | `false` | Send webhook notifications after the audit |
| `--enable-history` | `bool` | `false` | Record the audit in the SQLite history database for trend tracking |

### Templates

Built-in audit templates adjust enabled checks, focus areas, and scoring thresholds:

| Template | Focus Areas | Description |
|----------|-------------|-------------|
| `erc20` | Token logic, approvals, supply | Standard ERC20 token audit with emphasis on transfer logic, allowance mechanisms, and supply consistency |
| `erc721` | NFT logic, metadata, royalties | NFT contract audit covering ownership tracking, metadata integrity, and royalty enforcement |
| `defi` | Lending, swaps, oracles, MEV | DeFi protocol audit focused on lending pools, AMM logic, price oracle manipulation, and MEV exposure |
| `bridge` | Cross-chain, message passing, validators | Bridge contract audit for cross-chain message verification, validator set management, and fund safety |
| `upgradeable` | Proxies, storage gaps, initializers | Upgradeable contract audit covering proxy patterns, storage collision prevention, and initializer safety |

Templates are **fully applied** to the audit:

- `enabled_checks` / `disabled_checks` โ€” force-enable or disable specific check IDs in the security engine
- `focus_areas` โ€” weighted 2ร— in the overall security score calculation
- `min_scores` โ€” per-category minimum scores that gate production readiness

Templates are JSON files in `~/.forge-guard/templates/` and are user-customizable. A user template with the same name as a built-in overrides it. To create one:

```bash
mkdir -p ~/.forge-guard/templates
cat > ~/.forge-guard/templates/my-defi.json <<'EOF'
{
  "name": "my-defi",
  "description": "My DeFi focus template",
  "enabled_checks": ["FA-H-011", "FA-H-016"],
  "disabled_checks": [],
  "min_scores": { "exploit_resistance": 80 },
  "focus_areas": ["exploit_resistance", "security"]
}
EOF
forge-guard audit --template my-defi
```

### Examples

```bash
# Standard audit
forge-guard audit

# Quick audit (~5x faster)
forge-guard audit --quick

# Full audit with exploit paths and gas analysis
forge-guard audit --full

# Executive summary
forge-guard audit --summary

# Quick summary (fastest feedback)
forge-guard audit --quick --summary

# Cross-chain audit
forge-guard audit --chain arbitrum
forge-guard audit --all-chains

# AI-powered audit
forge-guard audit --ai
forge-guard audit --ai --ai-provider claude --ai-model claude-5-sonnet-20260701

# Output formats
forge-guard audit --json
forge-guard audit --markdown
forge-guard audit --json --report   # Save to file

# Strict mode (fail on any finding)
forge-guard audit --strict

# Use a template
forge-guard audit --template defi
forge-guard audit --list-templates

# Custom source directories
forge-guard audit --sources "src,contracts" --exclude "test,mock"
```

---

## 2. `forge-guard deploy`

Deploy contracts with automatic security checks. Runs an audit before deployment and blocks if vulnerabilities are found. Use `--force` to bypass the guard.

**Shared flags:** โœ…

### Flags

| Argument/Flag | Type | Default | Description |
|---------------|------|---------|-------------|
| `contract` | `Option<String>` | โ€” | Contract name to deploy |
| `--force` | `bool` | `false` | Bypass deployment guard (warnings still shown) |
| `--args <ARGS>` | `Option<String>` | โ€” | Constructor arguments (comma-separated) |
| `--salt <SALT>` | `Option<String>` | โ€” | Create2 salt for deterministic address |
| `--verify` | `bool` | `false` | Verify contract after deployment |
| `--notify` | `bool` | `false` | Send webhook notification after the deployment attempt |

### Examples

```bash
# Deploy with security guard
forge-guard deploy

# Deploy specific contract
forge-guard deploy MyContract

# Force deploy (bypasses security guard)
forge-guard deploy MyContract --force

# Deploy with constructor arguments
forge-guard deploy MyContract --args "0x1234,100"

# Create2 deployment
forge-guard deploy MyContract --salt 0xabc

# Deploy with auto-verification
forge-guard deploy MyContract --verify
```

---

## 3. `forge-guard deploy-safe`

Deploy with a mandatory security pass requirement โ€” **cannot be bypassed** with `--force`. Contracts must pass all security checks to deploy.

**Shared flags:** โœ…

### Flags

| Argument/Flag | Type | Default | Description |
|---------------|------|---------|-------------|
| `contract` | `Option<String>` | โ€” | Contract name to deploy |
| `--args <ARGS>` | `Option<String>` | โ€” | Constructor arguments (comma-separated) |
| `--verify` | `bool` | `false` | Verify contract after deployment |
| `--notify` | `bool` | `false` | Send webhook notification after the deployment attempt |

### Examples

```bash
# Safe deploy (blocked if vulnerabilities found)
forge-guard deploy-safe MyContract

# With constructor args
forge-guard deploy-safe MyContract --args "0x1234"
```

---

## 4. `forge-guard fuzz`

Run fuzzing campaigns against your smart contracts. Configurable run count, seeding, and test function filtering.

**Shared flags:** โœ…

### Flags

| Argument/Flag | Type | Default | Description |
|---------------|------|---------|-------------|
| `contract` | `Option<String>` | โ€” | Fuzz contract |
| `--runs <N>` | `u32` | `10000` | Number of fuzz runs |
| `--seed <N>` | `Option<u64>` | โ€” | Fuzz seed for reproducible results |
| `--test <NAME>` | `Option<String>` | โ€” | Test function filter |

### Examples

```bash
# Basic fuzzing
forge-guard fuzz

# Fuzz specific contract with 50k runs
forge-guard fuzz Vault --runs 50000

# Reproducible fuzzing with seed
forge-guard fuzz --seed 42

# Fuzz a specific test function
forge-guard fuzz Vault --test testFuzzDeposit
```

---

## 5. `forge-guard invariant`

Run invariant tests on your smart contracts. Supports configurable run depth and failure modes.

**Shared flags:** โœ…

### Flags

| Argument/Flag | Type | Default | Description |
|---------------|------|---------|-------------|
| `contract` | `Option<String>` | โ€” | Invariant contract |
| `--runs <N>` | `u32` | `1000` | Number of runs |
| `--depth <N>` | `u32` | `100` | Depth of calls per run |
| `--fail-on-revert` | `bool` | `false` | Fail test on any revert |

### Examples

```bash
# Basic invariant test
forge-guard invariant

# Custom runs and depth
forge-guard invariant --runs 2000 --depth 150

# Fail on revert
forge-guard invariant --fail-on-revert
```

---

## 6. `forge-guard simulate`

Run deployment simulations to analyze contract behavior before deploying. Includes MEV analysis capability.

**Shared flags:** โœ…

### Flags

| Argument/Flag | Type | Default | Description |
|---------------|------|---------|-------------|
| `contract` | `Option<String>` | โ€” | Contract to simulate deployment for |
| `--blocks <N>` | `u32` | `100` | Number of simulation blocks |
| `--deployer <ADDRESS>` | `Option<String>` | โ€” | Simulate with specific deployer address |
| `--mev` | `bool` | `false` | Include MEV (sandwich, flash loan) analysis |

### Examples

```bash
# Basic simulation
forge-guard simulate

# With MEV analysis
forge-guard simulate --mev

# Custom block range and deployer
forge-guard simulate --blocks 200 --deployer 0x...
```

---

## 7. `forge-guard gas`

Analyze gas usage and get optimization suggestions. Can compare against previous reports.

**Shared flags:** โœ…

### Flags

| Argument/Flag | Type | Default | Description |
|---------------|------|---------|-------------|
| `contract` | `Option<String>` | โ€” | Check specific contract |
| `--diff <FILE>` | `Option<String>` | โ€” | Compare with previous report |
| `--all` | `bool` | `false` | Report gas for all functions |
| `--warn-threshold <N>` | `u64` | `50000` | Minimum gas threshold for warnings |

### Examples

```bash
# Analyze gas for all contracts
forge-guard gas

# Analyze specific contract
forge-guard gas Vault

# Report all functions
forge-guard gas --all

# Compare with baseline
forge-guard gas --diff previous.json

# Custom warning threshold
forge-guard gas --warn-threshold 100000
```

---

## 8. `forge-guard report`

Generate audit reports from existing audit result JSON files. Supports multiple output formats.

**Shared flags:** โœ…

### Flags

| Argument/Flag | Type | Default | Description |
|---------------|------|---------|-------------|
| `input` | `Option<PathBuf>` | โ€” | Path to audit result JSON |
| `--format <FORMAT>` | `String` | `markdown` | Output report format (`json`, `markdown`, `html`) |
| `--output <PATH>` | `Option<PathBuf>` | โ€” | Output file path |
| `--exploit-paths` | `bool` | `false` | Include exploit paths in report |
| `--summary` | `bool` | `false` | Summary only |
| `--history` | `bool` | `false` | Show score trends over time from the history database (SQLite) |
| `--regression` | `bool` | `false` | Highlight findings new since the last audit (regression diff) |

### Examples

```bash
# Generate markdown report from results
forge-guard report result.json

# JSON output
forge-guard report --format json

# HTML report
forge-guard report --format html

# Save to file
forge-guard report result.json --output audit_report.md

# Summary only
forge-guard report --summary

# Score trends over time (run forge-guard audit --enable-history first)
forge-guard report --history

# Findings new since the last audit
forge-guard report --regression
```

---

## 9. `forge-guard verify`

Verify contract deployments on block explorers. Supports on-chain bytecode matching and multiple explorer endpoints.

**Shared flags:** โœ…

### Flags

| Argument/Flag | Type | Default | Description |
|---------------|------|---------|-------------|
| `address` | `Option<String>` | โ€” | Contract address to verify |
| `name` | `Option<String>` | โ€” | Contract name |
| `--api-key <KEY>` | `Option<String>` | โ€” | Explorer API key |
| `--constructor-args <ARGS>` | `Option<String>` | โ€” | Constructor arguments ABI-encoded |
| `--all` | `bool` | `false` | Check all deployments |

### Examples

```bash
# Verify a specific contract
forge-guard verify --address 0x... --name MyContract

# Bulk verify all deployments
forge-guard verify --all

# Verify on a different chain
forge-guard verify --address 0x... --name MyContract --chain base

# With constructor arguments
forge-guard verify --address 0x... --name Token --constructor-args 0x0001
```

---

## 10. `forge-guard doctor`

Analyze project health and configuration. Checks Foundry installation, Solidity version, project structure, dependencies, compiler settings, RPC connectivity, and security configuration.

**Shared flags:** โœ…

### Flags

| Flag | Type | Default | Description |
|------|------|---------|-------------|
| `--fix` | `bool` | `false` | Fix issues automatically where possible |
| `--verbose` | `bool` | `false` | Verbose output |
| `--check <CATEGORY>` | `Option<String>` | โ€” | Check only specific category |
| `--sync` | `bool` | `false` | Sync forge-guard.toml settings from foundry.toml |
| `--dry-run` | `bool` | `false` | Preview config sync changes without writing (use with `--sync`) |
| `--diff` | `bool` | `false` | Show diff of what `--sync` would change (use with `--sync`) |

### Checks Performed

| Check | Description |
|-------|-------------|
| ๐Ÿ” Foundry installation | Verifies Foundry is installed and checks version |
| ๐Ÿ” Solidity version | Checks configured Solidity compiler version |
| ๐Ÿ” Project structure | Validates source directories, config files |
| ๐Ÿ” Dependency vulnerabilities | Scans for known vulnerable dependencies |
| ๐Ÿ” Compiler settings | Checks optimizer, EVM version, and other settings |
| ๐Ÿ” RPC connectivity | Tests RPC endpoint reachability (skipped in `--offline` mode) |
| ๐Ÿ” Security configuration | Validates security check settings |

### Examples

```bash
# Full health check
forge-guard doctor

# Verbose output
forge-guard doctor --verbose

# Auto-fix issues
forge-guard doctor --fix

# Check specific category
forge-guard doctor --check dependencies

# JSON output
forge-guard doctor --json

# Sync config from foundry.toml
forge-guard doctor --sync

# Preview sync changes without writing
forge-guard doctor --sync --dry-run

# Show diff of sync changes
forge-guard doctor --sync --diff
```

### Config Sync (`--sync`)

Reads `foundry.toml` and writes matching settings into `forge-guard.toml`:

- `src` โ†’ `src_dirs`
- `test` โ†’ `test_dirs`
- `libs` โ†’ `lib_dirs`
- `solc` โ†’ `solc_version`
- `remappings` โ†’ `remappings`

`--dry-run` previews changes without writing; `--diff` shows the current vs. new config side-by-side.

---

## 11. `forge-guard watch`

Watch files for changes and automatically re-audit. Configurable directory paths, debounce interval, and exclusion patterns.

**Shared flags:** โœ…

### Flags

| Flag | Type | Default | Description |
|------|------|---------|-------------|
| `--dirs <DIRS>` | `String` | `src` | Watch specific directories (comma-separated) |
| `--debounce-ms <N>` | `u64` | `500` | Debounce interval in milliseconds |
| `--exclude <PATTERNS>` | `Option<String>` | โ€” | Exclude patterns (comma-separated) |
| `--full` | `bool` | `false` | Run full audit on change (includes exploit + gas) |

### Examples

```bash
# Watch default src directory
forge-guard watch

# Watch multiple directories
forge-guard watch --dirs src,contracts

# Custom debounce
forge-guard watch --debounce-ms 1000

# Exclude test files
forge-guard watch --exclude *.test.sol

# Run full audit on change
forge-guard watch --full
```

---

## 11b. `forge-guard dashboard`

Launch a local web dashboard that visualizes the last audit result. Serves a self-contained page with an overall score gauge, per-category score bars, severity distribution charts, a score-over-time trend chart (from the SQLite history DB, populated by `audit --enable-history`), and an interactive finding list (severity chips, text search, chain filter, expandable details). Updates live over WebSocket whenever the cached audit result changes; `--watch` re-audits on file changes and pushes the new result to connected clients.

**Shared flags:** โœ…

### Flags

| Flag | Type | Default | Description |
|------|------|---------|-------------|
| `--port <N>` | `u16` | `9090` | Port to bind the dashboard HTTP server on |
| `--host <HOST>` | `String` | `127.0.0.1` | Host interface to bind (use `0.0.0.0` to expose on your network) |
| `--watch` | `bool` | `false` | Re-audit on file changes and push updates over WebSocket |
| `--dirs <DIRS>` | `String` | `src` | Directories to watch (comma-separated, used with `--watch`) |
| `--debounce-ms <N>` | `u64` | `500` | Debounce interval in ms when `--watch` is set |
| `--open` | `bool` | `false` | Open the dashboard in the default browser |
| `--full` | `bool` | `false` | Run full audit on change (includes exploit + gas, used with `--watch`) |

### Examples

```bash
# Run an audit first, then serve the dashboard
forge-guard audit
forge-guard dashboard

# Custom port
forge-guard dashboard --port 8080

# Expose on your network
forge-guard dashboard --host 0.0.0.0

# Re-audit on file changes with live WebSocket updates
forge-guard dashboard --watch

# Watch specific directories and open the browser
forge-guard dashboard --watch --dirs src,contracts --open

# Record history for the Score Trend chart, then view it on the dashboard
forge-guard audit --enable-history
forge-guard dashboard
```

---

## 12. `forge-guard ci`

Generate CI/CD pipeline configuration files for various platforms. Creates ready-to-use workflow files.

**Shared flags:** โœ…

### Flags

| Flag | Type | Default | Description |
|------|------|---------|-------------|
| `--platform <PLATFORM>` | `String` | `github` | CI platform: `github`, `gitlab`, `bitbucket`, `azure` |
| `--output <PATH>` | `PathBuf` | `.github/workflows` | Output directory for CI configs |
| `--include-deploy` | `bool` | `false` | Include deployment pipeline |
| `--overwrite` | `bool` | `false` | Overwrite existing files |

### Examples

```bash
# Generate GitHub Actions workflow
forge-guard ci --platform github

# GitLab CI
forge-guard ci --platform gitlab

# With deployment pipeline
forge-guard ci --platform github --include-deploy

# Custom output directory
forge-guard ci --output .github/workflows

# Overwrite existing configs
forge-guard ci --overwrite
```

---

## 13. `forge-guard benchmark`

Run performance benchmarks to measure and compare analysis speed across modules.

**Shared flags:** โœ…

### Flags

| Flag | Type | Default | Description |
|------|------|---------|-------------|
| `--iterations <N>` | `u32` | `10` | Number of benchmark iterations |
| `--warmup <N>` | `u32` | `3` | Warmup iterations before measurement |
| `--compare <FILE>` | `Option<PathBuf>` | โ€” | Compare with baseline results |
| `--save <FILE>` | `Option<PathBuf>` | โ€” | Save benchmark results |
| `--module <NAME>` | `Option<String>` | โ€” | Benchmark specific module (e.g., `source_discovery`) |

### Examples

```bash
# Run all benchmarks
forge-guard benchmark

# Custom iterations
forge-guard benchmark --iterations 50

# Benchmark specific module
forge-guard benchmark --module pattern_matching

# Compare with baseline
forge-guard benchmark --save results.json --compare baseline.json
```

---

## 14. `forge-guard scan`

Scan project dependencies for known vulnerabilities. Uses a 30+ entry vulnerability database covering OpenZeppelin, Solmate, Solady, Chainlink, Wormhole, LayerZero, forge-std, PRBMath, solc, and more.

**Shared flags:** โœ…

### Flags

| Flag | Type | Default | Description |
|------|------|---------|-------------|
| `--depth <N>` | `u32` | `1` | Scan depth (0=direct deps only, 1=direct + indirect, etc.) |
| `--update` | `bool` | `false` | Update vulnerability database from remote source |
| `--vulnerable-only` | `bool` | `false` | Output only packages with vulnerabilities |
| `--fail-fast` | `bool` | `false` | Fail immediately on any vulnerability |

### Examples

```bash
# Standard scan
forge-guard scan

# Deep scan (include indirect dependencies)
forge-guard scan --depth 2

# Update vulnerability database
forge-guard scan --update

# Show only vulnerable packages
forge-guard scan --vulnerable-only

# Fail on any vulnerability
forge-guard scan --fail-fast

# JSON output
forge-guard scan --json
```

---

## 15. `forge-guard upgrade-check`

Analyze upgrade paths and proxy safety. Checks storage collisions, UUPS upgrade paths, and proxy pattern correctness.

**Shared flags:** โœ…

### Flags

| Argument/Flag | Type | Default | Description |
|---------------|------|---------|-------------|
| `proxy` | `Option<String>` | โ€” | Proxy contract address |
| `implementation` | `Option<String>` | โ€” | Implementation contract address |
| `--all` | `bool` | `false` | Check all proxies |
| `--storage-collision` | `bool` | `false` | Check storage collision between versions |
| `--uups` | `bool` | `false` | Check UUPS upgrade path |

### Examples

```bash
# Check specific proxy
forge-guard upgrade-check 0xproxy 0ximpl

# Check all proxies
forge-guard upgrade-check --all

# Storage collision analysis
forge-guard upgrade-check --storage-collision

# UUPS path check
forge-guard upgrade-check --uups
```

---

## 16. `forge-guard plugins`

Manage audit plugins. Supports listing, installing, removing, enabling, disabling, and creating plugin scaffolds. Plugins can be built-in Rust plugins or external binaries communicating via JSON IPC.

**Shared flags:** โœ…

### Subcommands

| Subcommand | Description |
|------------|-------------|
| `list` | List installed plugins |
| `install <name> [source]` | Install a plugin from source (git URL or download URL) |
| `remove <name>` | Remove an installed plugin |
| `enable <name>` | Enable a plugin |
| `disable <name>` | Disable a plugin |
| `new <name>` | Create a new plugin scaffold with Rust template |

### Examples

```bash
# List installed plugins
forge-guard plugins list

# Create a new plugin scaffold
forge-guard plugins new my-custom-check

# Install from git
forge-guard plugins install my-check https://github.com/user/my-check.git

# Enable/disable
forge-guard plugins enable my-custom-check
forge-guard plugins disable my-custom-check

# Remove
forge-guard plugins remove my-custom-check
```

### Built-in Plugins

| Plugin | Version | Description |
|--------|---------|-------------|
| `forge-guard-example` | 0.1.0 | Example plugin showing the IPC protocol |
| `forge-guard-offline-guard` | 0.1.0 | Extra offline-mode security validations |

---

## 17. `forge-guard chain`

Configure chain settings. View supported chains, get chain info, add custom chains, and test RPC connectivity.

**Shared flags:** โœ…

### Subcommands

| Subcommand | Description |
|------------|-------------|
| `list` | List all supported chains |
| `info <chain>` | Show details about a specific chain |
| `add <name> [rpc_url] [chain_id]` | Add a custom chain |
| `remove <name>` | Remove a custom chain |
| `test <chain> [rpc_url]` | Test chain RPC connectivity |

### Supported Chains

| Chain | Chain ID | Currency |
|-------|----------|----------|
| Ethereum | 1 | ETH |
| Base | 8453 | ETH |
| Arbitrum | 42161 | ETH |
| Optimism | 10 | ETH |
| Polygon | 137 | MATIC |
| BNB Chain | 56 | BNB |
| Avalanche | 43114 | AVAX |
| Scroll | 534352 | ETH |
| Linea | 59144 | ETH |
| Unichain | 130 | ETH |
| ZKSync | 324 | ETH |
| HyperEVM | 999 | HYPE |
| Monad | 10143 | MON |
| Sonic | 146 | S |
| Blast | 81457 | ETH |
| Mantle | 5000 | MNT |
| Robinhood | 31753 | ETH |

### Examples

```bash
# List all chains
forge-guard chain list

# Show chain info
forge-guard chain info polygon

# Add custom chain
forge-guard chain add my-chain https://rpc.my-chain.io 99999

# Remove custom chain
forge-guard chain remove my-chain

# Test RPC connectivity
forge-guard chain test ethereum
forge-guard chain test polygon https://polygon-rpc.com
```

---

## 18. `forge-guard sbom`

Generate a Software Bill of Materials (SBOM) for your Foundry project. Supported formats: CycloneDX 1.6 and SPDX 2.3.

Automatically discovers dependencies from `remappings.txt`, `foundry.toml`, and `lib/` directory. Detects solc compiler version, Foundry framework, and library versions via `package.json`, `Cargo.toml`, and git refs.

**Shared flags:** โœ…

### Flags

| Flag | Type | Default | Description |
|------|------|---------|-------------|
| `--format <FORMAT>` | `String` | `cyclonedx` | SBOM format: `cyclonedx` (or `cyc`, `cdx`) or `spdx` |
| `--output <PATH>` | `Option<PathBuf>` | โ€” | Output file path (default: stdout) |
| `--ci` | `bool` | `false` | Also write `.github/workflows/sbom.yml` for automated SBOM publishing |

### Examples

```bash
# Generate CycloneDX SBOM (stdout)
forge-guard sbom

# SPDX format
forge-guard sbom --format spdx

# Save to file
forge-guard sbom --output sbom.json

# Format aliases work too
forge-guard sbom --format cdx

# Export a GitHub Actions workflow for supply-chain compliance
forge-guard sbom --ci
```

---

## 19. `forge-guard install-hook`

Install or uninstall a git pre-commit hook that automatically audits staged Solidity files before each commit. Blocks commits with HIGH or CRITICAL findings.

**No shared flags** โ€” operates independently on the git repository.

### Flags

| Flag | Type | Default | Description |
|------|------|---------|-------------|
| `--uninstall` | `bool` | `false` | Uninstall the pre-commit hook instead of installing |
| `--force` | `bool` | `false` | Force install even if a hook already exists |
| `--project <PATH>` | `PathBuf` | `.` | Project root path |

### Hook Behavior

- **On commit**: Runs `forge-guard audit --quick` on all staged `.sol` files
- **Blocks**: Commits where any staged `.sol` file has HIGH or CRITICAL findings
- **Bypass**: Set `FORGE_GUARD_SKIP_HOOK=1` environment variable to skip the hook
- **Safety check**: Uninstall verifies the hook is a forge-guard hook before removing
- **Worktree support**: Handles `.git` file references (common in git worktrees/submodules)

### Examples

```bash
# Install pre-commit hook
forge-guard install-hook

# Force install (overwrite existing hook)
forge-guard install-hook --force

# Uninstall
forge-guard install-hook --uninstall

# Install in specific project
forge-guard install-hook --project /path/to/project
```

---

## 20. `forge-guard security`

Configure security settings. View current configuration, list all available checks, set thresholds, and enable/disable individual checks.

**Shared flags:** โœ…

### Subcommands

| Subcommand | Description |
|------------|-------------|
| `config` | Show current security configuration |
| `threshold <score>` | Set minimum deployment score (0โ€“100) |
| `enable <check>` | Enable a specific security check |
| `disable <check>` | Disable a specific security check |
| `list` | List all available security checks with severity levels |
| `info <check>` | Show detailed information about a specific check |

### Examples

```bash
# Show current config
forge-guard security config

# List all checks
forge-guard security list

# Check details
forge-guard security info Reentrancy

# Set threshold
forge-guard security threshold 85

# Enable/disable checks
forge-guard security enable "tx.origin Usage"
forge-guard security disable "Unsafe Assembly"
```

---

## 21. `forge-guard import`

Import findings from external security analyzers (Slither, Mythril, Semgrep) into Forge Guard's unified format. Tool-specific severity scales are mapped onto Forge Guard's 5-level scale, and findings can be deduplicated against Forge Guard's own audit results to produce a combined report.

**Shared flags:** โœ…

### Flags

| Flag | Type | Default | Description |
|------|------|---------|-------------|
| `--from <TOOL>` | `String` | `slither` | Analyzer to import from: `slither`, `mythril`, `semgrep` |
| `input` | `Option<PathBuf>` | โ€” | Path to the analyzer's JSON results file |
| `--findings <FILE>` | `Option<PathBuf>` | โ€” | Forge-guard audit JSON to deduplicate against (unified report) |
| `--output <FILE>` | `Option<PathBuf>` | โ€” | Write the unified report (JSON) to a file |

### Severity Mapping

| Tool | Source field | Mapping |
|------|-------------|---------|
| Slither | `impact` (`High`/`Medium`/`Low`/`Informational`/`Optimization`) | โ†’ High/Medium/Low/Info |
| Mythril | `severity` or `type` | โ†’ High/Medium/Low/Info |
| Semgrep | `severity` (`ERROR`/`WARNING`/`INFO`) | โ†’ High/Medium/Low |

### Examples

```bash
# Import Slither results (terminal report)
forge-guard import --from slither slither_results.json

# Import Mythril results and deduplicate against the last forge-guard audit
forge-guard import --from mythril mythril_out.json --findings reports/audit.json

# Import Semgrep results as JSON
forge-guard import --from semgrep semgrep_results.json --json

# Write a unified report file
forge-guard import --from slither slither_results.json --findings reports/audit.json --output unified.json
```

### Supported JSON Schemas

Imported findings are tagged with a tool prefix in their ID (`SL-`, `MY-`, `SG-`), and deduplication (with `--findings`) matches on file + line + lowercase title. Only the fields below are read โ€” anything else is ignored.

#### Slither (`slither . --json out.json`)

| Path | Used as |
|------|---------|
| `results.detectors[]` | One finding per detector |
| `.check` | Finding title & category (`slither:<check>`) |
| `.impact` | Severity (`High`/`Medium`/`Low`/`Informational`/`Optimization`) |
| `.description` | Finding description |
| `.markdown` | Recommendation |
| `.elements[0].source_mapping.filename_relative` (or `filename_absolute`) | File path |
| `.elements[0].source_mapping.line` | Line number |
| `.elements[0].source_mapping.content` | Code snippet |

```json
{
  "success": true,
  "results": {
    "detectors": [
      {
        "check": "reentrancy-eth",
        "impact": "High",
        "description": "Reentrancy in withdraw",
        "markdown": "Use checks-effects-interactions.",
        "elements": [
          {
            "type": "function",
            "name": "withdraw",
            "source_mapping": {
              "filename_relative": "contracts/Vault.sol",
              "line": 42,
              "content": "msg.sender.call{value: amount}(\"\");"
            }
          }
        ]
      }
    ]
  }
}
```

#### Mythril (`myth analyze ... -o mythril_out.json`)

| Path | Used as |
|------|---------|
| `issues[]` | One finding per issue |
| `.title` | Finding title |
| `.severity` or `.type` | Severity (`Critical`/`High`/`Medium`/`Low`) |
| `.description` | Finding description |
| `.function` | Category (`mythril:<function>`) |
| `.swc-id` | Reference (`SWC-<id>`) |
| `.source.filename` | File path |
| `.source.line` | Line number |
| `.source.source` | Code snippet |

```json
{
  "success": true,
  "issues": [
    {
      "title": "The contract executes an external call",
      "severity": "High",
      "swc-id": "107",
      "function": "withdraw",
      "source": {
        "filename": "contracts/Vault.sol",
        "line": 42,
        "source": "msg.sender.call{value: amount}(\"\");"
      }
    }
  ]
}
```

#### Semgrep (`semgrep scan --json`)

| Path | Used as |
|------|---------|
| `results[]` | One finding per result |
| `.check_id` | Category (`semgrep:<check_id>`), title fallback |
| `.extra.message` | Finding title |
| `.extra.severity` | Severity (`ERROR`/`WARNING`/`INFO`) |
| `.extra.lines` | Code snippet |
| `.extra.metadata.cwe` (array or string) | References (`CWE-...`) |
| `.path` | File path |
| `.start.line` | Line number |

```json
{
  "results": [
    {
      "check_id": "solidity.reentrancy",
      "path": "contracts/Vault.sol",
      "start": { "line": 42, "col": 1 },
      "extra": {
        "message": "External call before state update",
        "severity": "ERROR",
        "metadata": { "cwe": ["CWE-1077"] },
        "lines": "msg.sender.call{value: amount}(\"\");"
      }
    }
  ],
  "errors": []
}
```

---

## 22. `forge-guard notify`

Send audit summaries to Slack and Discord webhooks. Platform is auto-detected from the webhook URL, or set explicitly with `--kind`. Payloads include severity counts, overall score, risk level, and top findings.

> ๐Ÿ’ก See [`examples/forge-guard.toml`](examples/forge-guard.toml) for a fully commented `[notifications.slack]` / `[notifications.discord]` configuration.

**Shared flags:** โœ…

### Flags

| Flag | Type | Default | Description |
|------|------|---------|-------------|
| `--webhook <URL>` | `Option<String>` | โ€” | Webhook URL (overrides `forge-guard.toml`) |
| `--kind <PLATFORM>` | `Option<String>` | โ€” | Platform: `slack` or `discord` (auto-detected from URL when omitted) |
| `--findings <FILE>` | `Option<PathBuf>` | โ€” | Forge-guard audit result JSON to summarize |
| `--title <TEXT>` | `String` | `Forge Guard Audit` | Notification title |
| `--message <TEXT>` | `Option<String>` | โ€” | Extra free-form message text |
| `--severity <LEVEL>` | `Option<String>` | โ€” | Minimum severity gate: `informational`, `low`, `medium`, `high`, `critical` |
| `--on-critical` | `bool` | `false` | Only notify when critical findings are present |
| `--on-high` | `bool` | `false` | Only notify when high (or higher) findings are present |
| `--dry-run` | `bool` | `false` | Print the exact payload without sending |

### Configuration

```toml
[notifications.slack]
webhook = "https://hooks.slack.com/services/T000/B000/XXXX"
min_severity = "high"

[notifications.discord]
webhook = "https://discord.com/api/webhooks/123/abc"
min_severity = "critical"
```

The `--notify` flag on `forge-guard audit`, `forge-guard deploy`, and `forge-guard deploy-safe` uses this configuration automatically. Blocked deployments always notify; successful runs respect `min_severity`.

### Examples

```bash
# Send a summarized audit result to a Slack webhook
forge-guard notify --findings reports/audit.json --webhook https://hooks.slack.com/services/T/B/X

# Discord embed, only when critical findings exist
forge-guard notify --findings reports/audit.json --on-critical

# Dry-run: print the payload without sending
forge-guard notify --findings reports/audit.json --dry-run

# Simple message
forge-guard notify --webhook https://hooks.slack.com/services/T/B/X --title "Nightly audit" --message "All checks passed"
```

---

## Appendix: Severity Levels

| Severity | Color | Blocks Deployment |
|----------|-------|-------------------|
| ๐Ÿ›‘ Critical | Red | โœ… Yes |
| ๐Ÿ”ด High | Red | โœ… Yes |
| ๐ŸŸก Medium | Yellow | โŒ No (configurable) |
| ๐Ÿ”ต Low | Blue | โŒ No |
| โšช Info | White | โŒ No |

## Appendix: Exit Codes

| Code | Meaning |
|------|---------|
| `0` | Success โ€” no findings blocking deployment |
| `1` | Failure โ€” findings detected or command error |
| `2` | Invalid arguments |

---

*Generated from the Forge Guard codebase. For the latest updates, see the [CHANGELOG](CHANGELOG.md).*