Skip to content

Commit 176d9b6

Browse files
fohteclaude
andauthored
feat(init): add runok init subcommand (#152)
Co-authored-by: Claude Opus 4.6 <[email protected]>
1 parent c2f6d72 commit 176d9b6

24 files changed

Lines changed: 3672 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 140 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ seccompiler = "=0.5.0"
2525
anyhow = "=1.0.102"
2626
cel-interpreter = "=0.10.0"
2727
clap = { version = "=4.5.60", features = ["derive"] }
28+
dialoguer = "=0.11.0"
2829
schemars = { version = "=1.2.1", optional = true }
2930
serde = { version = "=1.0.228", features = ["derive"] }
3031
serde-saphyr = "=0.0.20"
3132
serde_json = "=1.0.149"
3233
sha2 = "=0.10.9"
3334
shlex = "=1.3.0"
35+
similar = { version = "=2.7.0", features = ["unicode"] }
3436
thiserror = "=2.0.18"
3537
tree-sitter = "=0.26.5"
3638
tree-sitter-bash = "=0.25.1"

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,15 @@ Pre-built binaries are also available on [GitHub Releases](https://github.com/fo
140140

141141
### Configure
142142

143-
Create `~/.config/runok/runok.yml`:
143+
The fastest way to get started is with the interactive setup wizard:
144+
145+
```sh
146+
runok init
147+
```
148+
149+
This creates a `runok.yml`, and if you have Claude Code configured, migrates your Bash permissions to runok rules and registers the PreToolUse hook automatically.
150+
151+
You can also configure manually. Create `~/.config/runok/runok.yml`:
144152

145153
```yaml
146154
rules:
@@ -155,9 +163,7 @@ defaults:
155163
action: ask
156164
```
157165

158-
### Integrate with Claude Code
159-
160-
Add runok as a PreToolUse hook in `.claude/settings.json`:
166+
And add runok as a PreToolUse hook in `.claude/settings.json`:
161167

162168
```json
163169
{

docs/src/content/docs/cli/init.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: runok init
3+
description: Initialize runok configuration with an interactive setup wizard.
4+
sidebar:
5+
order: 4
6+
---
7+
8+
`runok init` creates a `runok.yml` configuration file through an interactive setup wizard. It can also detect existing Claude Code Bash permissions and migrate them to runok rules.
9+
10+
## Usage
11+
12+
```sh
13+
runok init [options]
14+
```
15+
16+
## Flags
17+
18+
### `--scope <scope>`
19+
20+
Configuration scope. Available values:
21+
22+
- `user` — Create `~/.config/runok/runok.yml` for global rules that apply to all projects. Also registers the runok PreToolUse hook in `~/.claude/settings.json` if Claude Code is detected.
23+
- `project` — Create `runok.yml` in the current directory for project-specific rules.
24+
25+
When omitted, the wizard prompts you to choose.
26+
27+
### `-y`, `--yes`
28+
29+
Accept all defaults without prompting. Useful for scripted setups.
30+
31+
## What the wizard does
32+
33+
1. **Scope selection** — Choose `user` or `project` scope (skipped if `--scope` is given).
34+
2. **Claude Code detection** — If a `.claude/settings.json` exists with Bash permissions or a missing runok hook, the wizard offers to:
35+
- **Migrate Bash permissions** — Convert `permissions.allow` and `permissions.deny` entries for `Bash(...)` patterns into runok rules, and remove them from `settings.json`.
36+
- **Register the hook** — Add the `runok check` PreToolUse hook to `settings.json` (user scope only).
37+
3. **Preview and confirm** — Show a unified diff of all proposed changes and ask for confirmation.
38+
4. **Create `runok.yml`** — Write the configuration file with migrated rules (if any) or a boilerplate template.
39+
40+
## Examples
41+
42+
Interactive setup (prompts for scope and options):
43+
44+
```sh
45+
runok init
46+
```
47+
48+
Set up user-global configuration non-interactively:
49+
50+
```sh
51+
runok init --scope user -y
52+
```
53+
54+
Set up project-local configuration:
55+
56+
```sh
57+
runok init --scope project
58+
```
59+
60+
## Related
61+
62+
- [Quick Start](/getting-started/quickstart/) — Getting started with runok.
63+
- [Claude Code Integration](/getting-started/claude-code/) — Manual hook setup and sandbox configuration.
64+
- [Configuration](/configuration/schema/) — Full configuration reference.

docs/src/content/docs/cli/overview.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ sidebar:
55
order: 1
66
---
77

8-
runok provides two main subcommands for evaluating and executing commands against your permission rules.
8+
runok provides subcommands for initializing configuration, evaluating commands, and executing them against your permission rules.
99

1010
## Commands
1111

12+
### [`runok init`](/cli/init/)
13+
14+
Initialize runok configuration with an interactive setup wizard. Detects existing Claude Code Bash permissions and offers to migrate them to runok rules.
15+
1216
### [`runok check`](/cli/check/)
1317

1418
Evaluate a command against your rules and report the decision — without executing it. Useful for previewing what runok would do, or for integrating with external tools like [Claude Code hooks](/getting-started/claude-code/).

docs/src/content/docs/getting-started/claude-code.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ runok integrates with [Claude Code](https://docs.anthropic.com/en/docs/claude-co
1818

1919
If you haven't already, follow the [Quick Start](/getting-started/quickstart/) to install runok and create a `runok.yml`.
2020

21+
:::tip
22+
[`runok init --scope user`](/cli/init/) can automate steps 1 and 2: it creates a `runok.yml`, migrates existing Claude Code Bash permissions, and registers the hook — all in one command.
23+
:::
24+
2125
## Step 2: Configure the PreToolUse hook
2226

2327
Add the runok hook to your Claude Code settings file (`.claude/settings.json`):

0 commit comments

Comments
 (0)