88import shutil
99import subprocess
1010import tempfile
11+ import webbrowser
1112from pathlib import Path
1213
1314import click
@@ -931,7 +932,7 @@ def cli():
931932 "-o" ,
932933 "--output" ,
933934 type = click .Path (),
934- help = "Output directory (default: current directory, or temp dir with --gist)" ,
935+ help = "Output directory (default: current directory, or temp dir with --gist/--open )" ,
935936)
936937@click .option (
937938 "--repo" ,
@@ -948,10 +949,16 @@ def cli():
948949 is_flag = True ,
949950 help = "Include the original JSON session file in the output directory." ,
950951)
951- def session (json_file , output , repo , gist , include_json ):
952+ @click .option (
953+ "--open" ,
954+ "open_browser" ,
955+ is_flag = True ,
956+ help = "Open the generated index.html in your default browser." ,
957+ )
958+ def session (json_file , output , repo , gist , include_json , open_browser ):
952959 """Convert a Claude Code session JSON file to HTML."""
953960 # Determine output directory
954- if gist and output is None :
961+ if ( gist or open_browser ) and output is None :
955962 # Extract session ID from JSON file for temp directory name
956963 with open (json_file , "r" ) as f :
957964 data = json .load (f )
@@ -982,6 +989,10 @@ def session(json_file, output, repo, gist, include_json):
982989 click .echo (f"Preview: { preview_url } " )
983990 click .echo (f"Files: { output } " )
984991
992+ if open_browser :
993+ index_url = (output / "index.html" ).resolve ().as_uri ()
994+ webbrowser .open (index_url )
995+
985996
986997def resolve_credentials (token , org_uuid ):
987998 """Resolve token and org_uuid from arguments or auto-detect.
@@ -1256,7 +1267,7 @@ def generate_html_from_session_data(session_data, output_dir, github_repo=None):
12561267 "-o" ,
12571268 "--output" ,
12581269 type = click .Path (),
1259- help = "Output directory (default: creates folder with session ID, or temp dir with --gist)" ,
1270+ help = "Output directory (default: creates folder with session ID, or temp dir with --gist/--open )" ,
12601271)
12611272@click .option ("--token" , help = "API access token (auto-detected from keychain on macOS)" )
12621273@click .option (
@@ -1277,7 +1288,15 @@ def generate_html_from_session_data(session_data, output_dir, github_repo=None):
12771288 is_flag = True ,
12781289 help = "Include the JSON session data in the output directory." ,
12791290)
1280- def import_session (session_id , output , token , org_uuid , repo , gist , include_json ):
1291+ @click .option (
1292+ "--open" ,
1293+ "open_browser" ,
1294+ is_flag = True ,
1295+ help = "Open the generated index.html in your default browser." ,
1296+ )
1297+ def import_session (
1298+ session_id , output , token , org_uuid , repo , gist , include_json , open_browser
1299+ ):
12811300 """Import a session from the Claude API and convert to HTML.
12821301
12831302 If SESSION_ID is not provided, displays an interactive picker to select a session.
@@ -1337,7 +1356,7 @@ def import_session(session_id, output, token, org_uuid, repo, gist, include_json
13371356 raise click .ClickException (f"Network error: { e } " )
13381357
13391358 # Determine output directory
1340- if gist and output is None :
1359+ if ( gist or open_browser ) and output is None :
13411360 output = Path (tempfile .gettempdir ()) / session_id
13421361 elif output is None :
13431362 output = session_id
@@ -1364,8 +1383,10 @@ def import_session(session_id, output, token, org_uuid, repo, gist, include_json
13641383 click .echo (f"Gist: { gist_url } " )
13651384 click .echo (f"Preview: { preview_url } " )
13661385 click .echo (f"Files: { output } " )
1367- else :
1368- click .echo (f"Done! Open { output } /index.html to view." )
1386+
1387+ if open_browser :
1388+ index_url = (output / "index.html" ).resolve ().as_uri ()
1389+ webbrowser .open (index_url )
13691390
13701391
13711392def main ():
0 commit comments