๊ฐ€์ž… ํ›„ ์ดˆ๋Œ€ ๋งํฌ๋ฅผ ๊ณต์œ ํ•˜๋ฉด ๋™์˜์ƒ ์žฌ์ƒ ๋ฐ ์ดˆ๋Œ€ ๋ณด์ƒ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture ๆŠ•็จฟใฏๅ€‹ไบบใฎๆ„่ฆ‹ใงใ™ใ€‚
๊ฐ€์ž… May 2026
258 ํŒ”๋กœ์ž‰ ์ค‘    227 ํŒฌ
# Useful but Little-Known Features of Claude Agent SDK ๐ŸŒ Let AI modify your files with confidence -- you can always roll back. File checkpointing automatically tracks changes made by Write/Edit/NotebookEdit and lets you rewind to any point in time. ๐Ÿ“Œ Title: File Checkpointing and Rollback ๐Ÿ”— URL: ๐Ÿงฉ Overview File checkpointing tracks file modifications during agent sessions. When you set enable_file_checkpointing=True, the SDK creates backups before any Write, Edit, or NotebookEdit tool modifies a file. Each UserMessage's UUID serves as a checkpoint, and you can call rewind_files() with that UUID to restore files to that point. Created files get deleted, and modified files are restored to their original content. ๐Ÿ›  How to Use ```python import asyncio from claude_agent_sdk import ( ClaudeSDKClient, ClaudeAgentOptions, UserMessage, ResultMessage, ) async def main(): # Step 1: Enable checkpointing options = ClaudeAgentOptions( enable_file_checkpointing=True, permission_mode="acceptEdits", extra_args={"replay-user-messages": None}, # Required for UUIDs ) checkpoint_id = None session_id = None async with ClaudeSDKClient(options) as client: await client.query("Refactor the authentication module") # Step 2: Capture checkpoint UUID from UserMessage async for message in client.receive_response(): if isinstance(message, UserMessage) and message.uuid and not checkpoint_id: checkpoint_id = message.uuid if isinstance(message, ResultMessage) and not session_id: session_id = message.session_id # Step 3: Resume session and rollback if checkpoint_id and session_id: async with ClaudeSDKClient( ClaudeAgentOptions( enable_file_checkpointing=True, resume=session_id ) ) as client: await client.query("") # Empty prompt to open connection async for message in client.receive_response(): await client.rewind_files(checkpoint_id) break print(f"Rewound to checkpoint: {checkpoint_id}") ``` ๐Ÿ— Integration into Production Systems - extra_args={"replay-user-messages": None} is required; without it, UUIDs won't appear in the stream - To rollback, resume the session, send an empty prompt, then call rewind_files() - Persist checkpoint UUIDs and session IDs to enable rollback after process restarts - Combine with permission_mode="acceptEdits" to auto-approve file changes while maintaining rollback safety ๐Ÿ’ก Use Cases ๐Ÿ”ง Safe refactoring: try changes and instantly rollback if issues arise ๐Ÿงช Experimental code generation: validate AI output and revert if quality is low ๐Ÿ“ Auto-generated documentation: review results and undo unwanted changes โš ๏ธ Caveats - Changes via Bash commands (echo > file.txt, sed -i, etc.) are NOT tracked - Only file content is tracked; directory creation/move/deletion is not undone - Conversation history is not rolled back -- only files are restored - Checkpoints are tied to the session that created them โœจ Develop fearlessly with "undo-able" AI -- let the agent code with confidence! #ClaudeAgentSDK# #AIAgent#
๋” ๋ณด๊ธฐ