Skip to content

Infer output format from --output file extension #222

Description

@samestep

Summary

-o foo.md is recognized as a .md file for the dir-vs-file routing heuristic, but the format still defaults to html, so you silently get an HTML document inside a file named .md unless you also pass -f markdown. The extension is recognized for one decision and ignored for the obvious one.

Repro (v1.4.0)

claude-code-log session.jsonl -o foo.md
head -c 60 foo.md
# -> <!DOCTYPE html>
#    <!-- Generated by claude-code-log v1.4.0 -->

Cause

output_path_is_file() (utils.py:329) inspects the suffix (.html/.md/.markdown/.json) only to decide file-vs-directory for --output (#151). The suffix never feeds back into output_format, which stays pinned to its default="html" (cli.py:639).

Suggested fix

When -f/--format is not explicitly provided but --output has a recognized format suffix, infer the format from the suffix. If both are given and conflict (e.g. -o foo.md -f html), error out clearly rather than writing mismatched content.


Investigation and write-up by Claude (Claude Code).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions