# What Programming Language Is CodexBar Written In? Swift 6 Architecture Explained

> Discover CodexBar! This Swift 6 application leverages the swift-tools-version 6.2 package and strict concurrency for robust performance. Learn about its architecture.

- Repository: [Peter Steinberger/CodexBar](https://github.com/steipete/CodexBar)
- Tags: architecture
- Published: 2026-07-10

---

**CodexBar is written entirely in Swift 6, utilizing the swift-tools-version 6.2 package format with strict concurrency checking enabled throughout the codebase.**

CodexBar is a native macOS menu-bar application designed for tracking OpenAI usage. If you're investigating what programming language CodexBar is written in, the repository demonstrates a pure **Swift** implementation targeting modern Swift 6 standards. The project structure, defined in [`Package.swift`](https://github.com/steipete/CodexBar/blob/main/Package.swift), confirms the exclusive use of Swift for both the core library and command-line interface.

## Swift 6 Package Configuration

The foundation of CodexBar's language choice is explicitly declared in the package manifest.

### Package.swift Swift Tools Version

In [`Package.swift`](https://github.com/steipete/CodexBar/blob/main/Package.swift), the header specifies swift-tools-version 6.2, establishing Swift 6 as the minimum required version for compilation. This declaration affects the entire build system and dependency resolution according to the repository's main branch.

### Strict Concurrency Model

The package enables Swift 6's strict concurrency checking through specific build settings in [`Package.swift`](https://github.com/steipete/CodexBar/blob/main/Package.swift) (lines 71-73). This enforcement ensures that all concurrent code paths are thread-safe by default, a hallmark of modern Swift development as implemented in the steipete/CodexBar repository.

## Core Swift Components

The repository organizes its Swift code into distinct targets, each serving specific architectural purposes.

### macOS App Implementation

[`Sources/CodexBar/StatusItemController.swift`](https://github.com/steipete/CodexBar/blob/main/Sources/CodexBar/StatusItemController.swift) contains the core implementation of the macOS status-item controller that drives the menu UI. This file uses AppKit frameworks interfaced through Swift, demonstrating how CodexBar integrates with macOS system APIs using native Swift syntax.

### Data Persistence Layer

[`Sources/CodexBar/UsageStore.swift`](https://github.com/steipete/CodexBar/blob/main/Sources/CodexBar/UsageStore.swift) handles persistent tracking of token usage across providers. The implementation uses Swift's concurrency features including async/await patterns for asynchronous operations.

### CLI Target

[`Sources/CodexBarCLI/main.swift`](https://github.com/steipete/CodexBar/blob/main/Sources/CodexBarCLI/main.swift) serves as the entry point for the command-line interface, built using Swift package manager targets and the Commander framework for argument parsing.

### Test Suite

The project includes comprehensive Swift testing in [`Tests/CodexBarTests/UsageStoreTests.swift`](https://github.com/steipete/CodexBar/blob/main/Tests/CodexBarTests/UsageStoreTests.swift), utilizing the XCTest framework native to Swift to verify the usage-tracking logic.

## Practical Swift Code Examples

The following examples demonstrate Swift syntax and patterns used throughout CodexBar.

### CLI Command Implementation

This example from the CLI target shows Swift argument parsing and command registration:

```swift
import CodexBarCLI
import Commander

// Define a "hello" command that prints a greeting.
let hello = command(
    Argument<String>("name", description: "Your name")
) { name in
    print("Hello, \(name)! Welcome to Codex Bar.")
}

// Register the command and run the CLI.
let cli = CLI()
cli.add(command: hello, name: "hello", description: "Greet the user")
cli.run()

```

### Status Item Controller

The menu bar functionality relies on AppKit integration through Swift:

```swift
import CodexBarCore
import AppKit

// Minimal status-item controller showing a static menu.
class SimpleStatusItem {
    private let statusItem = NSStatusBar.system
        .statusItem(withLength: NSStatusItem.squareLength)

    init() {
        statusItem.button?.title = "🪄"
        let menu = NSMenu()
        menu.addItem(withTitle: "About Codex Bar", action: #selector(showAbout), keyEquivalent: "")
        statusItem.menu = menu
    }

    @objc private func showAbout() {
        let alert = NSAlert()
        alert.messageText = "Codex Bar"
        alert.informativeText = "A Swift-based menu-bar utility for OpenAI usage tracking."
        alert.runModal()
    }
}

```

### Async Usage Store Operations

The `UsageStore` leverages Swift's modern concurrency features:

```swift
import CodexBarCore

Task {
    do {
        // Load the persistent usage store.
        let store = try await UsageStore.shared.load()
        // Retrieve the current month's token count.
        let tokens = try await store.currentMonthTokenCount()
        print("Tokens used this month: \(tokens)")
    } catch {
        print("Failed to read usage: \(error)")
    }
}

```

## Summary

- **CodexBar is written entirely in Swift 6**, requiring swift-tools-version 6.2 or later according to the [`Package.swift`](https://github.com/steipete/CodexBar/blob/main/Package.swift) manifest.
- The codebase implements **Swift 6 strict concurrency** checking to ensure thread-safe operations across the application.
- All components—including the macOS UI in [`StatusItemController.swift`](https://github.com/steipete/CodexBar/blob/main/StatusItemController.swift), the persistence layer in [`UsageStore.swift`](https://github.com/steipete/CodexBar/blob/main/UsageStore.swift), and the CLI in [`main.swift`](https://github.com/steipete/CodexBar/blob/main/main.swift)—use native Swift syntax and frameworks.
- Testing is implemented using **XCTest** in [`Tests/CodexBarTests/UsageStoreTests.swift`](https://github.com/steipete/CodexBar/blob/main/Tests/CodexBarTests/UsageStoreTests.swift), maintaining the Swift-only architecture.

## Frequently Asked Questions

### Is CodexBar written in Swift or Objective-C?

CodexBar is written entirely in **Swift**, with no Objective-C components. The repository uses Swift 6 features exclusively, including modern concurrency patterns and strict type safety, as evidenced by the [`Package.swift`](https://github.com/steipete/CodexBar/blob/main/Package.swift) configuration and the absence of any `.m` or `.h` files in the source tree.

### What version of Swift does CodexBar require?

CodexBar requires **Swift 6.2** or later, as specified by the `swift-tools-version:6.2` declaration in [`Package.swift`](https://github.com/steipete/CodexBar/blob/main/Package.swift) (lines 1-34). This version requirement ensures access to the latest concurrency checking and language features introduced in Swift 6.

### Does CodexBar use SwiftUI or AppKit for its user interface?

CodexBar uses **AppKit** for its macOS menu-bar interface. The [`StatusItemController.swift`](https://github.com/steipete/CodexBar/blob/main/StatusItemController.swift) file implements `NSStatusBar` and `NSMenu` components rather than SwiftUI views, which is typical for macOS menu-bar utilities that require system tray integration and status item management.

### Can I contribute to CodexBar if I know Swift?

Yes, contributors familiar with **Swift 6** and macOS development can contribute to CodexBar. The codebase follows standard Swift package manager conventions, uses XCTest for testing, and implements modern Swift concurrency patterns, making it accessible to developers experienced with Swift's ecosystem.