Once: Cache CLI Commands
Recorded: Oct. 9, 2026, 2:10 p.m.
| Original | Summarized |
GitHub - alex0ptr/once: Run a command once, reuse its output for a while. · GitHub Skip to content Navigation MenuSign inAppearance settingsPlatformAI CODE CREATIONGitHub CopilotWrite better code with AIGitHub Copilot appDirect agents from issue to mergeMCP RegistryIntegrate external toolsDEVELOPER WORKFLOWSActionsAutomate any workflowCodespacesInstant dev environmentsIssuesPlan and track workCode ReviewManage code changesCode QualityEnforce quality at mergeAPPLICATION SECURITYGitHub Advanced SecurityFind and fix vulnerabilitiesCode securitySecure your code as you buildSecret protectionStop leaks before they startEXPLOREWhy GitHubDocumentationBlogChangelogMarketplaceView all featuresSolutionsBY COMPANY SIZEEnterprisesSmall and medium teamsStartupsNonprofitsBY USE CASEApp ModernizationDevSecOpsDevOpsCI/CDView all use casesBY INDUSTRYHealthcareFinancial servicesManufacturingGovernmentView all industriesView all solutionsResourcesEXPLORE BY TOPICAISoftware DevelopmentDevOpsSecurityView all topicsEXPLORE BY TYPECustomer storiesEvents & webinarsEbooks & reportsBusiness insightsGitHub SkillsSUPPORT & SERVICESDocumentationCustomer supportCommunity forumTrust centerPartnersView all resourcesOpen SourceCOMMUNITYGitHub SponsorsFund open source developersPROGRAMSSecurity LabMaintainer CommunityGitHub StarsArchive ProgramREPOSITORIESTopicsTrendingCollectionsEnterpriseENTERPRISE SOLUTIONSEnterprise platformAI-powered developer platformAVAILABLE ADD-ONSGitHub Advanced SecurityEnterprise-grade security featuresCopilot for BusinessEnterprise-grade AI featuresPremium SupportEnterprise-grade 24/7 supportPricingSearch/Sign inSign upAppearance settings You signed in with another tab or window. Reload to refresh your session. Dismiss alert alex0ptronceRepository navigationCodeIssuesPull requestsActionsProjectsSecurity and qualityInsightsMore items oncePublicNotificationsYou must be signed in to change notification settingsFork1 (1)Star41 (41)You must be signed in to star a repositoryAboutRun a command once, reuse its output for a while.ResourcesReadmeMIT licenseActivityStars41 starsWatchers0 watchingForks1 forkReport repositorymainBranchesTagsGo to fileCodeOpen more actions menuLatest commit History5 Commits5 CommitsFolders and filesNameNameLast commit messageLast commit date.gitignore.gitignore LICENSELICENSE README.mdREADME.md client.goclient.go coredump_linux.gocoredump_linux.go coredump_other.gocoredump_other.go daemon.godaemon.go go.modgo.mod key.gokey.go main.gomain.go once_test.goonce_test.go paths.gopaths.go View all filesRepository files navigationREADMEMIT licenseMore itemsonce # later while you work in your scripts / direnv / mise.toml Option --ttl --until --tenant --refresh --no-dir once status shows the daemon, its entry count and when it will stop. It separates cache contexts (shells, projects, scripts): a context with a It does not stop other processes of your own user from using the cache; see once computes the key and asks the daemon over a Unix socket. The socket lives in $XDG_RUNTIME_DIR/once-<uid>/ (or the temp dir) in a Protection against other users comes from the Unix socket and file Limits Outputs larger than 64 MiB are passed through but not cached. License Footer © 2026 GitHub, Inc. Footer navigation Terms Privacy Security Status Community Docs Contact Manage cookies Do not share my personal information You can’t perform that action at this time. |
The once tool is designed to execute a command once and subsequently reuse its output for a defined duration, operating through a small, per-user background daemon that maintains the cached results in memory. This functionality is particularly useful in scenarios requiring privileged information retrieval, such as accessing secrets, by allowing the command to run only once while granting repeated access to the stored result. A typical application involves setting a tenant key, which serves to separate cache contexts, allowing the system to manage distinct sets of stored information for different sessions or projects. The mechanism of caching relies on generating a unique cache key, which is derived using an HMAC-SHA256 function based on the tenant key, the working directory, the command executed, and its arguments, with the option to exclude the working directory for directory-independent caching. This key generation ensures that cache entries are context-specific and practically unguessable. The system communicates with the daemon via a Unix socket located in a secure directory, specifically $XDG_RUNTIME_DIR/once-<uid>/, which maintains restrictive file permissions (0700) to prevent unauthorized access by other users. The operational parameters for caching are controlled by several options. The time-to-live, denoted by --ttl, specifies the duration for which the cached result is valid, and it must be provided. An absolute expiration time can be set using --until, which acts as an absolute upper bound for the entry's validity, noting that the system does not compute relative dates. The option --refresh allows a user to bypass the cache, forcing the command to be executed again and overwriting any existing cached value. The --no-dir option is crucial for directory-independent caching, ensuring that the cache key is not influenced by the working directory path, which is beneficial for commands whose output is not dependent on the directory structure. When a cache miss occurs, once executes the command within the current environment. If the command is successful, once manages the daemon, saving the output along with its determined expiry time. The daemon itself only maintains entries in memory, shutting down when all cached entries have expired. The system ensures that only the standard output is cached; standard input and standard error are passed through, allowing interactive prompts to function correctly. Furthermore, results from commands that exit with a non-zero status code are never cached, and the exit code is relayed. From a security perspective, the isolation mechanism is structured around the Unix socket and file permissions. While the system prevents other users from accessing the cache data, processes belonging to the same user are permitted to use the cache by accessing the socket and potentially reading the tenant key from configuration files. The cached values are held within the daemon's memory and are subject to overwriting before being released, although the text notes that memory remains vulnerable to swapping. To further mitigate data exposure, core dumps of the daemon are disabled, and memory contains cached values are not written to core files. Performance limitations include the filtering of outputs larger than sixty-four megabytes, which are passed through the system but are not stored in the cache. This design establishes a framework for secure, time-limited persistence of command execution results. |