This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
The Rootly CLI is a command-line interface for interacting with rootly.com, primarily focused on sending "pulses" (deployment notifications and tracking events) from the command line, CI environments, or shell scripts. It's written in Go and uses the Cobra framework for command structure.
# Install dependencies
go get all
# Build the binary (outputs to ./bin/rootly)
make build
# Run tests
make test
# Run linters (requires golangci-lint, hadolint, goreleaser)
make lint
# Clean build artifacts
make clean# Run tests for a specific package
go test -count=1 -v ./pkg/api/...
go test -count=1 -v ./pkg/commands/...
go test -count=1 -v ./pkg/inputs/...# Build Docker image
make docker-build
# Push Docker image
make docker-pushThe project uses semantic versioning with automated version bumping:
# Show current and next versions
make version-show
# Bump versions (updates root.go, commits, creates tag, and pushes)
make release-patch # 1.2.10 → 1.2.11 (for bug fixes)
make release-minor # 1.2.10 → 1.3.0 (for new features)
make release-major # 1.2.10 → 2.0.0 (for breaking changes)
# Or use individual steps
make version-patch # Just bump and tag patch version
make version-minor # Just bump and tag minor version
make version-major # Just bump and tag major version
# Preview next version without making changes
make version-next
# Legacy manual release (requires VERSION variable)
make release VERSION="v1.0.0"Note: Version bumping requires a clean git working directory. The script will:
- Update version in
pkg/commands/root.go - Commit the change
- Create and push a git tag
- Trigger GitHub Actions to build and publish the release
- cmd/rootly/ - Main entry point; initializes logging and executes root command
- pkg/commands/ - Cobra command definitions (
pulse,pulse-run, root command) - pkg/api/ - HTTP client logic for Rootly API, request building, and response parsing
- pkg/inputs/ - Input handling across three layers:
flags/- Cobra flag definitionsenv/- Environment variable parsingparse/- String parsing utilities (arrays, key-value pairs)- Main package unifies flag + env variable retrieval
- pkg/models/ - Data structures for pulses and API responses
- pkg/log/ - Custom logging with context-aware error handling
The CLI uses a unified input system that prioritizes flags over environment variables:
- Flag Layer (
pkg/inputs/flags/): Defines all Cobra flags - Environment Layer (
pkg/inputs/env/): Provides fallback viaROOTLY_*env vars - Input Getter (
pkg/inputs/get.go): Unified retrieval that checks flags first, then env vars - Parsing Layer (
pkg/inputs/parse/): Converts strings to structured data (arrays, maps)
Key pattern: inputs.GetString(names.ApiKeyName, cmd, required) checks flag --api-key, then falls back to ROOTLY_API_KEY.
rootly pulse (pkg/commands/pulse.go)
- Sends a pulse with provided metadata
- Summary is required (taken from positional arguments or
ROOTLY_SUMMARY) - Collects metadata: labels (key=value pairs), services, environments, source, refs
- Timestamps:
StartedAtcaptured at command start,EndedAtwhen pulse is sent
rootly pulse-run (pkg/commands/pulse_run.go)
- Wraps a shell command execution
- Automatically adds
exit_statuslabel with the command's exit code - If no summary provided, uses the command itself as summary
- Flow: Parse inputs → Run command → Add exit code to labels → Send pulse
- Uses generated client from
rootlyhq/rootly-gopackage - Manual request construction in
pkg/api/request.gousingoapi-codegen - Authentication via Bearer token (API key)
- Validates service/environment IDs in response and reports missing ones
Labels and refs use format key=value, key2=value2 (comma-separated, no spaces around =).
Parser (pkg/inputs/convert.go):
- Splits on commas, then on
= - Converts keys to lowercase and replaces spaces with underscores
- Validates format (exactly one
=per item, non-empty values)
Critical fix context: Recent fix addressed panic in key-value parsing for refs and labels when format was invalid (see commit 2c38ee2).
Current version is maintained in pkg/commands/root.go:34 and managed through git tags.
The scripts/bump-version.sh script automates version management:
- Reads current version from latest git tag
- Calculates next version based on semver (patch/minor/major)
- Updates
pkg/commands/root.gowith new version - Commits the change with message "Update version to vX.Y.Z"
- Creates annotated git tag (vX.Y.Z)
- Pushes commit and tag to origin
Use Makefile targets for version management:
make version-show- Display current and next versionsmake release-patch- Bump patch (bug fixes)make release-minor- Bump minor (new features)make release-major- Bump major (breaking changes)
The CLI checks for updates on --version flag using the gleich/release package.
GitHub Actions workflows (.github/workflows/):
build.yml- Build verificationlint.yml- Linting checkstest.yml- Test executionrelease.yml- Automated releases via GoReleaser
All flags support environment variables: replace hyphens with underscores, uppercase, and prefix with ROOTLY_.
- Tests use
testifyassertions - Example test locations:
- API conversion tests:
pkg/api/convert_test.go - Request tests:
pkg/api/request_test.go - Parsing tests:
pkg/inputs/parse/array_test.go - Logging tests:
pkg/log/format_test.go
- API conversion tests: