<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mr.Anh</title>
    <description>The latest articles on Forem by Mr.Anh (@anhfactor).</description>
    <link>https://forem.com/anhfactor</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F173921%2F6ce5d8a4-c8b5-46db-86d7-fe6e1f851cb6.jpg</url>
      <title>Forem: Mr.Anh</title>
      <link>https://forem.com/anhfactor</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/anhfactor"/>
    <language>en</language>
    <item>
      <title>xplain — AI-Powered CLI to Explain Code, Commands &amp; Errors</title>
      <dc:creator>Mr.Anh</dc:creator>
      <pubDate>Wed, 11 Feb 2026 22:56:18 +0000</pubDate>
      <link>https://forem.com/anhfactor/xplain-ai-powered-cli-to-explain-code-commands-errors-3e8n</link>
      <guid>https://forem.com/anhfactor/xplain-ai-powered-cli-to-explain-code-commands-errors-3e8n</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/github-2026-01-21"&gt;GitHub Copilot CLI Challenge&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;xplain&lt;/strong&gt; is a developer-focused CLI tool that uses the GitHub Models API to explain code, shell commands, error messages, and git diffs — in 10+ languages.&lt;/p&gt;

&lt;p&gt;As developers, we constantly encounter unfamiliar commands, cryptic errors, and complex diffs. xplain brings AI-powered explanations directly into your terminal workflow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;xplain cmd "git rebase -i HEAD~3 --autosquash"&lt;/code&gt;&lt;/strong&gt; — breaks down every flag and argument&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;xplain error "TypeError: Cannot read property 'map' of undefined"&lt;/code&gt;&lt;/strong&gt; — diagnoses the error and suggests fixes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;xplain code ./utils.py&lt;/code&gt;&lt;/strong&gt; — explains code files step by step&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;xplain diff HEAD~1&lt;/code&gt;&lt;/strong&gt; — summarizes what changed in your last commit&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;python app.py 2&amp;gt;&amp;amp;1 | xplain pipe&lt;/code&gt;&lt;/strong&gt; — auto-detects if piped input is an error, code, or logs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;xplain chat&lt;/code&gt;&lt;/strong&gt; — interactive chat for any dev question&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;xplain history&lt;/code&gt;&lt;/strong&gt; — browse and search past explanations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;xplain wtf&lt;/code&gt;&lt;/strong&gt; — 🤯 explain the last failed command from your shell history&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;xplain --tldr cmd "..."&lt;/code&gt;&lt;/strong&gt; — ⚡ one-line TL;DR explanations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All commands support &lt;code&gt;--lang&lt;/code&gt; for multilingual output (English, Vietnamese, Chinese, Japanese, Korean, Spanish, French, German, Portuguese, Russian), &lt;code&gt;--model&lt;/code&gt; to choose any AI model from the GitHub Models Marketplace (GPT-4o, GPT-4.1, Llama 4, DeepSeek R1, etc.), and &lt;code&gt;--output&lt;/code&gt; to export explanations to &lt;code&gt;.md&lt;/code&gt;, &lt;code&gt;.json&lt;/code&gt;, or &lt;code&gt;.txt&lt;/code&gt; files.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;WTF Mode&lt;/strong&gt; — &lt;code&gt;xplain wtf&lt;/code&gt; reads your shell history, re-runs the last command, captures the error, and explains what went wrong with a fix. Fun, memorable, and solves a real pain point.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TL;DR Mode&lt;/strong&gt; — &lt;code&gt;xplain --tldr&lt;/code&gt; for ultra-short one-line explanations across all commands&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Model Selection&lt;/strong&gt; — choose any model from the GitHub Models Marketplace (&lt;code&gt;--model openai/gpt-4.1&lt;/code&gt;, &lt;code&gt;--model deepseek/DeepSeek-R1&lt;/code&gt;, etc.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smart Pipe Detection&lt;/strong&gt; — automatically classifies piped input as error, code, or general output using heuristic pattern matching&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Git Diff Explanations&lt;/strong&gt; — understands unstaged, staged, or ref-based diffs with file stats&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shell Integration&lt;/strong&gt; — &lt;code&gt;source shell/xplain.zsh&lt;/code&gt; for aliases (&lt;code&gt;wtf&lt;/code&gt;, &lt;code&gt;xc&lt;/code&gt;, &lt;code&gt;xe&lt;/code&gt;, &lt;code&gt;xd&lt;/code&gt;), tab completion, and auto command-not-found handler&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Persistent History&lt;/strong&gt; — JSON-based local storage of all explanations, searchable and filterable&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Export&lt;/strong&gt; — save any explanation to markdown, JSON, or plain text&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Beautiful Terminal UI&lt;/strong&gt; — Rich-powered panels, syntax highlighting, loading spinners, and language flags&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/anhfactor/xplain-copilot" rel="noopener noreferrer"&gt;github.com/anhfactor/xplain-copilot&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8bogi9m10b1sjhqz7m5a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8bogi9m10b1sjhqz7m5a.png" alt=" " width="800" height="553"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Video Walkthrough (actually its a gif)
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc2i60h9hqkn5q46jqnj1.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc2i60h9hqkn5q46jqnj1.gif" alt=" " width="760" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The walkthrough covers all 6 core features:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Explain commands&lt;/strong&gt; — &lt;code&gt;xplain cmd "git rebase -i HEAD~3" --lang vi&lt;/code&gt; with Vietnamese output&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WTF mode&lt;/strong&gt; — &lt;code&gt;xplain wtf&lt;/code&gt; explains the last failed command with a fix&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TL;DR mode&lt;/strong&gt; — &lt;code&gt;xplain --tldr cmd "..."&lt;/code&gt; for one-line answers&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smart pipe&lt;/strong&gt; — &lt;code&gt;npm run build 2&amp;gt;&amp;amp;1 | xplain pipe&lt;/code&gt; auto-detects error output&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Model selection&lt;/strong&gt; — &lt;code&gt;xplain --model deepseek/DeepSeek-R1 diff HEAD~1&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shell integration&lt;/strong&gt; — aliases, tab completion, auto command-not-found handler&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Quick Demo
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmdb6qvazhc0puvpslcho.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmdb6qvazhc0puvpslcho.gif" alt=" " width="800" height="591"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  My Experience with GitHub Copilot CLI
&lt;/h2&gt;

&lt;p&gt;I used &lt;a href="https://gh.io/copilot-cli" rel="noopener noreferrer"&gt;GitHub Copilot CLI&lt;/a&gt; (&lt;code&gt;gh copilot&lt;/code&gt;) throughout the development of xplain. Here are specific examples of how it shaped the project:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Understanding Code with Copilot CLI
&lt;/h3&gt;

&lt;p&gt;I used &lt;code&gt;gh copilot&lt;/code&gt; to explain my own code and verify correctness:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ gh copilot -p "Explain what the _get_last_command_zsh function does in src/commands/wtf.py" \
    --allow-tool 'shell(cat)'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copilot CLI read the file autonomously and produced a detailed 6-point breakdown of the function — from how it reads the history file efficiently (last 8KB only) to how it parses zsh's extended history format (&lt;code&gt;: timestamp:0;command&lt;/code&gt;). This helped me verify the implementation was correct.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp3nxraepmvue3uwftuz9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp3nxraepmvue3uwftuz9.png" alt=" " width="800" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Feature Design with Copilot CLI
&lt;/h3&gt;

&lt;p&gt;I asked Copilot CLI to suggest how to add a &lt;code&gt;--json&lt;/code&gt; output flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ gh copilot -p "Suggest how to add a --json output flag to the wtf command" \
    --allow-tool 'shell(cat,ls,find)'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It explored the project structure autonomously (reading 5 files across &lt;code&gt;src/commands/&lt;/code&gt; and &lt;code&gt;src/core/&lt;/code&gt;), then produced a 3-part implementation plan with code snippets. I followed its suggestion exactly — adding &lt;code&gt;_format_as_json()&lt;/code&gt;, the &lt;code&gt;--json&lt;/code&gt; typer option, and conditional output logic. &lt;strong&gt;~15 lines of code, non-breaking, enables &lt;code&gt;xplain wtf --json | jq&lt;/code&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fspkyfdb6jwk9w090y6mt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fspkyfdb6jwk9w090y6mt.png" alt=" " width="800" height="678"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Architecture Decisions
&lt;/h3&gt;

&lt;p&gt;Copilot CLI helped solve the GitHub Models API authentication issue. My initial approach used &lt;code&gt;gh api&lt;/code&gt; which returned 401 errors. Copilot explained that &lt;code&gt;gh api&lt;/code&gt; only forwards tokens to &lt;code&gt;api.github.com&lt;/code&gt;, not third-party hosts like &lt;code&gt;models.github.ai&lt;/code&gt;. It suggested extracting the token via &lt;code&gt;gh auth token&lt;/code&gt; and making direct HTTP calls with &lt;code&gt;httpx&lt;/code&gt; — which became the core of &lt;code&gt;src/core/copilot.py&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For the &lt;code&gt;--tldr&lt;/code&gt; flag, Copilot suggested the dual system prompt approach (&lt;code&gt;SYSTEM_PROMPT&lt;/code&gt; vs &lt;code&gt;SYSTEM_PROMPT_TLDR&lt;/code&gt;) with a global flag, which was cleaner than modifying every command individually.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Test Generation
&lt;/h3&gt;

&lt;p&gt;Copilot CLI analyzed the test file and project structure, identifying all 6 test classes and their coverage areas. It helped generate the &lt;code&gt;TestWTFCommand&lt;/code&gt;, &lt;code&gt;TestTLDRMode&lt;/code&gt;, and &lt;code&gt;TestShellIntegration&lt;/code&gt; test classes with proper temp file handling and environment variable cleanup.&lt;/p&gt;

&lt;p&gt;The result: &lt;strong&gt;44 tests, all passing&lt;/strong&gt;, with good coverage of the core functionality.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Made It Special
&lt;/h3&gt;

&lt;p&gt;The most impactful aspect was &lt;strong&gt;agentic exploration&lt;/strong&gt;. Copilot CLI didn't just answer questions — it autonomously read files, explored the project structure, and produced context-aware suggestions. When I asked about adding &lt;code&gt;--json&lt;/code&gt;, it read 5 files before suggesting an implementation that perfectly matched the project's existing patterns. It felt like pair programming with someone who actually understands the codebase.&lt;/p&gt;




&lt;p&gt;Built with Python, Typer, Rich, and the GitHub Models API.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/anhfactor/xplain-copilot" rel="noopener noreferrer"&gt;github.com/anhfactor/xplain-copilot&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Contributor:&lt;/strong&gt; &lt;a href="https://dev.to/anhfactor"&gt;https://dev.to/anhfactor&lt;/a&gt; AnhFactor&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>githubchallenge</category>
      <category>cli</category>
      <category>githubcopilot</category>
    </item>
  </channel>
</rss>
