Merged
Conversation
…ager Adopts three major features from bnema/claude-agent-sdk-go fork: Budget Tracking (budget.go): - BudgetTracker for cumulative spending across sessions - Warning thresholds with callbacks - Per-session spending breakdown Plugin System (plugin.go): - Plugin interface with lifecycle hooks (OnToolCall, OnMessage, OnComplete) - Priority-based execution ordering - Pre-built plugins: Logging, Metrics, ToolFilter, Audit - BasePlugin for easy extension Subagent Management (subagent.go): - SubagentManager for registering and executing specialized agents - SubagentConfig with description, prompt, tools, model - Pre-built templates: SecurityReviewer, CodeReviewer, TestAnalyst, etc. - Session continuity support Also updates: - RunOptions with new fields (BudgetTracker, PluginManager, Agents, etc.) - permissions.go with ToolInput, PermissionResult, PermissionCallback - Pre-built permission callbacks (ReadOnlyCallback, SafeBashCallback, etc.) - JSON response parsing to handle CLI's new array format
Examples added: - sessions: Session management (SessionID, ForkSession, ephemeral) - mcp: MCP configuration with builder pattern - permissions: Permission callbacks and chaining - retry: RetryPolicy and error recovery patterns - streaming: StreamPrompt with channel handling - workflow: CI/CD automation patterns Build system: - Removed Taskfile.yml (project uses just/make) - Updated build.just with new example targets - Fixed modular justfile path resolution Code review fixes applied: - Use math.Pow instead of custom pow function - Added security warning for hardcoded credentials
1. Use errors.Join in PluginManager.Shutdown to collect all plugin shutdown failures instead of only returning the last error 2. Fix mutex-held-during-callback pattern in PluginManager callbacks (OnToolCall, OnMessage, OnComplete) using copy-under-lock to prevent potential deadlocks 3. Implement proper glob matching in ToolPermission.MatchesPattern using filepath.Match for standard patterns (*, ?, [...]) and custom logic for ** recursive directory matching 4. Use crypto/rand for backoff jitter calculation to prevent timing prediction and ensure cryptographically secure randomization
- Expand dangerous package tests from 41.5% to 90.4% - Add BYPASS_ALL_PERMISSIONS context and variant tests - Add DANGEROUS_RunWithEnvironment tests - Add GetSecurityWarnings with MCP debug tests - Add AllProductionEnvChecks test cases - Replace custom containsString helper with strings.Contains - Add comprehensive context cancellation tests to claude package - TestRunPromptCtx_ContextCancellation - TestRunPromptCtx_ContextDeadlineExceeded - TestStreamPrompt_ContextCancellation - TestStreamPrompt_ContextDeadline - TestRunFromStdinCtx_ContextCancellation - TestRunOptionsTimeout - TestContextPropagationThroughMethods - Add MCP configuration error path tests - TestParseMCPConfig_InvalidJSONVariants - TestLoadMCPConfigFile_Errors - TestMCPConfig_Merge_EdgeCases - TestMCPConfig_GetServer_EdgeCases - TestParseMCPConfig_NullJSON Coverage: 82.9% (claude), 90.4% (dangerous)
Extract claude.go into smaller, focused files: - options.go: RunOptions struct, OutputFormat, PermissionMode, PreprocessOptions, validation helpers, RetryPolicy - session.go: Session management (GenerateSessionID, ValidateSessionID, RunWithSession, RunEphemeral, ForkAndRun methods) - streaming.go: Message type and StreamPrompt method This refactoring: - Reduces claude.go from 1019 lines to 487 lines - Improves code organization and maintainability - Maintains 100% backward compatibility (no API changes) - All tests pass with same coverage (82.9%/90.4%)
Move pre-built plugin implementations from plugin.go to dedicated file: - LoggingPlugin: Tool call and message logging with secret redaction - MetricsPlugin: Execution metrics collection - ToolFilterPlugin: Tool blocking by name - AuditPlugin: Audit trail recording Also moved supporting code: - secretPatterns regex patterns - truncateString, redactSecrets, getCurrentTimestamp helpers This refactoring: - Reduces plugin.go from 634 lines to 327 lines - Separates core interface/manager from built-in implementations - Maintains 100% backward compatibility - All tests pass with same coverage (82.9%/90.4%)
- Full README.md rewrite covering all SDK features including plugins, budget tracking, subagents, session control, MCP, retry, and permissions - Update demo README with 4 new interactive demos - Add Makefile and justfile targets for all 9 demos - Fix sessions demo GenerateSessionID signature (returns 1 value) - Fix permissions demo PermissionMode constant names - Add new demo modules to go.work workspace
- Replace fmt.Print/Println with os.Stdout.WriteString for documentation blocks containing Printf format specifiers (avoids go vet false positives) - Remove redundant trailing newlines from multi-line string literals - All examples now pass go vet without warnings
- Add scripts/record-demo-gif.sh for automated GIF recording - Add 9 demo scripts in scripts/demo-scripts/ for each SDK feature - Add GIF commands to .justfiles/demos.just (gif, gif-all, gif-list) - Create docs/DEMOS.md with sections for each demo - Create docs/gif/ directory for storing generated GIFs Uses asciinema + agg for terminal recording and GIF conversion. Generate GIFs with: just demo gif <name> or just demo gif-all
Replace demo shell scripts with input files for recording actual Go demos: - Delete scripts/demo-scripts/*.sh (code snippet display scripts) - Add scripts/demo-inputs/*.txt (input for real demo recordings) - Update record-demo-gif.sh to build and run real Go binaries - Update docs/DEMOS.md to reflect new approach The GIF recordings now capture real Claude API interactions instead of static code snippets, showing actual SDK functionality in action.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: CLI Feature Parity Release (v1.0.0)
Summary
This PR brings the Go SDK to feature parity with the Claude Code CLI, adding comprehensive abstractions for plugins, budget tracking, session management, streaming, subagent orchestration, and MCP integration.
What's Changed
New Features
Plugin System
OnToolCall,OnMessage,OnComplete,Initialize,ShutdownPluginManagerfor registering and coordinating multiple pluginsLoggingPlugin- Configurable logging with secret sanitizationMetricsPlugin- Execution metrics collectionToolFilterPlugin- Block specific toolsAuditPlugin- Record all tool calls for auditingBudget Tracking
BudgetTrackerwith configurable spending limitsSession Management
SessionManagerfor multi-turn conversation stateResumeIDStreaming Support
StreamPromptfor real-time response processingSubagent Orchestration
SubagentManagerfor spawning and managing child agentsMCP Integration
mcp__<server>__<tool>)Additional CLI Flag Support
JSONSchema- Structured output validation with JSON SchemaFallbackModel- Automatic fallback when primary model is overloadedDebug- Debug mode with category filteringCode Quality Improvements
claude.gofrom ~800 lines to focused modules:options.go- Configuration and validationstreaming.go- Stream handlingsession.go- Session managementbuiltin_plugins.go- 313 lines of reusable pluginsClaudeErrortypesTesting
plugin_test.go: 929 lines covering all plugin scenariossubagent_test.go: 570 lines with concurrent execution testsbudget_test.go: 214 lines with thread-safety testsmcp_test.go: 815 lines for MCP validationDocumentation & Examples
examples/budget/- Budget tracking demoexamples/mcp/- MCP integrationexamples/permissions/- Permission modesexamples/plugins/- Plugin system usageexamples/retry/- Retry with backoffexamples/sessions/- Session managementexamples/streaming/- Real-time streamingexamples/subagents/- Subagent orchestrationexamples/workflow/- Complex workflow patternsdocs/DEMOS.mddocumentationBuild System
.justfiles/)just build,just test,just democommandsjust releasemodule for release managementBreaking Changes
None. This release is fully backward compatible with v0.1.x.
Testing Checklist
just test all)just lint)Merge Checklist