Pair with Claude in Your Shell Using Anthropic + Flox
Steve Swoyer | 19 July 2024
When you're working in your project environment and stuff's starting to come together, you gotta do everything you can to stay in your flow. You gotta avoid the distraction of context-switching, even if it's just from one browser tab to another.
But even when you're in your flow, sometimes you run into questions you can't answer on your own, and you just gotta know. When this happens, you use tools like googler or ddgr to search the web from your CLI.
Now you can prompt Anthropic's Claude LLMs from your CLI, too—staying within your flow.
With Flox's latest pre-built example environment, you can pass prompts to Anthropic's Claude models and get on-point results right within your terminal. What's more, you can pipe files to the Claude model of your choice, prompt it to analyze their contents, and optionally persist the model's response.
With a little coding, you could even add a quick-and-dirty Flask API endpoint to our Anthropic environment, giving you a way to access it programmatically.
This blog explores how you might use Flox's Anthropic environment in your day-to-day workflow.
The Case of the Nattering Node App
Picture this: You're in your Node.js project environment, building a new service that integrates streaming data from Apache Kafka. You've used Node.js's kafkajs library to set up your Kafka producers and consumers. That went swimmingly. Now you're in your flow state, trying to tune your Kafka consumer group so it scales better to handle increased throughput levels.
That's when you start getting these messages in your terminal:
Rebalancing happens over and over again—even under normal load.
Why? What gives? Output from Kafka's kafka-consumer-groups tool tells you there's pretty major lag between the current and log-end offsets. And your logs paint an even more dire picture:
But why? Dammit this was working! What the ^#@&\* is going on?!
This is what tools like CoPilot were created for. Let's say for the sake of argument that you don't use CoPilot... but you do use the pre-built Flox environment for prompting Anthropic's Claude LLMs from your terminal.
You remember how when you first set it up, it asked you a couple of questions and was ready to go. Just like that.
That was all there was to it.
Prompting i-Claudeius
You're already in your Flox Node.js environment, building and testing your new application on the latest release of Node.js. So you go ahead and activate Claude as a Flox remote environment:
This environment is layered—or superimposed virtually—over your Node.js project environment. It basically gives you an on-when-you-need-it, gone-when-you-don't prompting playground.
And right now, you need it! So you get right to it:
This is frustratingly basic stuff. It does make you think, however. Yes, you made some configuration changes in Kafka, but you also refactored code in your kafkajs app, implementing synchronous logic to speed up message processing. But these changes were supposed to improve performance under load! Your refactored code couldn't be the root cause...could it?
You decide to pipe your code to Claude for analysis, asking it to compare your original and current versions. It's been a minute since you've used Flox's Anthropic environment, so you type:
Eureka! -i was the option you needed. This lets you pass files to a Claude model for analysis.
Claude printed a lot more information than this to your console—dozens and dozens of off-screen lines.
So you decide to prompt it again, this time serializing its response to a text file:
You fire up your text editor to see what Claude had to say. Ordinarily, you'd do this using vi in your terminal, but vi doesn't make for a pretty or compelling visual in a walk-through.
So we'll use gnome-text-editor instead. It isn't particularly pretty, but at least it's a GUI!
There it is. The change you made to improve performance under load actually nerfed performance under all conditions! You could just revert to your prior, known-good code, but let's first ask Claude for help. You've been using the Flox Anthropic environment's default model, Claude Sonnet 3.5, but now you use the -m option to switch to Claude Opus 3, an older model that's arguably at least as capable, just slower. You've gotten excellent results from it when you've used it to debug stuff in the past.
This time, you passed both an input file (-i) and code as part of your prompt, as well as specified a new model. But you kept the -o option, saving the output to a text file so you can more easily view and change the code generated by Claude. You once again fire up fixed.txt in your GUI text editor:
This code snippet is actually a little different from your original. But it passes your sniff test.
So you try it in your app, restarting Node.js, running your stress tests, and going to your logs.
That's it. You've solved your problem. But you're curious: could Claude zero in on exactly the right answer if you constrain its output, passing -x to limit the number of tokens it uses to generate responses?
The very model of conciseness! Every good writer knows that being succinct is an art. Four centuries ago, Blaise Pascal put this best, deadpanning “I would have written a shorter letter, but did not have the time.”
Given the right prompt constraints, the best LLMs do a pretty good job at making the time.
The thing is, you could easily use Flox to build these environments on your own! There's really nothing special about them, and you can view their source using flox list -c -r and the environment name. Take a look to see how this one was built!
Curious? Intrigued? Skeptical? Why not take one of our example environments for a spin?