A simple, elegant command-line tool for tracking daily habits and building streaks. Built with Go.
- ✅ Track unlimited habits with daily completion
- 📈 Automatic streak calculation for consecutive days
- 💾 Persistent storage in JSON format
- 🎯 Simple and intuitive CLI interface
- ⚙️ Configurable data file location
- 📊 Comprehensive statistics
- 🌍 Cross-platform support (Linux, macOS, Windows)
- 🔍 Search habits by name
- ✏️ Rename habits
- 📤 Export to CSV or JSON
- 📥 Import from CSV or JSON with merge support
- 💾 Backup & Restore functionality
- 🚀 Shell completions (Bash, Zsh, Fish)
- 🐳 Docker support
curl -sfL https://raw.githubusercontent.com/codeforgood-org/cli-habit-tracker-go/main/install.sh | shgo install github.com/codeforgood-org/cli-habit-tracker-go/cmd/habit@latestbrew tap codeforgood-org/tap
brew install habit-trackerDownload the latest binary for your platform from the releases page.
git clone https://github.com/codeforgood-org/cli-habit-tracker-go.git
cd cli-habit-tracker-go
make build
sudo make installdocker pull ghcr.io/codeforgood-org/habit-tracker:latest
docker run --rm -v ~/.habit-tracker:/root/.habit-tracker ghcr.io/codeforgood-org/habit-tracker list# Mark a habit as done for today (creates it if new)
habit mark "Morning Exercise"
# List all habits with their streaks
habit list
# View statistics
habit stats
# Search for habits
habit search exercise
# Delete a habit
habit delete "Old Habit"
# Rename a habit
habit edit "Excercise" "Exercise"
# Export habits to CSV
habit export csv habits.csv
# Import habits from JSON
habit import json backup.json --merge
# Create a backup
habit backup
# Restore from backup
habit restore habits-backup.jsonList all tracked habits with their current streaks and last completion dates.
habit listOutput:
📋 Tracking 3 habit(s):
- Morning Exercise | Streak: 7 | Last done: 2025-01-15
- Reading | Streak: 3 | Last done: 2025-01-14
- Meditation | Streak: 10 | Last done: 2025-01-15
Mark a habit as completed for today. Creates the habit if it doesn't exist.
habit mark "Morning Exercise"
habit done ReadingStreak behavior:
- ✅ Consecutive days: streak increments
- ⏭️ Gap in days: streak resets to 1
- ℹ️ Already marked: shows a message, doesn't change streak
Permanently remove a habit from tracking.
habit delete "Old Habit"
habit rm ExerciseReset a habit's streak to zero and clear its completion date.
habit reset "Morning Exercise"Display comprehensive statistics about all your habits.
habit statsOutput:
📊 Habit Statistics:
Total habits: 5
Marked today: 3
Longest streak: 15 day(s)
Total streak days: 42
Average streak: 8.4 day(s)
Search for habits by name (case-insensitive substring match).
habit search exercise
habit find readRename an existing habit.
habit edit "Excercise" "Exercise"
habit rename "Old Name" "New Name"Export habits to a file. Supported formats: csv, json
habit export csv habits.csv
habit export json habits-backup.jsonImport habits from a file. Use --merge to merge with existing habits.
# Replace existing habits
habit import json habits-backup.json
# Merge with existing habits
habit import csv habits.csv --mergeCreate a backup of your habits data. If no file specified, uses timestamp.
habit backup # Auto-named backup
habit backup my-backup.json # Custom filenameRestore habits from a backup file. Current data is auto-backed up first.
habit restore habits-backup-20250113.jsonDisplay the version number.
habit versionDisplay detailed help information.
habit helpBy default, habits are stored in ~/.habit-tracker/habits.json. You can customize this location using the HABIT_DATA_FILE environment variable:
# Temporary override
HABIT_DATA_FILE=~/my-habits.json habit list
# Permanent override (add to ~/.bashrc or ~/.zshrc)
export HABIT_DATA_FILE=~/my-habits.jsonEnable tab completion for your shell:
Bash:
sudo cp completions/habit.bash /etc/bash_completion.d/habit
source /etc/bash_completion.d/habitZsh:
mkdir -p ~/.zsh/completions
cp completions/habit.zsh ~/.zsh/completions/_habit
# Add to ~/.zshrc:
fpath=(~/.zsh/completions $fpath)
autoload -U compinit && compinitFish:
cp completions/habit.fish ~/.config/fish/completions/Habits are stored in JSON format:
[
{
"name": "Morning Exercise",
"last_done": "2025-01-15",
"streak": 7
},
{
"name": "Reading",
"last_done": "2025-01-14",
"streak": 3
}
]- Go 1.21 or higher
- Make (optional but recommended)
make buildmake testmake coveragemake lintmake cleancli-habit-tracker-go/
├── cmd/habit/ # Main application entry point
├── pkg/
│ ├── models/ # Data models with business logic
│ ├── storage/ # JSON persistence layer
│ └── commands/ # CLI command handlers
├── internal/config/ # Configuration management
├── docs/ # Documentation
│ ├── ARCHITECTURE.md # Architecture documentation
│ └── FAQ.md # Frequently asked questions
├── completions/ # Shell completion scripts
├── .github/workflows/ # CI/CD pipelines
├── Dockerfile # Docker configuration
├── .goreleaser.yml # Release automation
├── install.sh # Installation script
├── Makefile # Build automation
└── [documentation files]
Contributions are welcome! Please see CONTRIBUTING.md for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Architecture Documentation - Design and architecture details
- Contributing Guide - How to contribute
- FAQ - Frequently asked questions
- Changelog - Version history and changes
This project is licensed under the MIT License - see the LICENSE file for details.
- Built for Code for Good
- Inspired by the need for simple, effective habit tracking
- Thanks to all contributors
If you encounter any issues or have questions:
- Check the FAQ
- Search existing issues
- Create a new issue
Future enhancements we're considering:
- Cloud sync support (Dropbox, Google Drive, iCloud)
- Reminder notifications
- Charts and visualizations (terminal-based)
- Goal setting (e.g., "Complete 30 days in a row")
- Habit categories and tags
- Weekly/monthly reports
- Habit templates
- Mobile companion app
- Web dashboard
- API for integrations
# Morning routine
habit mark "Wake up at 6am"
habit mark "Morning Exercise"
habit mark "Meditation"
habit mark "Healthy Breakfast"
# Check progress
habit list
# Evening review
habit stats# Add various habits
habit mark "Read 30 minutes"
habit mark "Drink 8 glasses of water"
habit mark "Learn Spanish"
habit mark "Code Review"
habit mark "Journal"
# View all habits
habit list
# Search for specific habits
habit search water# Fix typos
habit edit "Excercise" "Exercise"
# Remove old habits
habit delete "Deprecated Habit"
# Start fresh with a habit
habit reset "Exercise"
# Check overall statistics
habit stats# Create daily backup
habit backup ~/backups/habits-$(date +%Y%m%d).json
# Export to CSV for analysis
habit export csv habits-export.csv
# Import from another device
habit import json habits-from-laptop.json --merge# Use different data files for work/personal
alias work-habits='HABIT_DATA_FILE=~/work-habits.json habit'
alias personal-habits='HABIT_DATA_FILE=~/personal-habits.json habit'
work-habits mark "Code Review"
personal-habits mark "Exercise"
# Automated daily reminder script
#!/bin/bash
if habit list | grep -q "Last done: $(date +%Y-%m-%d)"; then
echo "Great job! You've tracked habits today!"
else
echo "Don't forget to track your habits!"
habit list
fiIf you find this project useful, please consider giving it a star ⭐
- GitHub Discussions - Ask questions, share ideas
- Issue Tracker - Report bugs, request features
Made with ❤️ by the Code for Good community