Repository navigation
Docs: guard a Claude Agent SDK app with cloudpin (#142) - #144
Merged
Merged
Conversation
docs/agent-sdk.md: an SDK app loads the project's .claude/settings.json by default, so `cloudpin install-hook claude` already guards it; with setting_sources=[] a PreToolUse callback (Python and TypeScript) pipes the hook input to `cloudpin hook claude` and fails closed. Covers Windows (cmd.exe with NoDefaultCurrentDirectoryInExePath, why not shutil.which or the .cmd shim directly), timeouts, "ask" answers and the MCP server as advice. Both snippets were run in real SDK sessions (claude-agent-sdk 0.2.174, @anthropic-ai/claude-agent-sdk 0.3.310, Claude Code 2.1.310) against a made-up GitHub pin and the active one, read-only commands only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cloudpin hook claude, fed the SDK's PreToolUse input with its extra fields, answers with exactly an SDK PreToolUse output or nothing, and takes the pin from the input's cwd. The page's two callbacks stay under 40 lines, start cloudpin through cmd.exe with a fixed line and no current-folder search, never use a shell, shutil.which or "allow", and load no settings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The plugin line was not tested in an SDK session, so it goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…#142) A callback that raises lets the command run (measured with Claude Code 2.1.310). The Python callback caught only OSError and TimeoutError, so output that isn't UTF-8 raised past it; a synchronous throw in the TypeScript Promise executor became a rejection. Both now catch everything around the whole body and deny, and deny an answer that isn't a JSON object. Called directly, both deny for invalid UTF-8 (Python), a BigInt input and an already-aborted signal (TypeScript), and JSON that isn't an object. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Checks both callbacks catch any error and an answer that isn't an object, and counts snippet lines without the trailing newline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…#142) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Closes #142.
docs/agent-sdk.mdcovers guarding a Claude Agent SDK app with cloudpin:cloudpin install-hook claudealready guards it.PreToolUsecallback for apps withsetting_sources=[]. On Windows they start cloudpin through%SystemRoot%\System32\cmd.exewithNoDefaultCurrentDirectoryInExePath=1, the forminstall-hookwrites for Codex and Copilot. A plantedcloudpin.cmdin the app's folder never runs.shutil.whichand a bare cross-spawn would search the current folder.askanswers, and the MCP server as advice.docs/mcp.md links the page.
Evidence (owner-approved real SDK sessions, read-only
gh repo view, fake pin)claude-agent-sdk0.2.174 and TypeScript@anthropic-ai/claude-agent-sdk0.3.310 (each bundles Claude Code 2.1.310), modelhaiku; 7 sessions, about $0.07.setting_sources=[]): a wrong pin was denied, and the right pin ran ({"name":"cli"}).tscpasses on the TypeScript snippet against the SDK's types.Checks
test/agent-sdk.test.ts(new, 13 tests):cloudpin hook claudeanswers the SDK's PreToolUse shape, and the pin comes from the input'scwd;npm run typecheck: exit 0.npm test: 1280 passed, 8 skipped.askin an SDK app, the MCP option inside a session, and a--userhook.🤖 Generated with Claude Code