Skip to content

Add ward init subcommand#4

Open
jstockdi wants to merge 1 commit intomainfrom
ward-init
Open

Add ward init subcommand#4
jstockdi wants to merge 1 commit intomainfrom
ward-init

Conversation

@jstockdi
Copy link
Copy Markdown
Owner

@jstockdi jstockdi commented Apr 6, 2026

Summary

  • Add ward init subcommand that auto-configures Claude Code hooks in ~/.claude/settings.json
  • Supports --dry-run (preview), --force (overwrite), and --remove (clean up) flags
  • Preserves existing non-ward hooks and other settings keys during merge and removal

Implementation

  • New src/init.rs module with hook configuration builder, JSON merge logic, and ward hook detection
  • Init variant added to Command enum in src/cli.rs with three boolean flags
  • src/main.rs restructured to handle init before stdin parsing (init does not read stdin)
  • 10 unit tests in init.rs covering merge, strip, and detection logic
  • 12 integration tests in tests/test_init.rs covering all subcommand modes and edge cases

Test plan

  • ward init creates settings.json from scratch with all five hook events
  • ward init --dry-run prints config to stdout without writing files
  • ward init errors when ward hooks already exist, suggesting --force
  • ward init --force replaces existing ward hooks while preserving non-ward hooks
  • ward init --remove strips ward hooks and cleans up empty events/hooks keys
  • Non-ward hooks and other settings keys are preserved in all operations
  • ward init does not block on stdin
  • All 139 existing + new tests pass with no warnings

Closes #1

Introduce `ward init` to automatically configure Claude Code hooks
in ~/.claude/settings.json. Supports --dry-run to preview changes,
--force to overwrite existing ward hooks, and --remove to clean up.
Preserves non-ward hooks and other settings during merge/removal.

Closes #1
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.

ward init — Auto-configure Claude Code hooks

1 participant