Skip to content

feat: add /project-costs Claude command and make target - #35

Merged
andre-salvati merged 2 commits into
mainfrom
feat/project-costs-command
Jun 8, 2026
Merged

feat: add /project-costs Claude command and make target#35
andre-salvati merged 2 commits into
mainfrom
feat/project-costs-command

Conversation

@andre-salvati

@andre-salvati andre-salvati commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds `scripts/project_costs.py` — queries AWS Cost Explorer (daily, last 30 days) and Databricks `system.billing.usage` via the SDK, printing two formatted tables
  • Adds `make project-costs` Makefile target as a quick runner
  • Adds `.claude/commands/project-costs.md` — `/project-costs` slash command that fetches the data then has Claude analyze it for anomalies, spikes, period comparisons, and cross-cloud correlation (S3/egress vs DBU spend)
  • Updates `.gitignore` to track `.claude/commands/` so project-level slash commands are shared with the team while personal settings/hooks remain local
  • Hardens `project_costs.py` against credential leakage and runtime failures: catches `FileNotFoundError` when AWS CLI is absent, adds `StatementState.CLOSED` to poll-exit set, guards `stmt.status.error` before `.message` on CANCELED, wraps `json.loads` against pager output, replaces raw AWS stderr (which can contain caller ARNs) with a sanitized message, prints `type(e).name` instead of full SDK exceptions (which can embed the workspace URL), and validates `--days >= 1`

Test plan

  • `make project-costs` prints both tables (AWS daily + Databricks DBU by SKU)
  • `/project-costs` in Claude Code runs the script and produces a written analysis with anomaly/spike/trend commentary
  • AWS session expired → script prints sanitized error and continues to Databricks section
  • Databricks free-tier workspace → script prints fallback message instead of crashing
  • Code review findings addressed (credential leakage, infinite poll loop, null deref on cancel, JSON decode crash, negative --days)

🤖 Generated with Claude Code

andre-salvati and others added 2 commits June 8, 2026 10:42
Adds a cost-visibility tool with two parts:
- `scripts/project_costs.py`: queries AWS Cost Explorer (daily, last 30 days) and Databricks `system.billing.usage` (via SDK), printing two formatted tables.
- `make project-costs`: thin Makefile target that runs the script.
- `.claude/commands/project-costs.md`: slash command that runs the script then has Claude analyze the output for anomalies, spikes, period comparisons, and cross-cloud correlation.
- `.gitignore`: tracks `.claude/commands/` so project-level slash commands are shared with the team; personal settings/hooks remain gitignored.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…akage

- Catch FileNotFoundError when AWS CLI is not on PATH (previously crashed
  before Databricks table printed)
- Add StatementState.CLOSED to poll-exit set to prevent infinite loop when
  a warehouse closes a statement
- Guard stmt.status.error before accessing .message (was None on CANCELED)
- Wrap json.loads in try/except JSONDecodeError for AWS pager/helper output
- Stop echoing raw AWS CLI stderr — AccessDeniedException messages include
  caller ARNs with the AWS account ID; print a sanitized message instead
- Print type(e).__name__ instead of the full exception on WorkspaceClient
  init failure — SDK exceptions can embed the workspace URL
- Validate --days >= 1 to prevent inverted AWS date range and negative SQL INTERVAL

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@andre-salvati
andre-salvati merged commit b2363b2 into main Jun 8, 2026
1 check passed
andre-salvati added a commit that referenced this pull request Jun 10, 2026
- Add #35 (project-costs command + make target), which was merged but never
  given a CHANGELOG entry.
- Correct the entry labeled #30 to #31: PR #30 was closed and superseded by #31
  (same title), which is the one actually merged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant