Class: ClaudeAgentSDK::MaterializedResume

Inherits:
Object
  • Object
show all
Defined in:
lib/claude_agent_sdk/session_resume.rb

Overview

Result of SessionResume.materialize_resume_session.

config_dir is a temp directory laid out like ~/.claude/ — point the subprocess at it via CLAUDE_CONFIG_DIR. resume_session_id is passed as --resume. Call #cleanup after the subprocess exits to remove the temp dir.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_dir:, resume_session_id:) ⇒ MaterializedResume

Returns a new instance of MaterializedResume.



22
23
24
25
# File 'lib/claude_agent_sdk/session_resume.rb', line 22

def initialize(config_dir:, resume_session_id:)
  @config_dir = config_dir
  @resume_session_id = resume_session_id
end

Instance Attribute Details

#config_dirObject (readonly)

Returns the value of attribute config_dir.



20
21
22
# File 'lib/claude_agent_sdk/session_resume.rb', line 20

def config_dir
  @config_dir
end

#resume_session_idObject (readonly)

Returns the value of attribute resume_session_id.



20
21
22
# File 'lib/claude_agent_sdk/session_resume.rb', line 20

def resume_session_id
  @resume_session_id
end

Instance Method Details

#cleanupObject

Best-effort removal of the temp config dir (never raises).



28
29
30
# File 'lib/claude_agent_sdk/session_resume.rb', line 28

def cleanup
  SessionResume.rmtree_with_retry(@config_dir)
end

#preserve_transcriptsObject

Teardown when the transcript mirror dropped batches: the CLI's authoritative transcript lives in this temp dir, and the store copy is missing the dropped turns — deleting the dir would permanently lose them. Keep the transcripts (projects/), remove the redacted credential copies, and tell the user where the data is so they can import it into the store manually. Never raises.



38
39
40
41
42
43
44
45
46
47
# File 'lib/claude_agent_sdk/session_resume.rb', line 38

def preserve_transcripts
  ['.credentials.json', '.claude.json'].each do |name|
    FileUtils.rm_f(File.join(@config_dir, name))
  end
  warn "Claude SDK: transcript mirror dropped batches; the session store copy is incomplete. " \
       "Preserving the session transcript under #{File.join(@config_dir, 'projects')} instead of " \
       'deleting it — import it into your session store, then remove the directory.'
rescue StandardError => e
  warn "Claude SDK: failed to scrub preserved transcript dir #{@config_dir}: #{e.message}"
end