Add Cost Reporting Feature to Claude Code CLI in Non-Interactive Mode

Resolved 💬 3 comments Opened Mar 14, 2025 by swellmkt Closed Mar 17, 2025

Background

Claude Code currently provides cost tracking through the /cost command, but this is only available in interactive mode. When running Claude Code in non-interactive mode (e.g., for scripting or automation), there's no way to access cost information after task completion.

Feature Request

Extend the existing cost reporting functionality to non-interactive mode, allowing users to see cost metrics when running one-off commands.

Proposed Implementation

Add a flag (e.g., --report-cost or -c) to display cost information upon task completion in non-interactive mode:

claude -p "implement task1.md" --report-cost

Alternatively, implement an environment variable or config setting to enable this reporting by default.

Example Output

After completing a task in non-interactive mode, Claude Code would output something like:

✅ Task completed successfully
📊 Cost information:
   - Input tokens: 1,245
   - Output tokens: 3,782
   - Total cost: $0.076

Use Cases

  • CI/CD pipelines where Claude Code is used for automated tasks
  • Batch processing scripts where costs need to be tracked
  • DevOps workflows that need to allocate costs to different projects
  • Automation scripts where users want to monitor spending without manual intervention

Related Features

This builds upon the existing /cost command in interactive mode, providing similar functionality for non-interactive use cases.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗