Skip to content

Conversation

MariaChrysafis
Copy link

refactor: consolidate permissions into structured types

Summary

Refactored the Claude Code SDK permissions system to use cleaner, structured types instead of scattered individual fields. Added ToolConfig and PermissionConfig structs to group related configuration options, following patterns observed in reference repositories like opcode.

Key Changes:

  • New structured types: ToolConfig (with Allowed/Disallowed) and PermissionConfig (with Mode/PromptTool/DangerouslySkip)
  • Backward compatibility: All existing fields remain functional but are marked as deprecated
  • Dual field support: CLI argument building handles both new structured fields and legacy individual fields
  • Updated examples: All example files and documentation updated to demonstrate the new structured approach
  • Cleaner API: Reduces verbose option setting and groups related permissions logically

The refactoring maintains 100% backward compatibility while providing a cleaner, more organized API for new users.

Review & Testing Checklist for Human

⚠️ Medium Risk PR - Requires careful testing due to API changes and multiple file updates

  • Test backward compatibility: Verify existing code using AllowedTools, DisallowedTools, PermissionMode, etc. still works unchanged
  • Test potential conflicts: Check behavior when both new structured fields AND legacy fields are set simultaneously (e.g., both Tools.Allowed and AllowedTools)
  • Validate example compilation: Ensure all updated example files in examples/ directory compile and run without errors
  • Test CLI integration: Run actual Claude CLI commands to verify the CLI argument generation produces correct --allowedTools, --permission-mode, etc. flags
  • Verify JSON serialization: Test that the new struct types serialize/deserialize correctly and don't break existing API consumers

Notes

  • Integration tests were skipped during development due to missing Claude CLI, so manual CLI testing is especially important
  • The CLI argument building logic now checks both new and legacy fields - watch for potential argument duplication
  • All backward compatibility is preserved through deprecated field handling in addModelAndToolArgs() and addPermissionArgs()

Requested by: Maria Chrysafis (@MariaChrysafis)
Link to Devin run: https://app.devin.ai/sessions/df27f367592345bd9b9cade2fcbb0e9c

- Add ToolConfig and PermissionConfig for cleaner organization
- Maintain backward compatibility with deprecated fields
- Reduce verbose permission handling code
- Update documentation with new structured approach
- Update all examples to use new structured permissions

Co-Authored-By: Maria Chrysafis <[email protected]>
Copy link

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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.

1 participant