This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
go build- Build the spacectl binarymake lint- Run golangci-lint for code lintinggo test ./...- Run all testsgo run main.go- Run spacectl from source
go test ./internal/cmd/...- Run tests for command packagesgo test -v ./client/session/...- Run session tests with verbose output
CLI Framework: Built on github.com/urfave/cli/v3 with a modular command structure
GraphQL Client: Uses github.com/shurcooL/graphql (forked at github.com/spacelift-io/graphql) for API communication
Authentication System: Multi-method authentication supporting:
- Environment variables (API tokens, GitHub tokens, API keys)
- Profile-based credentials stored in
~/.spacelift/ - Session management in
client/session/
Command Versioning: Commands support multiple versions for compatibility between SaaS and Self-Hosted Spacelift instances using cmd.VersionedCommand
main.go- Entry point, command registration, instance version detectioninternal/cmd/- All CLI commands organized by functionalityclient/- GraphQL client and HTTP client managementclient/session/- Authentication and session handlinginternal/cmd/authenticated/- Shared authentication logic for commands
Commands are defined using cmd.Command with versioned implementations:
EarliestVersion: cmd.SupportedVersionAll- Works with any Spacelift versionEarliestVersion: cmd.SupportedVersionLatest- SaaS only, pending Self-Hosted releaseEarliestVersion: cmd.SupportedVersion("2.5.0")- Requires specific version or higher
The client automatically detects unauthorized errors and provides contextual messages:
- Distinguishes between "no access to resource" vs "need to re-login"
- Uses
spacectl profile loginfor authentication guidance
Includes Model Context Protocol server (mcp.Command()) for AI model interaction with Spacelift resources.
When working with this Go codebase, make liberal use of available MCP servers:
- mcp-gopls: Essential for spacectl Go development, providing:
- Navigate CLI Architecture: Use
GoToDefinitionandFindReferencesto trace command implementations frominternal/cmd/through to GraphQL client calls - Debug Authentication Flow: Search symbols like "session", "profile", "token" to understand the multi-method auth system in
client/session/ - Explore GraphQL Integration: Find implementers of GraphQL query structs and trace data flow from API responses to CLI output
- Maintain Code Quality:
GetDiagnosticscatches Go compilation errors,FormatCodeensures gofmt compliance,OrganizeImportsmanages the extensive import dependencies - Refactor Safely:
RenameSymbolfor renaming across the modular command structure without breaking CLI interface compatibility - Understand Command Versioning: Search for
VersionedCommandusage to see how commands support different Spacelift instance versions
- Navigate CLI Architecture: Use
- context7: Essential for accessing current documentation for spacectl's key dependencies:
- CLI Framework: Get latest
github.com/urfave/cli/v3patterns for command structure, flags, and subcommands used throughoutinternal/cmd/ - GraphQL Client: Access
github.com/shurcooL/graphql(forked asspacelift-io/graphql) documentation for query building and response handling - Terminal UI: Find examples for
github.com/charmbracelet/bubbletea,bubbles, andlipglossused in interactive features like local preview and worker pool management - Authentication Libraries: Get guidance on
golang.org/x/oauth2andgithub.com/golang-jwt/jwt/v4for the multi-method auth system - Utility Libraries: Access docs for
github.com/manifoldco/promptui(user prompts),github.com/pkg/browser(opening URLs),github.com/mholt/archiver/v3(file handling) - Testing Frameworks: Get current patterns for
github.com/stretchr/testifyandgithub.com/onsi/gomegaused in the test suite
- CLI Framework: Get latest
- spacectl: For working with Spacelift's GraphQL schema and API operations. Use this MCP server to:
- Introspect the GraphQL schema (
mcp__spacectl__introspect_graphql_schema) - Search for specific GraphQL fields and types (
mcp__spacectl__search_graphql_schema_fields) - Get detailed information about GraphQL types (
mcp__spacectl__get_graphql_type_details) - Get comprehensive authentication guidance (
mcp__spacectl__get_authentication_guide)
- Introspect the GraphQL schema (
These tools provide enhanced Go development capabilities including real-time code analysis, intelligent code completion, comprehensive documentation access, and direct Spacelift API interaction.