feat: add CodeBuddy Code support#1967
Conversation
Implements rtk-ai#1966 - Add CODEBUDDY_DIR (.codebuddy) and CODEBUDDY_HOOK_COMMAND constants - Add `rtk hook codebuddy` command that reuses Claude Code's PreToolUse JSON protocol (tool_input.command + PreToolUse event) - Add `rtk init -g --agent codebuddy` to install the hook into ~/.codebuddy/settings.json and write ~/.codebuddy/CODEBUDDY.md - Add `rtk init -g --agent codebuddy --uninstall` to remove artifacts - Add AgentTarget::Codebuddy enum variant - Extract patch_settings_json_at() helper for patching settings.json in an arbitrary agent config directory (used by CodeBuddy; avoids hardcoding the Claude config dir) - Add hooks/codebuddy/rtk-awareness.md and hooks/codebuddy/README.md
# Conflicts: # src/hooks/init.rs
- Extract patch_settings_json_at() as generic version of patch_settings_json_command(), accepting an explicit agent dir - Extract remove_hooks_from_settings_at() as generic version of remove_hook_from_settings(), accepting path + hook commands - Extract remove_matching_hooks_from_json() from remove_hook_from_json(), accepting a command list instead of hardcoding CLAUDE_HOOK_COMMAND - Delete remove_rtk_hook_from_settings() — CodeBuddy uninstall now uses the shared remove_hooks_from_settings_at() - Keep backward-compatible wrappers for Claude-specific behavior (manual instructions output, resolve_claude_dir)
|
Hi maintainers 👋 Just a quick update — I've refactored the CodeBuddy/Claude settings.json handling to eliminate the duplication I introduced earlier. The shared logic is now extracted into:
CodeBuddy support is now fully wired up and production-ready:
All 1996 tests pass. The refactoring makes it straightforward to add future agents that share the same I'd love to get this merged so CodeBuddy Code users can benefit from RTK's token savings. Happy to address any feedback. Thanks for reviewing! |
|
When will it be released? |
|
Hi @FlorianBruniaux @pszymkowiak — gentle ping on this PR. It has been open for about a month and all 1996 tests pass with zero conflicts. Just a bit of context on why this matters: I am actively working on adding Headroom support for CodeBuddy Code, and that project integrates RTK as its token-optimization layer. Having this PR merged would make the Headroom + RTK + CodeBuddy Code stack work seamlessly out of the box, which benefits both projects. Quick recap of the change
Scope
Would really appreciate a review when you have a moment. Happy to address any feedback or make adjustments. Thanks! |
|
Hi @aeppling @KuSh — gentle ping on this PR. I noticed you two have been actively merging PRs this past week (e.g. #2514, #2465, #2416, #2406, #2394, #2294). Would you mind taking a look at this one when you have a moment? Quick recap
This has been open since May 19. Happy to address any feedback or make changes. Thanks! |
KuSh
left a comment
There was a problem hiding this comment.
Hi, thanks for the PR. A few changes are needed before we can consider merging this.
I’m not familiar with CodeBuddy Code, and while we plan to support the main tools, we don’t necessarily want to add every niche one. Especially since this appears to be compatible with Claude, it seems a symlink to the .claude directory might be all that’s needed.
Could you share a bit more context on why CodeBuddy Code should be integrated here, such as what unique needs it covers beyond Claude compatibility, and how significant its user base or adoption is?
- Delegate run_codebuddy to run_claude (zero protocol duplication) - Switch remove_hooks_from_settings_at to single &str (YAGNI per reviewer) - Simplify Skip-mode match to unified print_manual_instructions on Skipped|Declined - Restore Claude-specific output (backup hint + Restart) lost during refactor - Fix stale doc comment on patch_settings_json_at (relationship reversed) - Extract uninstall_codebuddy_at for testability + add 3 unit tests - Simplify resolve_codebuddy_dir match to ? - Merge Patched|WouldPatch no-op arms; gate Restart print on AlreadyPresent - Extract patch_mode_from_flags helper (dedup gemini/codebuddy/default) - Move CodeBuddy entries to list ends per reviewer nitpick - Add protocol-stability note to hooks/codebuddy/README.md - Shared rtk_awareness_for_agent template; drop codebuddy/rtk-awareness.md All 1999 tests pass.
|
Hi @KuSh, thanks for the thorough review — all feedback addressed in the latest push (commit On the top-level question: why CodeBuddy Code, not a symlinkCodeBuddy Code is an independent product (hosted at cnb.cool/codebuddy/codebuddy-code, built by Tencent) — it is not a Claude Code fork or wrapper. A symlink from
The only thing CodeBuddy Code shares with Claude Code is the If you'd like more context on adoption: CodeBuddy Code is the AI coding agent bundled with CodeBuddy (Tencent's AI dev suite). I'm actively integrating RTK as the token-optimization layer for CodeBuddy Code via Headroom, so this PR is what makes that stack work out of the box. Inline comments
Happy to adjust anything else. |
- Drop the 'Code' suffix everywhere (code + docs): the product is called CodeBuddy, not 'CodeBuddy Code'. - Update the official URL from cnb.cool/codebuddy/codebuddy-code to https://www.codebuddy.ai across hooks/codebuddy/README.md. No behavioral change. All 1999 tests pass.
KuSh
left a comment
There was a problem hiding this comment.
Thanks for the changes! Unfortunately, there’s one big blocker: CodeBuddy handles exit codes differently from Claude, so we’ll need to adapt the preToolUse shell to account for that. Otherwise LGTM!
CodeBuddy's PreToolUse protocol uses `modifiedInput` (not Claude's `updatedInput`), so delegating to `run_claude` silently dropped every rewrite. Restore a dedicated path. Two correctness fixes vs the naive delegation: - Deny verdict now emits `permissionDecision: "deny"` instead of returning empty output (which CodeBuddy treats as allow). Without this, RTK deny rules were non-functional under CodeBuddy. - Ask/Default verdicts map to `"ask"` so CodeBuddy prompts the user, matching the existing VSCode/Claude path behavior. Previously the dedicated path hard-coded `"allow"`, bypassing ask rules. Also: use `PRE_TOOL_USE_KEY` constant instead of literal, drop misleading `rtk rewrite` exit-code comment, and fix a pre-existing rustfmt nit in init.rs so CI `cargo fmt --check` passes.
|
Thanks for catching the exit-code/protocol blocker (@KuSh). I dug into it and the root cause is a protocol field-name mismatch rather than exit codes themselves: CodeBuddy's PreToolUse expects Changes in the latest push (
On the earlier inline suggestion to collapse Verified locally: Regarding the |
Closes #1966
Summary
Adds first-class support for CodeBuddy Code, a Claude-powered AI coding assistant whose config lives in
.codebuddy/.CodeBuddy Code uses the same
PreToolUsehook JSON protocol as Claude Code, so the hook implementation delegates directly to the existingprocess_claude_payloadlogic.Changes
New commands
rtk hook codebuddy— PreToolUse hook processor (reads JSON from stdin, rewritestool_input.command)rtk init -g --agent codebuddy— installs hook into~/.codebuddy/settings.jsonand writes~/.codebuddy/CODEBUDDY.mdrtk init -g --agent codebuddy --uninstall— removes all RTK artifactsFiles changed
src/hooks/constants.rsCODEBUDDY_DIR(.codebuddy) andCODEBUDDY_HOOK_COMMANDconstantssrc/hooks/hook_cmd.rsrun_codebuddy()— delegates toprocess_claude_payloadsrc/hooks/init.rsrun_codebuddy_mode(),uninstall_codebuddy(), andpatch_settings_json_at()helpersrc/main.rsAgentTarget::Codebuddy,HookCommands::Codebuddy, dispatch logichooks/codebuddy/rtk-awareness.md~/.codebuddy/CODEBUDDY.mdhooks/codebuddy/README.mdDesign notes
PreToolUse+tool_input.commandJSON format as Claude Code, sorun_codebuddy()simply callsprocess_claude_payload().patch_settings_json_at(): Extracted a new helper that patchessettings.jsonin an arbitrary directory (instead of hardcoding the Claude config dir). This makes it easy to add future agents with similar config layouts.~/.codebuddy/).Testing