How to Integrate CodexBar into an Android Application: A Complete Guide

CodexBar is a macOS-only Swift utility, but you can integrate it into Android apps by running its CLI HTTP server on a macOS host and querying the JSON endpoint from Android using standard HTTP clients like OkHttp.

CodexBar, developed by steipete, is a menu-bar application designed exclusively for macOS that monitors AI coding assistant usage. Since no native Android library exists, integrating CodexBar into an Android application requires an architectural bridge: exposing the tool's data via its built-in HTTP server or command-line interface, then consuming that data remotely from your Android client.

Understanding the Integration Architecture

Because CodexBar is written in Swift and relies on macOS-specific APIs, it cannot run directly on Android devices. The solution leverages the CodexBar CLI and its optional local HTTP server to expose usage data across the network.

The core components that enable this integration reside in the following source files:

Setting Up the CodexBar HTTP Server on macOS

To make CodexBar data accessible to Android, you must first launch the HTTP server on your macOS host. This server exposes a JSON endpoint containing real-time usage statistics.

Start the server by executing the serve command:

codexbar serve --port 9090

The CLIServeCommand.swift file implements this command, which initializes the server defined in CLILocalHTTPServer.swift. Once running, the server listens on http://localhost:9090/status and returns a JSON payload structured like this:

{
  "provider": "Claude",
  "usage": {
    "usedTokens": 12345,
    "totalTokens": 200000
  },
  "plan": "Pro",
  "timestamp": "2026-07-10T12:34:56Z"
}

Replace localhost with the macOS host's IP address when configuring your Android client, ensuring both devices are on the same network or that the port is properly forwarded.

Querying CodexBar from Android

Once the HTTP server is running on macOS, your Android application can fetch usage data using standard HTTP libraries.

Using OkHttp to Fetch Status Data

Add the OkHttp dependency to your build.gradle file:

implementation("com.squareup.okhttp3:okhttp:4.12.0")

Then implement a function to query the endpoint and parse the JSON response:

import okhttp3.OkHttpClient
import okhttp3.Request
import org.json.JSONObject

val client = OkHttpClient()

fun fetchCodexBarStatus(): JSONObject? {
    val request = Request.Builder()
        .url("http://<MAC_HOST_IP>:9090/status") // Replace with your macOS host IP
        .build()

    client.newCall(request).execute().use { response ->
        if (!response.isSuccessful) return null
        val body = response.body?.string() ?: return null
        return JSONObject(body)
    }
}

// Example usage in a ViewModel
val status = fetchCodexBarStatus()
status?.let {
    val used = it.getJSONObject("usage").getInt("usedTokens")
    val total = it.getJSONObject("usage").getInt("totalTokens")
    // Update UI with usage statistics
}

Alternative CLI Integration via SSH

If network restrictions prevent HTTP access, you can execute the CodexBar CLI remotely via SSH and capture the output. The CLIEntry.swift file implements the status sub-command, which prints the same JSON that the HTTP server serves.

import java.io.BufferedReader
import java.io.InputStreamReader

fun sshFetchCodexBar(): String? {
    val process = ProcessBuilder(
        "ssh", "user@mac-host", "codexbar status"
    ).redirectErrorStream(true).start()

    BufferedReader(InputStreamReader(process.inputStream)).use { reader ->
        return reader.readText()
    }
}

This approach requires the Android device to have SSH access to the macOS host, making it suitable for development environments or devices on VPNs.

Configuring Provider Settings

The data exposed by CodexBar depends on the active provider configuration managed in Sources/CodexBarCore/Providers/ProviderCLIConfig.swift. This file determines whether the server reports Claude, Codex, or other provider statistics.

Ensure your macOS host has the correct provider selected before starting the server:

codexbar config --provider Claude

The HTTP server will then serve quota and usage data specific to that provider's API limits.

Building the CLI from Source

If you need to modify the HTTP server behavior or add custom endpoints, you can rebuild the CLI using the Swift Package Manager manifest defined in Package.swift:

git clone https://github.com/steipete/CodexBar.git
cd CodexBar
swift build -c release

The compiled binary will be available in .build/release/, allowing you to deploy a customized version of the server for your Android integration.

Summary

  • CodexBar is macOS-only, requiring an HTTP server bridge to serve data to Android.
  • Run codexbar serve (implemented in CLIServeCommand.swift and CLILocalHTTPServer.swift) to expose a JSON endpoint on your macOS host.
  • Query the endpoint from Android using OkHttp or Retrofit, parsing the usage, provider, and plan fields.
  • Configure the provider in ProviderCLIConfig.swift to ensure the correct API quotas are monitored.
  • Use SSH as a fallback when direct HTTP connections are unavailable, invoking codexbar status from CLIEntry.swift.

Frequently Asked Questions

Can CodexBar run natively on Android?

No. CodexBar is written in Swift and relies on macOS-specific APIs for menu-bar integration. Android apps must interact with CodexBar remotely via its HTTP server or CLI interface running on a macOS host.

What data does the CodexBar HTTP endpoint return?

The endpoint returns a JSON object containing the active provider name (e.g., "Claude"), usage statistics including usedTokens and totalTokens, the subscription plan type, and a timestamp. This structure is generated by the server logic in CLILocalHTTPServer.swift.

Is the HTTP server secure for production use?

The CodexBar HTTP server (CLILocalHTTPServer.swift) is designed for local development and assumes a trusted network environment. For production use, implement additional security layers such as VPN tunneling, SSH port forwarding, or reverse proxy authentication to protect the endpoint from unauthorized access.

How do I handle network security between Android and macOS?

Place both devices on the same private network or use a VPN to ensure the macOS host is reachable from Android. Avoid exposing the CodexBar HTTP port (default 9090) directly to the public internet without additional authentication mechanisms, as the server does not implement built-in authorization checks.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →