A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
feat: show Codex plan usage and reset credits in the notch
Mahbod Tajdinifff96499ca04
diff --git a/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj b/NotchBuddy/NotchBuddy.xcodeproj/project.pbxprojindex 2d2950ec..5cad0ce3 100644--- a/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj+++ b/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj@@ -68,6 +68,7 @@94A742758D0FF79124E26B21 /* MochiWardrobe.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0BB15BD82E4A0B729045880 /* MochiWardrobe.swift */; };94E0849D13762C6EC8548FEF /* ClaudePlanCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4263B550838CC5614569D13 /* ClaudePlanCardView.swift */; };967B525F7D3837F31D740D18 /* ResendPoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61B5FDDE03F5F711146937E2 /* ResendPoller.swift */; };+ 9AD370335A3ECC9C82375F93 /* CodexPlanGauge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73FA4DF1BE5246CCFFB72E5C /* CodexPlanGauge.swift */; };9C653B8291EFFA414565E8A8 /* MusicController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F142FB3952B5F0639383047 /* MusicController.swift */; };9DD56C95ECABDDCE23652D50 /* HookServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79D8DD79C3DD9BBC584B3CB2 /* HookServer.swift */; };B2D86BE268D6F4C86BD0C446 /* ChatMarkdown.swift in Sources */ = {isa = PBXBuildFile; fileRef = D797CC384B5BC70D34F121BC /* ChatMarkdown.swift */; };@@ -99,6 +100,7 @@E81575CE4433C6F88E424A8F /* LocalChat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8790ACE9F73BD74640A0F20C /* LocalChat.swift */; };E85D8AC2617F7742C2547E11 /* MochiOutfitDrawing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34C2BC327511DB0B86D4D62E /* MochiOutfitDrawing.swift */; };E9C21D11BCB72C392436D19E /* ClaudePlanGauge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BF22817EC70748F2D1FB2E7 /* ClaudePlanGauge.swift */; };+ EB1D9680D3DB0F0707D4A043 /* CodexPlanGauge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73FA4DF1BE5246CCFFB72E5C /* CodexPlanGauge.swift */; };EB23ED9F1C12EA8B54A76A91 /* ResendPoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61B5FDDE03F5F711146937E2 /* ResendPoller.swift */; };ECECA2F225E82B7C951658D7 /* UploadSequenceEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FD65943C32E150F1CD65C31 /* UploadSequenceEngine.swift */; };ED5D9A334DE08C0EB81DE322 /* AskQuestion.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBB84A66045EB20CAC93A8A6 /* AskQuestion.swift */; };@@ -128,6 +130,7 @@62CF42AE7611EF212CA0458F /* ShortcutsSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutsSettingsView.swift; sourceTree = "<group>"; };6FD65943C32E150F1CD65C31 /* UploadSequenceEngine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadSequenceEngine.swift; sourceTree = "<group>"; };71718D1B87A39A4879DD2A9D /* VercelPoller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VercelPoller.swift; sourceTree = "<group>"; };+ 73FA4DF1BE5246CCFFB72E5C /* CodexPlanGauge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodexPlanGauge.swift; sourceTree = "<group>"; };78BC1357785CA1B099A33969 /* IslandScreenGeometry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IslandScreenGeometry.swift; sourceTree = "<group>"; };79D8DD79C3DD9BBC584B3CB2 /* HookServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HookServer.swift; sourceTree = "<group>"; };7C1A7D5CBE2AC084A10C5FF3 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };@@ -180,6 +183,7 @@F4263B550838CC5614569D13 /* ClaudePlanCardView.swift */,8BF22817EC70748F2D1FB2E7 /* ClaudePlanGauge.swift */,A83D5410BD030B243ADDCFF4 /* ClaudeService.swift */,+ 73FA4DF1BE5246CCFFB72E5C /* CodexPlanGauge.swift */,B1DDC96E7967032F5D0BD585 /* DesktopMochi.swift */,C086E1932F86B9C2B559BE03 /* DesktopMochiLogic.swift */,3DB24C2469551040FBAA4DBF /* DiffEngine.swift */,@@ -370,6 +374,7 @@94E0849D13762C6EC8548FEF /* ClaudePlanCardView.swift in Sources */,D861479F6E7EAD07A6AC2105 /* ClaudePlanGauge.swift in Sources */,2DEB459FBD0BA3CEAAA5FDE9 /* ClaudeService.swift in Sources */,+ 9AD370335A3ECC9C82375F93 /* CodexPlanGauge.swift in Sources */,BEC5DDB55B3DA67C61CA8470 /* DesktopMochi.swift in Sources */,BA65FC4A40F7227837C26214 /* DesktopMochiLogic.swift in Sources */,6697436AA05A3F92C1DD85C3 /* DiffEngine.swift in Sources */,@@ -425,6 +430,7 @@18D47AE663EB96BE5638D5F7 /* ClaudePlanCardView.swift in Sources */,E9C21D11BCB72C392436D19E /* ClaudePlanGauge.swift in Sources */,0329E76BA4A8FEEA8A6D76E7 /* ClaudeService.swift in Sources */,+ EB1D9680D3DB0F0707D4A043 /* CodexPlanGauge.swift in Sources */,273FC0FA14AAF6CE62FD14AE /* DesktopMochi.swift in Sources */,C93BA975D35B8CD7473CF995 /* DesktopMochiLogic.swift in Sources */,C1A29371181553FB4169E195 /* DiffEngine.swift in Sources */,diff --git a/NotchBuddy/Sources/App/AppState.swift b/NotchBuddy/Sources/App/AppState.swiftindex 4a1047e9..bd47550f 100644--- a/NotchBuddy/Sources/App/AppState.swift+++ b/NotchBuddy/Sources/App/AppState.swift@@ -393,6 +393,21 @@ final class AppState: ObservableObject {// Transient — reset when island closes or view changes@Published var showingPlanDetail: Bool = false+ // Codex plan gauge (from `codex app-server`) — fetched when the pill shows+ @Published var showCodexPlanInNotch: Bool = false {+ didSet { UserDefaults.standard.set(showCodexPlanInNotch, forKey: "showCodexPlanInNotch") }+ }+ @Published var codexPlanUsage: CodexPlanUsage? = nil+ // Which card showingPlanDetail opens+ @Published var planDetailIsCodex: Bool = false++ func refreshCodexPlanUsage() {+ if let u = codexPlanUsage, Date().timeIntervalSince(u.updatedAt) < 60 { return }+ Task {+ if let u = await CodexPlanGauge.fetch() { codexPlanUsage = u }+ }+ }+func refreshPlanRelayState() {planRelayInstalled = HookServer.statusLineInstalled()}@@ -438,6 +453,7 @@ final class AppState: ObservableObject {let u = try? JSONDecoder().decode(PlanUsage.self, from: d) { claudePlanUsage = u }#if !APPSTOREif let v = ud.object(forKey: "showPlanInNotch") as? Bool { showPlanInNotch = v }+ if let v = ud.object(forKey: "showCodexPlanInNotch") as? Bool { showCodexPlanInNotch = v }planRelayInstalled = HookServer.statusLineInstalled()#endifdiff --git a/NotchBuddy/Sources/App/BotCanvasView.swift b/NotchBuddy/Sources/App/BotCanvasView.swiftindex 38f5598e..0db21068 100644--- a/NotchBuddy/Sources/App/BotCanvasView.swift+++ b/NotchBuddy/Sources/App/BotCanvasView.swift@@ -33,7 +33,9 @@ struct BotCanvasView: View {// Claude Code tasks use state-based gradient (working=blue, thinking=purple, etc.).#if !APPSTOREif state.showingPlanDetail {- let hex = ClaudePlanGauge.color(for: state.claudePlanUsage.flatMap { ClaudePlanGauge.dominantPct($0) })+ let hex = state.planDetailIsCodex+ ? CodexPlanGauge.color(state.codexPlanUsage)+ : ClaudePlanGauge.color(for: state.claudePlanUsage.flatMap { ClaudePlanGauge.dominantPct($0) })engine.bodyColor = cgColorFromHex(hex)} else {engine.bodyColor = (state.focusTask?.isIntegration == true)diff --git a/NotchBuddy/Sources/App/ClaudePlanCardView.swift b/NotchBuddy/Sources/App/ClaudePlanCardView.swiftindex e17bbce4..c2be2c46 100644--- a/NotchBuddy/Sources/App/ClaudePlanCardView.swift+++ b/NotchBuddy/Sources/App/ClaudePlanCardView.swift@@ -67,7 +67,7 @@ private let weeklyResetFormatter: DateFormatter = {return fmt}()-private struct GaugeRowView: View {+struct GaugeRowView: View {let label: Stringlet window: PlanWindow?let now: Datediff --git a/NotchBuddy/Sources/App/CodexPlanGauge.swift b/NotchBuddy/Sources/App/CodexPlanGauge.swiftnew file mode 100644index 00000000..399393c0--- /dev/null+++ b/NotchBuddy/Sources/App/CodexPlanGauge.swift@@ -0,0 +1,202 @@+#if !APPSTORE+import SwiftUI++// MARK: - Codex plan usage++struct CodexPlanUsage {+ var fiveHour: PlanWindow?+ var sevenDay: PlanWindow?+ var resetCredits: Int? // free full resets available+ var resetCreditExpiresAt: Date? // soonest expiry among them+ var planType: String?+ var updatedAt: Date++ var planUsage: PlanUsage { PlanUsage(fiveHour: fiveHour, sevenDay: sevenDay, updatedAt: updatedAt) }+}++// MARK: - Fetching (codex app-server, the source behind Codex's /status)++enum CodexPlanGauge {++ static func codexExecutable() -> String? {+ let home = FileManager.default.homeDirectoryForCurrentUser.path+ let candidates = [+ "\(home)/.local/bin/codex",+ "/opt/homebrew/bin/codex",+ "/usr/local/bin/codex",+ "\(home)/.npm-global/bin/codex",+ ]+ return candidates.first { FileManager.default.isExecutableFile(atPath: $0) }+ }++ /// Runs `codex app-server` and asks for `account/rateLimits/read`. nil if Codex is missing or not signed in.+ static func fetch() async -> CodexPlanUsage? {+ guard let codex = codexExecutable() else { return nil }+ return await Task.detached { readRateLimits(codex: codex) }.value+ }++ private static func readRateLimits(codex: String) -> CodexPlanUsage? {+ nonisolated(unsafe) let process = Process()+ process.executableURL = URL(fileURLWithPath: codex)+ process.arguments = ["app-server"]+ var env = ProcessInfo.processInfo.environment+ env["PATH"] = [URL(fileURLWithPath: codex).deletingLastPathComponent().path, "/opt/homebrew/bin", "/usr/local/bin",+ "/usr/bin", "/bin", env["PATH"] ?? ""].joined(separator: ":")+ process.environment = env+ let input = Pipe(), output = Pipe()+ process.standardInput = input+ process.standardOutput = output+ process.standardError = FileHandle.nullDevice+ do { try process.run() } catch { return nil }+ defer { if process.isRunning { process.terminate() } }++ // Give up after 15 s: terminating closes stdout, which ends the read loop.+ let timeout = DispatchWorkItem { if process.isRunning { process.terminate() } }+ DispatchQueue.global().asyncAfter(deadline: .now() + 15, execute: timeout)+ defer { timeout.cancel() }++ let requests = [+ #"{"id":1,"method":"initialize","params":{"clientInfo":{"name":"coucou","version":"1"}}}"#,+ #"{"method":"initialized"}"#,+ #"{"id":2,"method":"account/rateLimits/read"}"#,+ ]+ input.fileHandleForWriting.write(Data((requests.joined(separator: "\n") + "\n").utf8))++ var buffer = Data()+ while true {+ let chunk = output.fileHandleForReading.availableData+ if chunk.isEmpty { return nil }+ buffer.append(chunk)+ while let nl = buffer.firstIndex(of: 0x0A) {+ let line = buffer[buffer.startIndex..<nl]+ buffer.removeSubrange(buffer.startIndex...nl)+ guard let obj = try? JSONSerialization.jsonObject(with: line) as? [String: Any],+ obj["id"] as? Int == 2 else { continue }+ return (obj["result"] as? [String: Any]).flatMap(parse)+ }+ }+ }++ /// Parses an `account/rateLimits/read` result.+ static func parse(result: [String: Any]) -> CodexPlanUsage? {+ guard let limits = result["rateLimits"] as? [String: Any] else { return nil }+ var usage = CodexPlanUsage(planType: limits["planType"] as? String, updatedAt: Date())+ // primary/secondary are not fixed to a window: sort them by duration+ for key in ["primary", "secondary"] {+ guard let w = limits[key] as? [String: Any],+ let pct = w["usedPercent"] as? Double,+ let resetsAt = w["resetsAt"] as? Double else { continue }+ let window = PlanWindow(usedPct: min(100, max(0, pct)), resetsAt: Date(timeIntervalSince1970: resetsAt))+ if let mins = w["windowDurationMins"] as? Int, mins <= 24 * 60 {+ usage.fiveHour = window+ } else {+ usage.sevenDay = window+ }+ }+ if let resets = result["rateLimitResetCredits"] as? [String: Any] {+ usage.resetCredits = resets["availableCount"] as? Int+ let expiries = (resets["credits"] as? [[String: Any]] ?? [])+ .filter { $0["status"] as? String == "available" }+ .compactMap { $0["expiresAt"] as? Double }+ usage.resetCreditExpiresAt = expiries.min().map { Date(timeIntervalSince1970: $0) }+ }+ guard usage.fiveHour != nil || usage.sevenDay != nil else { return nil }+ return usage+ }++ static func pillLabel(_ usage: CodexPlanUsage?) -> String {+ guard let usage, let pct = ClaudePlanGauge.dominantPct(usage.planUsage) else { return "Codex —" }+ return "Codex \(Int(pct.rounded()))%"+ }++ static func color(_ usage: CodexPlanUsage?) -> String {+ ClaudePlanGauge.color(for: usage.flatMap { ClaudePlanGauge.dominantPct($0.planUsage) })+ }+}++// MARK: - Codex Plan Card View++private let resetExpiryFormatter: DateFormatter = {+ let fmt = DateFormatter()+ fmt.locale = Locale(identifier: "en_US_POSIX")+ fmt.dateFormat = "MMM d"+ return fmt+}()++struct CodexPlanCardView: View {+ let usage: CodexPlanUsage? // nil = loading or unavailable++ @State private var now = Date()++ var body: some View {+ VStack(alignment: .leading, spacing: 0) {+ // Header+ HStack(spacing: 6) {+ Circle()+ .fill(Color(hex: CodexPlanGauge.color(usage)))+ .frame(width: 7, height: 7)+ Text("Codex plan")+ .font(.system(size: 12, weight: .semibold))+ .foregroundColor(Color(hex: "#F5F6F8"))+ Text(subtitleText)+ .font(.system(size: 11))+ .foregroundColor(Color(hex: "#8E939C"))+ .lineLimit(1)+ .fixedSize()+ }+ .padding(.top, 6)+ .padding(.leading, 108)+ .padding(.trailing, 36)++ // Gauge rows+ VStack(alignment: .leading, spacing: 5) {+ if usage?.fiveHour != nil {+ GaugeRowView(label: "5 hours", window: usage?.fiveHour, now: now)+ }+ GaugeRowView(label: "Week", window: usage?.sevenDay, now: now, weekly: true)+ HStack(spacing: 5) {+ Text("Resets")+ .font(.system(size: 11))+ .foregroundColor(Color(hex: "#6B7079"))+ .frame(width: 40, alignment: .leading)+ Text(resetsText)+ .font(.system(size: 11, weight: .semibold))+ .foregroundColor(Color(hex: "#C5C8CD"))+ .lineLimit(1)+ .fixedSize()+ }+ }+ .padding(.top, 8)+ .padding(.leading, 108)+ .padding(.trailing, 12)+ }+ .frame(maxWidth: .infinity, alignment: .topLeading)+ .padding(.top, 4)+ // Update countdown every 30s, only while visible+ .background(+ TimelineView(.periodic(from: .now, by: 30)) { ctx in+ Color.clear.onChange(of: ctx.date) { _, d in now = d }+ }+ )+ }++ private var subtitleText: String {+ guard let usage else { return "Asking Codex…" }+ let plan = usage.planType.map { "\($0) · " } ?? ""+ let diff = now.timeIntervalSince(usage.updatedAt)+ if diff < 60 { return plan + "just now" }+ let mins = Int(diff / 60)+ if mins < 60 { return plan + "\(mins) min ago" }+ return plan + "\(mins / 60) h ago"+ }++ private var resetsText: String {+ guard let count = usage?.resetCredits else { return "—" }+ var text = "\(count) available"+ if count > 0, let exp = usage?.resetCreditExpiresAt {+ text += " · until \(resetExpiryFormatter.string(from: exp))"+ }+ return text+ }+}+#endifdiff --git a/NotchBuddy/Sources/App/IslandRootView.swift b/NotchBuddy/Sources/App/IslandRootView.swiftindex eb91f230..d3fd71d4 100644--- a/NotchBuddy/Sources/App/IslandRootView.swift+++ b/NotchBuddy/Sources/App/IslandRootView.swift@@ -489,6 +489,9 @@ struct IslandHeader: View {if state.view == .overview && state.showPlanInNotch && state.planRelayInstalled {ClaudePlanHeaderPill(state: state)}+ if state.view == .overview && state.showCodexPlanInNotch {+ ClaudePlanHeaderPill(state: state, codex: true)+ }#endifHStack(spacing: 14) {Button(action: {@@ -555,25 +558,32 @@ struct TabButton: View {#if !APPSTOREstruct ClaudePlanHeaderPill: View {@ObservedObject var state: AppState+ var codex: Bool = false@State private var isHovered = falseprivate var effectiveColor: String {- ClaudePlanGauge.color(for: state.claudePlanUsage.flatMap { ClaudePlanGauge.dominantPct($0) })+ if codex { return CodexPlanGauge.color(state.codexPlanUsage) }+ return ClaudePlanGauge.color(for: state.claudePlanUsage.flatMap { ClaudePlanGauge.dominantPct($0) })}private var label: String {+ if codex { return CodexPlanGauge.pillLabel(state.codexPlanUsage) }guard let usage = state.claudePlanUsage,let pct = ClaudePlanGauge.dominantPct(usage) else { return "Claude —" }return "Claude \(Int(pct.rounded()))%"}- private var isActive: Bool { state.showingPlanDetail || isHovered }+ private var isOpen: Bool { state.showingPlanDetail && state.planDetailIsCodex == codex }+ private var isActive: Bool { isOpen || isHovered }var body: some View {Button(action: {withAnimation(.spring(response: 0.28, dampingFraction: 0.82)) {- state.showingPlanDetail.toggle()+ let open = isOpen+ state.planDetailIsCodex = codex+ state.showingPlanDetail = !open}+ if codex { state.refreshCodexPlanUsage() }}) {HStack(spacing: 4) {Circle()@@ -604,6 +614,7 @@ struct ClaudePlanHeaderPill: View {.onHover { h inwithAnimation(.spring(response: 0.2, dampingFraction: 0.7)) { isHovered = h }}+ .onAppear { if codex { state.refreshCodexPlanUsage() } }}}#endifdiff --git a/NotchBuddy/Sources/App/IslandViewContent.swift b/NotchBuddy/Sources/App/IslandViewContent.swiftindex 3947f0d6..52359e11 100644--- a/NotchBuddy/Sources/App/IslandViewContent.swift+++ b/NotchBuddy/Sources/App/IslandViewContent.swift@@ -103,8 +103,14 @@ struct OverviewView: View {#if !APPSTOREif state.showingPlanDetail {CardBackground(wash: nil)- ClaudePlanCardView(usage: state.claudePlanUsage)- .transition(.opacity)+ Group {+ if state.planDetailIsCodex {+ CodexPlanCardView(usage: state.codexPlanUsage)+ } else {+ ClaudePlanCardView(usage: state.claudePlanUsage)+ }+ }+ .transition(.opacity)}#endifdiff --git a/NotchBuddy/Sources/App/SettingsView.swift b/NotchBuddy/Sources/App/SettingsView.swiftindex 9a3d0408..8d87334b 100644--- a/NotchBuddy/Sources/App/SettingsView.swift+++ b/NotchBuddy/Sources/App/SettingsView.swift@@ -589,6 +589,15 @@ struct SettingsView: View {.buttonStyle(.bordered)}}+ Divider()+ Text("Shows your Codex plan usage (weekly limit and free resets left) in the notch header. Coucou asks the Codex CLI (codex app-server) when the pill shows; nothing is installed. Codex must be signed in with ChatGPT.")+ .font(.system(size: 11))+ .foregroundColor(.secondary)+ .fixedSize(horizontal: false, vertical: true)+ Toggle("Show Codex plan in the notch", isOn: Binding(+ get: { state.showCodexPlanInNotch },+ set: { state.showCodexPlanInNotch = $0 }+ ))}.padding(6)}diff --git a/README.md b/README.mdindex abf6f8cd..449563ea 100644--- a/README.md+++ b/README.md@@ -39,6 +39,7 @@ Meet **Mochi**: a soft little squircle with big eyes that pops out of your notch- 🧑💻 **Jump to the right terminal** — open the exact terminal window of a session *(macOS)*.- 💬 **Chat with Claude, Gemini, OpenAI, or a local model (Ollama / LM Studio)** — click the model name above the chat box to switch provider and pick a model. Cloud providers use your own API key; local providers connect to a server running on your Mac. *(Gemini, OpenAI and local models: macOS)*- 📊 **Claude plan usage** *(macOS, GitHub build)* — a small pill in the notch header shows your 5-hour and weekly Claude plan limits. Enable it from Settings → Agents → Plan usage. Pro and Max plans only.+- 📊 **Codex plan usage** *(macOS, GitHub build)* — a Codex pill next to it shows your Codex limits and how many free resets you have left, read from the Codex CLI. Turn it on in Settings → Agents → Plan usage.- 📋 **Declare the tools you use** — open Settings → Active pills and pick your main workspace tool (VS Code, Cursor, Codex or Antigravity), then toggle up to 4 more: Gemini CLI, Anthropic, Google AI, OpenAI, Ollama, LM Studio and service integrations *(macOS)*.- 📎 **Drop a file on the notch** — Mochi turns into a box and swallows it, then ask a question about it or send it by email *(email: macOS, Mail.app)*.- 🖥️ **Mochi on the desktop** — drag Mochi out of the island to set him loose on your desktop: he floats as a 120 pt companion, follows your cursor, wears his outfit, reacts to alerts by flying home and flying back, and comes back where you left him on next launch.