Having different development contexts — e.g. work, personal projects, different repositories and permissions — it becomes a concern to manage the permissions among them in a safe way. This is important, especially if we use agentic tools such as Claude. In that case, we would need to provide the least permissions possible for that agent, such as read-only access, so that something which was not planned is not going to happen.
The gh CLI itself has limited ways to change contexts, as it is not fully automated. If we have two accounts, we would need to manually use gh auth switch <OPTIONS>. There are also environment variables like GH_TOKEN and GH_CONFIG_DIR to change contexts accordingly, but they are not that practical if you need to change contexts all the time. More elaborate options require writing custom scripts and logic, which would eventually lead to the creation of a custom tool.
Kalamarnica is a CLI tool which adds useful commands over the gh CLI, context-wise. It has some simple one-off commands to manage GitHub contexts, including kalamarnica bind and kalamarnica apply.
Those commands specifically allow you to set per-repository contexts. kalamarnica bind <context-name>, run inside a git repository, binds a context to the current git repository by its name; it stores the GitHub context name inside a file called .ghcontext. Later, when you enter this repository again, you can use kalamarnica apply to switch to the context of this repository, if it has any registered in the .ghcontext file. You can also create a .envrc file (for direnv) that runs kalamarnica apply automatically.
Another useful feature is kalamarnica set-token, which is the primary why reason I decided to create this tool. With gh, we can’t bind more than one token to the same GitHub account, so if we want more than one token for our account — say, a token with read-only permissions, which we use with Claude — we can do kalamarnica set-token --name <context-name> <token> to create a new context with that new token even though it points to the same account.
It also has other useful commands — check the documentation for more. The repository source code and documentation are hosted at https://github.com/Propfend/kalamarnica.